Read "everything except", "from the map", a doubled verb and a grid reference after "near"

"hide everything except flights" (or "all but", "other than") switches off
every layer that is on but the ones named, or says no other layers are on.
"remove flights from the map" is "remove flights", "hide hide everything"
reads the verb once, and "flights near 14R PU 2090 4906" flies to the grid
reference. A keyword that begins a name ("Fire Island", "Radio City Music
Hall") no longer offers a plan to the rest of the name. The arrow keys drop
a check for a list that opens upward, which it never does.

Co-authored-by: Manjunath Paparaju <[email protected]>
This commit is contained in:
Sameh KhamisandManjunath Paparaju committed 2026-11-18 17:12:39 -08:00
1 parent 91700f89f8
commit dc31774109
18 files changed
+172 -8

No files matched your search

+11
View File
@@ -9,6 +9,7 @@
// entity comes last.
import { msg } from '../i18n/index.js';
import { parseCoordinateQuery } from '../search/coordinateParser.js';
/** Visual styles, by the words people use for them. */
const STYLES = [
@@ -286,6 +287,11 @@ export function normalizeLine(text, { isRequest = isPlainRequest } = {}) {
.trim();
const end = /(?<!(?:^|[\s.])\p{L})[.!。]+$/u;
line = line.replace(end, '');
// A verb typed twice ("hide hide everything") is one.
line = line.replace(
/^((?:turn|switch) (?:on|off)|show|hide|remove|enable|disable|clear|go to|fly to)\s+\1\b/i,
'$1',
);
// "please" is dropped only around a request: "Please Touch Museum",
// "Kindly Lane" and "Pretty Please" are names.
const polite = line
@@ -903,6 +909,11 @@ export function parseOmnibar(
const unasked = steps.length > 0 && steps.every((step) => !asked.has(step));
if (place && !placeFrom) placeFrom = placeBare ? 'bare' : 'near';
if (place) {
// A grid reference is read only as typed ("14R PU 2090 4906"; in lower
// case it may be words), so the plan keeps it so.
const typed = asTypedIn(raw, place);
if (!parseCoordinateQuery(place) && parseCoordinateQuery(typed))
place = typed;
const step = { kind: 'place', place };
// How the place was typed, for its label only ("İstanbul", "iPhone
// store"); kept off the step's fields, which plans compare.
+64 -1
View File
@@ -153,6 +153,9 @@ 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 …". */
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.
export const POPULAR_LAYERS = [
'flights',
@@ -929,7 +932,55 @@ export function createOmnibar({ layers = [], isEntity = () => false } = {}) {
* 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
* line is not that, or names no layer to keep.
*/
function exceptRows(line, ask) {
const match = EXCEPT.exec(line.toLowerCase());
if (!match) return null;
const kept = match[1]
.split(/\s*(?:,|\band\b|&)\s*/)
.map((term) => matchLayers(term)[0])
.filter(named);
if (!kept.length) return null;
const keptIds = new Set(kept.map((layer) => layer.id));
const steps = all()
.filter((layer) => layer.enabled && !keptIds.has(layer.id))
.map((layer) => ({ kind: 'layer', layer, enabled: false }));
if (!steps.length)
return [
{
key: 'none',
kind: 'none',
icon: 'layers',
label: t('No other layers are on'),
hint: '',
},
ask,
];
return [
{
key: `plan:${JSON.stringify(steps)}`,
kind: 'plan',
icon: 'bolt',
steps,
label: steps.map(stepLabel).join(' · '),
hint: t('Do all'),
},
ask,
];
}
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(
/\s+(?:from|off) (?:the )?(?:map|globe|screen|view)$/i,
'',
);
const switching = line.toLowerCase().match(SWITCH);
if (
!switching ||
@@ -1278,11 +1329,23 @@ export function createOmnibar({ layers = [], isEntity = () => false } = {}) {
// without a verb may be part of the place's name, so the whole line as a
// place comes first and the plan second. After "go to …" with a request
// peeled off, the place is the one read ("go to London with flights").
// A keyword ahead of the rest of a name ("Fire Island", "Ship Bottom",
// "Radio City Music Hall") begins that name: the leftover is a fragment,
// not a place, so no plan goes there. "tokyo traffic" and "Thermal,
// California" (a comma parts them) keep their plans.
const lower = text.toLowerCase();
const fragment =
ambiguous &&
!peeled &&
placeStep &&
!/[,;]/.test(text) &&
lower.endsWith(placeStep.place.toLowerCase()) &&
!lower.startsWith(placeStep.place.toLowerCase());
if (ambiguous)
return withEntities(
[
peeled ? placeRow(placeStep.place, placeStep.shown) : placeRow(text),
plan,
...(fragment ? [] : [plan]),
...alternatives.filter((row) => row.kind !== 'place'),
ask,
],
+73
View File
@@ -670,3 +670,76 @@ test('a place named with "and" stays whole, and a place keeps how it was typed',
assert.match(istanbul.label, /^İstanbul /);
assert.equal(first('iPhone store').label, 'Go to iPhone store');
});
test('"everything except" keeps the layers named and switches off the rest', () => {
const omnibar = createOmnibar({
layers: layers(['flights', 'radio', 'cctv']),
});
const first = (text) => omnibar.rows(text, { places: [] }).rows[0];
for (const text of [
'hide everything except flights',
'turn off all but live flights',
'clear everything other than flights',
]) {
const plan = first(text);
assert.equal(plan.kind, 'plan', text);
assert.deepEqual(
plan.steps.map(stepOutcome),
['layer(radio,off)', 'layer(cctv,off)'],
text,
);
}
assert.deepEqual(
first('hide everything except flights and cctv').steps.map(stepOutcome),
['layer(radio,off)'],
);
const alone = createOmnibar({ layers: layers(['flights']) });
assert.equal(
alone.rows('hide everything except flights').rows[0].kind,
'none',
);
// Naming no layer to keep is not this reading.
assert.notEqual(first('hide everything except the coast').kind, 'plan');
});
test('"from the map" and a doubled verb do not change the request', () => {
assert.equal(
outcome('remove flights from the map', { on: ['flights'] }),
'layer(flights,off)',
);
assert.equal(
outcome('hide flights off the globe', { on: ['flights'] }),
'layer(flights,off)',
);
assert.equal(normalizeLine('show show flights'), 'show flights');
assert.equal(normalizeLine('turn off turn off flights'), 'turn off flights');
});
test('a grid reference after "near" is the place', () => {
const omnibar = createOmnibar({ layers: layers() });
const plan = omnibar.rows('flights near 14R PU 2090 4906', { places: [] })
.rows[0];
assert.equal(plan.kind, 'plan');
assert.equal(plan.steps[0].kind, 'place');
assert.match(plan.steps[0].place, /^14R PU 2090 4906$/i);
});
test('a keyword that begins a name offers no plan to the rest of it', () => {
const omnibar = createOmnibar({ layers: layers() });
for (const text of [
'Radio City Music Hall',
'Traffic Island',
'radio island',
]) {
const { rows } = omnibar.rows(text, { places: [] });
assert.equal(rows[0].kind, 'place', text);
assert.ok(!rows.some((row) => row.kind === 'plan'), text);
assert.ok(
rows.some((row) => row.kind === 'layer'),
text,
);
}
// A keyword after the place still offers its plan.
const { rows } = omnibar.rows('tokyo traffic', { places: [] });
assert.ok(rows.some((row) => row.kind === 'plan'));
});
+1 -5
View File
@@ -935,11 +935,7 @@ function onKeydown(event) {
if (!items.value.length && !chips.length) return;
event.preventDefault();
dismissed.value = false;
// When the list opens upward (read bottom-up) the keys follow the
// screen: Up moves away from the field.
const list = document.getElementById('gev-omnibar-list');
const upward = list && getComputedStyle(list).flexDirection === 'column-reverse';
const down = (event.key === 'ArrowDown') !== upward;
const down = event.key === 'ArrowDown';
if (inStrip.value) {
inStrip.value = false;
active.value = down ? 0 : items.value.length - 1;