From 36264005a8148308b1aaa971a8b21a81bf8f0b42 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Wed, 18 Nov 2026 12:58:11 -0800 Subject: [PATCH] Keep panels, compound names and signed coordinates apart when reading a line - "hide flights near Left Bank, Paris" closed the left panel: a side is closed only when the clause names nothing but the side. - "flights near Trinidad and Tobago" looked up Trinidad alone, and "take me to New York City NY" nothing (the command's words counted against the name): the whole place is looked up, and the limit counts its words. - "flights near 30.27, +97.74" and "30.27; -97.74" were split at the sign or semicolon; both stay coordinates. - "hide flights, show ships" listed "No layers are on": several requests in a line are read as one plan, as with "and". Co-authored-by: Manjunath Paparaju --- src/ui/omnibarIntent.js | 7 +++--- src/ui/omnibarRows.js | 19 +++++++++++---- src/ui/omnibarRows.test.mjs | 46 +++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 8 deletions(-) diff --git a/src/ui/omnibarIntent.js b/src/ui/omnibarIntent.js index 89a359f57f..aefaa07df0 100644 --- a/src/ui/omnibarIntent.js +++ b/src/ui/omnibarIntent.js @@ -109,9 +109,10 @@ function panelStep(clause) { (/\beverything\b/.test(clause) && onlyNames(clause, /\beverything\b/)) ) return { kind: 'panel', action: 'close', side: 'all' }; - if (/\bleft\b/.test(clause)) + // "hide the left panel", never "hide flights near Left Bank". + if (/\bleft\b/.test(clause) && onlyNames(clause, /\b(left|side)\b/g)) return { kind: 'panel', action: 'close', side: 'left' }; - if (/\bright\b/.test(clause)) + if (/\bright\b/.test(clause) && onlyNames(clause, /\b(right|side)\b/g)) return { kind: 'panel', action: 'close', side: 'right' }; for (const [pattern, side, item, name] of PANEL_NAMES) if (pattern.test(clause) && /panel/.test(clause)) @@ -359,7 +360,7 @@ const GO_TAIL = /** Clause separators; "black and white" is joined first so it survives. */ const SEPARATORS = - /(\s*(?:,|;|\+|&|\band then\b|\bthen\b|\band\b|\balso\b)\s*)/; + /(\s*(?:,|;(?!\s*[-+]?\d)|\+(?!\d)|&|\band then\b|\bthen\b|\band\b|\balso\b)\s*)/; function tidy(text) { return text.replace(/\s+/g, ' ').trim(); diff --git a/src/ui/omnibarRows.js b/src/ui/omnibarRows.js index 647e9afe15..6b7c30da24 100644 --- a/src/ui/omnibarRows.js +++ b/src/ui/omnibarRows.js @@ -932,7 +932,8 @@ export function createOmnibar({ layers = [], isEntity = () => false } = {}) { !switching || isPanelText(line) || isWholeMapClear(line) || - /\b(near|in|at|over|around|and|then)\b/.test(switching[2] || '') + // More than one request ("hide flights, show ships") is the parser's. + /\b(near|in|at|over|around|and|then)\b|[,;+&]/.test(switching[2] || '') ) return null; const verb = switching[1]; @@ -1517,8 +1518,7 @@ export function createOmnibar({ layers = [], isEntity = () => false } = {}) { if (line.length < minPlaceChars(line) || line.startsWith('>')) return null; if (/^[0-9a-f]{6}$/i.test(line) || CALLSIGN.test(line.replace(/\s+/g, ''))) return null; - if (line.includes('?') || line.split(/\s+/).length > placeWordLimit(line)) - return null; + if (line.includes('?')) return null; if (VILLAGES.test(line) || exactCommand(line) || coordinateTarget(line)) return null; if (switchRows(line, askRow(text))) return null; @@ -1531,13 +1531,22 @@ export function createOmnibar({ layers = [], isEntity = () => false } = {}) { if (place && !/[\p{L}\p{N}]/u.test(place.place)) return null; // A line of commands with no place in it ("night vision", "zoom in"). if (parsed.steps.length && !place) return null; + const words = (value) => value.split(/\s+/).length; + // The words the place has, not the command around it ("take me to New + // York City NY"); a line that may be one name counts all of its words. + const named = place && !parsed.ambiguous ? place.place : line; + if (words(named) > placeWordLimit(named)) return null; + // "flights near Trinidad and Tobago": the whole name is looked up; the + // rows still offer each part ("Tokyo and Osaka"). + const joined = (value) => + [value, ...(parsed.extraPlaces || [])].join(' and '); // After "go to … , noir" the place read is the one to look up. - if (parsed.peeled && place) return place.place; + if (parsed.peeled && place) return joined(place.place); return parsed.ambiguous || !place ? text : place.place === line ? text - : place.place; + : joined(place.place); } /** diff --git a/src/ui/omnibarRows.test.mjs b/src/ui/omnibarRows.test.mjs index e186176704..3d6533275c 100644 --- a/src/ui/omnibarRows.test.mjs +++ b/src/ui/omnibarRows.test.mjs @@ -601,3 +601,49 @@ test('only a layer in or near a place is counted, never a name', () => { ]) assert.equal(omnibar.countRequest(text), null, text); }); + +test('a place named Left or Right is no panel to close', () => { + const omnibar = createOmnibar({ layers: layers(['flights']) }); + const { rows, defaultIndex } = omnibar.rows( + 'hide flights near Left Bank, Paris', + ); + assert.equal(rows[defaultIndex].kind, 'plan'); + assert.ok(rows[defaultIndex].steps.every((step) => step.kind !== 'panel')); + for (const text of ['hide the left panel', 'close right side']) { + const read = omnibar.rows(text); + assert.ok( + read.rows[read.defaultIndex].steps.some((step) => step.kind === 'panel'), + text, + ); + } +}); + +test('the place service gets the whole place, however it is asked', () => { + const omnibar = createOmnibar({ layers: layers() }); + assert.equal( + omnibar.placeQuery('flights near Trinidad and Tobago'), + 'trinidad and tobago', + ); + assert.equal( + omnibar.placeQuery('take me to New York City NY'), + 'New York City NY', + ); + // A signed longitude or a semicolon stays inside the coordinates. + for (const text of [ + 'show flights near 30.27, +97.74', + 'go to 30.27; -97.74', + ]) { + const { rows, defaultIndex } = omnibar.rows(text); + assert.ok(defaultIndex >= 0, text); + assert.equal(omnibar.placeQuery(text), null, text); + assert.notEqual(rows[defaultIndex].kind, 'none', text); + } +}); + +test('several switches in one line are one plan', () => { + const omnibar = createOmnibar({ layers: layers(['flights']) }); + for (const text of ['hide flights, show radio', 'hide flights; show radio']) { + const { rows, defaultIndex } = omnibar.rows(text); + assert.equal(rows[defaultIndex].kind, 'plan', text); + } +});