mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 09:42:21 +00:00
Run "everything except" on Enter, keep every layer it names, and keep plans for places
"hide everything except flights" runs on Enter, as asked in so many words.
A layer to keep written with "the" is read ("except flights and the
radio"), and one that is not read switches nothing off: only Ask GEV is
offered. A keyword before the rest of a name only drops its plan when that
rest starts with a word for a kind of place ("Fire Island"), so
"earthquakes japan" and "flights London" keep theirs. "Saint Vincent and
the Grenadines" stays one place with its "the".
Co-authored-by: Manjunath Paparaju <[email protected]>
This commit is contained in:
1 parent
84d79f5c76
commit
25d33a2e6f
5 files changed
+65
-17
No files matched your search
@@ -140,6 +140,9 @@ export function mayRunOnEnter(item, text, parsed, context) {
|
||||
case 'open-draw':
|
||||
return verb;
|
||||
case 'plan':
|
||||
// A plan the whole line asked for in so many words ("hide everything
|
||||
// except flights") runs.
|
||||
if (item.asked) return true;
|
||||
// A command row runs on its exact label only; a verb that merely
|
||||
// lists it ("hide", "turn off") offers it.
|
||||
if (item.command) return Boolean(item.named);
|
||||
|
||||
+12
-4
@@ -402,8 +402,16 @@ const COMPOUND_PLACES = new Set([
|
||||
'dadra and nagar haveli',
|
||||
'brighton and hove',
|
||||
]);
|
||||
const isCompoundPlace = (first, second) =>
|
||||
COMPOUND_PLACES.has(`${first} and ${second}`.toLowerCase());
|
||||
/**
|
||||
* The joining words of a compound place ("and", or "and the" when "the" was
|
||||
* read off the second part: "Saint Vincent and the Grenadines"), or null.
|
||||
*/
|
||||
const compoundJoin = (first, second) =>
|
||||
COMPOUND_PLACES.has(`${first} and ${second}`.toLowerCase())
|
||||
? ' and '
|
||||
: COMPOUND_PLACES.has(`${first} and the ${second}`.toLowerCase())
|
||||
? ' and the '
|
||||
: null;
|
||||
|
||||
/**
|
||||
* Lower case one character at a time, so the line keeps its length and
|
||||
@@ -598,8 +606,8 @@ export function parseOmnibar(
|
||||
place &&
|
||||
afterPlace &&
|
||||
(separator === 'and' || separator === '&') &&
|
||||
isCompoundPlace(place.split(', ').at(-1), value);
|
||||
if (joinsName) place += ` and ${value}`;
|
||||
compoundJoin(place.split(', ').at(-1), value);
|
||||
if (joinsName) place += `${joinsName}${value}`;
|
||||
else if (place && bare && afterBarePlaceAnd) place += ` and ${value}`;
|
||||
else if (place && !afterPlaceComma) {
|
||||
if (separator === 'and') extraPlaces.push(value);
|
||||
|
||||
+16
-5
@@ -154,6 +154,10 @@ 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"). */
|
||||
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;
|
||||
|
||||
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.
|
||||
@@ -940,11 +944,14 @@ export function createOmnibar({ layers = [], isEntity = () => false } = {}) {
|
||||
function exceptRows(line, ask) {
|
||||
const match = EXCEPT.exec(line.toLowerCase());
|
||||
if (!match) return null;
|
||||
// Every layer to keep must be one: with a name not read ("flights and
|
||||
// the fog") nothing is switched off, and only GEV is offered.
|
||||
const kept = match[1]
|
||||
.split(/\s*(?:,|\band\b|&)\s*/)
|
||||
.map((term) => matchLayers(term)[0])
|
||||
.filter(named);
|
||||
.filter(Boolean)
|
||||
.map((term) => matchLayers(term.replace(/^(?:the|my)\s+/, ''))[0]);
|
||||
if (!kept.length) return null;
|
||||
if (!kept.every(named)) return [ask];
|
||||
const keptIds = new Set(kept.map((layer) => layer.id));
|
||||
const steps = all()
|
||||
.filter((layer) => layer.enabled && !keptIds.has(layer.id))
|
||||
@@ -966,6 +973,8 @@ export function createOmnibar({ layers = [], isEntity = () => false } = {}) {
|
||||
kind: 'plan',
|
||||
icon: 'bolt',
|
||||
steps,
|
||||
// Asked for in so many words: Enter runs it.
|
||||
asked: true,
|
||||
label: steps.map(stepLabel).join(' · '),
|
||||
hint: t('Do all'),
|
||||
},
|
||||
@@ -1330,8 +1339,9 @@ export function createOmnibar({ layers = [], isEntity = () => false } = {}) {
|
||||
// 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,
|
||||
// "Radio City Music Hall") begins that name when what is left starts
|
||||
// with a word for a kind of place: a fragment, not a place, so no plan
|
||||
// goes there. "earthquakes japan", "tokyo traffic" and "Thermal,
|
||||
// California" (a comma parts them) keep their plans.
|
||||
const lower = text.toLowerCase();
|
||||
const fragment =
|
||||
@@ -1340,7 +1350,8 @@ export function createOmnibar({ layers = [], isEntity = () => false } = {}) {
|
||||
placeStep &&
|
||||
!/[,;]/.test(text) &&
|
||||
lower.endsWith(placeStep.place.toLowerCase()) &&
|
||||
!lower.startsWith(placeStep.place.toLowerCase());
|
||||
!lower.startsWith(placeStep.place.toLowerCase()) &&
|
||||
NAME_TAIL.test(placeStep.place);
|
||||
if (ambiguous)
|
||||
return withEntities(
|
||||
[
|
||||
|
||||
@@ -659,6 +659,10 @@ test('a place named with "and" stays whole, and a place keeps how it was typed',
|
||||
first('flights near Bosnia & Herzegovina').steps[0].place,
|
||||
'bosnia and herzegovina',
|
||||
);
|
||||
assert.equal(
|
||||
first('flights near Saint Vincent and the Grenadines').steps[0].place,
|
||||
'saint vincent and the grenadines',
|
||||
);
|
||||
// Two places joined by "and" are still two.
|
||||
assert.equal(
|
||||
first('flights near Austin and Dallas').steps[0].place,
|
||||
@@ -690,9 +694,23 @@ test('"everything except" keeps the layers named and switches off the rest', ()
|
||||
);
|
||||
}
|
||||
assert.deepEqual(
|
||||
first('hide everything except flights and cctv').steps.map(stepOutcome),
|
||||
first('hide everything except flights and the cctv').steps.map(stepOutcome),
|
||||
['layer(radio,off)'],
|
||||
);
|
||||
// Enter runs it: the line asked for it in so many words.
|
||||
assert.equal(
|
||||
outcome('hide everything except flights', { on: ['flights', 'radio'] }),
|
||||
'layer(radio,off)',
|
||||
);
|
||||
// A layer to keep that is not read switches nothing off.
|
||||
const unread = omnibar.rows('hide everything except flights and the fog', {
|
||||
places: [],
|
||||
});
|
||||
assert.deepEqual(
|
||||
unread.rows.map((row) => row.kind),
|
||||
['ask'],
|
||||
);
|
||||
assert.equal(unread.defaultIndex, -1);
|
||||
const alone = createOmnibar({ layers: layers(['flights']) });
|
||||
assert.equal(
|
||||
alone.rows('hide everything except flights').rows[0].kind,
|
||||
@@ -739,7 +757,13 @@ test('a keyword that begins a name offers no plan to the rest of it', () => {
|
||||
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'));
|
||||
// A keyword after the place, or before a place that is no name's
|
||||
// fragment, still offers its plan.
|
||||
for (const text of ['tokyo traffic', 'earthquakes japan', 'radio London']) {
|
||||
const { rows } = omnibar.rows(text, { places: [] });
|
||||
assert.ok(
|
||||
rows.some((row) => row.kind === 'plan'),
|
||||
text,
|
||||
);
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user