Keep Space Missions with Satellites in "except", leave "turn off the screen" alone, and part places after a compound country

"hide everything except space missions" (or "satellites") keeps both, as
switching either off takes the other. "turn off the screen" is no longer
read as a switch with "off the screen" taken off it, which left a place
search. A place joined after a compound country is another place ("near
Trinidad and Tobago and Barbados"), and a compound country after another
place stays whole ("near Paris and Trinidad and Tobago"). Only a word for a
kind of place written after a name ("Island", "City") drops a plan, so
"earthquakes lake tahoe" and "traffic tower bridge" keep theirs. Two doc
comments are back above their code.

Co-authored-by: Manjunath Paparaju <[email protected]>
This commit is contained in:
Sameh KhamisandManjunath Paparaju committed 2026-11-18 18:11:18 -08:00
1 parent 25d33a2e6f
commit 859aa172e7
4 files changed
+119 -16

No files matched your search

+27 -3
View File
@@ -522,6 +522,9 @@ export function parseOmnibar(
const extraPlaces = [];
let previousHadPlace = false;
let previousBarePlace = false;
// Whether the clause before was a further place ("near Paris and
// Trinidad"), which a compound name may go on ("and Tobago").
let previousExtraPlace = false;
let previousGo = false;
// Whether a request was peeled off a "go to" clause, and how the place
// was named: after "go to", after "near"/"in", or bare.
@@ -561,6 +564,8 @@ export function parseOmnibar(
const afterPlaceComma = previousHadPlace && separator === ',';
// "trinidad and tobago": a bare place joined to a bare place by "and".
const afterBarePlaceAnd = previousBarePlace && separator === 'and';
const afterExtraPlace = previousExtraPlace;
previousExtraPlace = false;
const continuedLayer = previousLayerEnabled;
const afterGo = previousGo;
previousGo = false;
@@ -607,10 +612,29 @@ export function parseOmnibar(
afterPlace &&
(separator === 'and' || separator === '&') &&
compoundJoin(place.split(', ').at(-1), value);
if (joinsName) place += `${joinsName}${value}`;
else if (place && bare && afterBarePlaceAnd) place += ` and ${value}`;
if (joinsName) {
// The name is whole: a further "and" names another place ("near
// Trinidad and Tobago and Barbados").
place += `${joinsName}${value}`;
previousHadPlace = true;
previousBarePlace = false;
return;
}
// "near Paris and Trinidad and Tobago": the further place is whole too.
const joinsExtra =
afterExtraPlace &&
(separator === 'and' || separator === '&') &&
compoundJoin(extraPlaces.at(-1), value);
if (joinsExtra) {
extraPlaces[extraPlaces.length - 1] += `${joinsExtra}${value}`;
return;
}
if (place && bare && afterBarePlaceAnd) place += ` and ${value}`;
else if (place && !afterPlaceComma) {
if (separator === 'and') extraPlaces.push(value);
if (separator === 'and') {
extraPlaces.push(value);
previousExtraPlace = true;
}
return;
} else if (!place) {
place = value;
+31 -11
View File
@@ -153,11 +153,22 @@ const SETTINGS_FOR =
const SWITCH =
/^(turn on|switch on|enable|show|display|add|turn off|switch off|disable|hide|remove|toggle)(?:\s+(.*))?$/;
const SWITCH_OFF = /^(turn off|switch off|disable|hide|remove)\b/;
/** "hide everything except …", "turn off all layers but …". */
/** A word for a kind of place, which a name goes on with ("Fire Island"). */
/**
* A word for a kind of place written after the name it ends ("Fire
* Island", "Ship Bottom", "Radio City"), not one written before it ("Lake
* Tahoe", "Mount Fuji", "Tower Bridge", "Park City").
*/
const NAME_TAIL =
/^(?:islands?|isle|city|hall|bottom|lake|river|bay|beach|point|station|park|street|road|mountains?|mount|hills?|valley|falls|springs?|creek|county|town|village|harbou?r|cove|canyon|center|centre|square|tower|bridge|pass|ridge|peak)\b/i;
/^(?:islands?|isle|city|hall|bottom|beach|station|street|road|hills?|valley|falls|springs?|creek|county|town|village|harbou?r|cove|canyon|center|centre|square|bridge|ridge|peak)\b(?!\s+of\b)/i;
/**
* A layer that shows itself through another, which must stay on with it:
* Space Missions draws its missions with Satellites, and switching it off
* puts Satellites back as it was before.
*/
const SHOWN_THROUGH = new Map([['rocket-launches', ['satellites']]]);
/** "hide everything except …", "turn off all layers but …". */
const EXCEPT =
/^(?:turn off|switch off|disable|hide|remove|clear)\s+(?:everything|all(?: the)?(?: other)?(?: layers?)?|every layer)\s+(?:except(?: for)?|but(?: for)?|other than|apart from|besides|save for)\s+(.+)$/;
// Layers people reach for first, so "turn on" offers these before the rest.
@@ -930,12 +941,6 @@ export function createOmnibar({ layers = [], isEntity = () => false } = {}) {
return cache.get(line);
}
/**
* "turn on …", "hide …", "toggle …", alone or with a few letters: the
* layers and features that switch that way, never places. Null when the
* line is not such a switch, or names nothing to switch and may be a place
* ("Show Low, AZ").
*/
/**
* "hide everything except flights", "turn off all but ships": a plan that
* switches off every layer that is on but the ones named. Null when the
@@ -953,6 +958,13 @@ export function createOmnibar({ layers = [], isEntity = () => false } = {}) {
if (!kept.length) return null;
if (!kept.every(named)) return [ask];
const keptIds = new Set(kept.map((layer) => layer.id));
// Keeping either of a pair keeps both: switching one off would take the
// other with it ("except space missions", "except satellites").
for (const [layer, through] of SHOWN_THROUGH) {
const on = all().find((entry) => entry.id === layer)?.enabled;
if (keptIds.has(layer) || (on && through.some((id) => keptIds.has(id))))
for (const id of [layer, ...through]) keptIds.add(id);
}
const steps = all()
.filter((layer) => layer.enabled && !keptIds.has(layer.id))
.map((layer) => ({ kind: 'layer', layer, enabled: false }));
@@ -982,14 +994,22 @@ export function createOmnibar({ layers = [], isEntity = () => false } = {}) {
];
}
/**
* "turn on …", "hide …", "toggle …", alone or with a few letters: the
* layers and features that switch that way, never places. Null when the
* line is not such a switch, or names nothing to switch and may be a place
* ("Show Low, AZ").
*/
function switchRows(line, ask) {
const excepted = exceptRows(line, ask);
if (excepted) return excepted;
// "remove flights from the map": the map is where every layer is.
line = line.replace(
// "remove flights from the map": the map is where every layer is. Not
// the verb's own "off" ("turn off the screen" is no layer switch).
const bare = line.replace(
/\s+(?:from|off) (?:the )?(?:map|globe|screen|view)$/i,
'',
);
if (bare !== line && SWITCH.test(bare.toLowerCase())) line = bare;
const switching = line.toLowerCase().match(SWITCH);
if (
!switching ||
+56
View File
@@ -767,3 +767,59 @@ test('a keyword that begins a name offers no plan to the rest of it', () => {
);
}
});
test('"except" keeps a layer and the one it shows through together', () => {
const omnibar = createOmnibar({
layers: [
{ id: 'flights', name: 'Live Flights', enabled: true },
{ id: 'satellites', name: 'Satellites', enabled: true },
{ id: 'rocket-launches', name: 'Space Missions', enabled: true },
],
});
for (const text of [
'hide everything except space missions',
'hide everything except satellites',
])
assert.deepEqual(
omnibar.rows(text, { places: [] }).rows[0].steps.map(stepOutcome),
['layer(flights,off)'],
text,
);
});
test('"turn off the screen" is no layer switch and no place', () => {
for (const text of ['turn off the screen', 'switch off the map'])
assert.equal(outcome(text, { on: ['flights'] }), 'nothing', text);
});
test('a place after a compound country is another place', () => {
const omnibar = createOmnibar({ layers: layers() });
const places = (text) =>
omnibar
.rows(text, { places: [] })
.rows.filter((row) => row.kind === 'place')
.map((row) => row.place.toLowerCase());
assert.deepEqual(places('flights near trinidad and tobago and barbados'), [
'trinidad and tobago',
'barbados',
]);
assert.deepEqual(places('flights near Paris and Trinidad and Tobago'), [
'paris',
'trinidad and tobago',
]);
});
test('a kind of place written before its name keeps the plan', () => {
const omnibar = createOmnibar({ layers: layers() });
for (const text of [
'earthquakes lake tahoe',
'earthquakes mount fuji',
'traffic tower bridge',
]) {
const { rows } = omnibar.rows(text, { places: [] });
assert.ok(
rows.some((row) => row.kind === 'plan'),
text,
);
}
});