mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 09:42:21 +00:00
Merge pull request #1831 from bilawalsidhu/samehkhamis/omnibar-reading-fixes
Read more Omnibar lines the way they are meant
This commit is contained in:
20 files changed
+528
-23
No files matched your search
@@ -0,0 +1,7 @@
|
||||
- The Omnibar reads more lines the way they are meant: a country named with
|
||||
"and" stays whole ("flights near Trinidad and Tobago"), places show as they
|
||||
were typed, "hide everything except flights" switches off every other
|
||||
layer that is on, "remove flights from the map" and a doubled verb are
|
||||
understood, a grid reference after "near" is the place, and a layer word
|
||||
that begins a name ("Fire Island") no longer offers a plan to the rest of
|
||||
it (manjunath22466, samehkhamis, #1831).
|
||||
+17
-2
@@ -8061,7 +8061,18 @@ over").
|
||||
Otherwise the place row is the default and moves first ("Thermal,
|
||||
California", "radio near tokyo" searches Tokyo), and any plan or command is
|
||||
offered after it; a line with neither ("hi", "NY", "?") runs nothing. "hide everything near tokyo" clears the layers and flies to
|
||||
Tokyo. Following needs a callsign or ICAO address (letters and a digit), a
|
||||
Tokyo. "hide everything except flights" (or "all but", "other than", with
|
||||
"turn off", "clear" or "remove") switches off every layer that is on but
|
||||
the ones named, on Enter, or says no other layers are on; with a layer to
|
||||
keep that is not read, nothing is switched off and only Ask GEV is offered.
|
||||
While Space Missions is on, keeping either it or Satellites keeps both,
|
||||
since Space Missions draws through Satellites. "remove flights from the
|
||||
map" is "remove flights", after hide, remove,
|
||||
turn off, switch off or disable, and after clear only for the whole map
|
||||
("clear everything except flights from the map", "clear the layers from
|
||||
the map"; "show me the view from the map" is a question), a doubled verb ("hide hide everything") is read
|
||||
once, and a grid reference after "near" is the place ("flights near 14R PU
|
||||
2090 4906"). Following needs a callsign or ICAO address (letters and a digit), a
|
||||
nine-digit MMSI or the name of something loaded on the map, so "Track
|
||||
Hill" and "Track 29" are places; "nearest plane" counts alone or before a
|
||||
place ("Nearest Plane Crash Site" is a name), and "goto" only with a place
|
||||
@@ -8089,7 +8100,11 @@ noir", "go to London with flights"), a switch and a layer ("go to tokyo show
|
||||
flights"), or a comma part that is exactly a style, map, camera move or
|
||||
layer ("go to Tokyo, north up"). A line with one keyword and no verb beside
|
||||
the rest of a name ("Tilt Cove", "tokyo traffic", "Hurricane, Utah") offers
|
||||
the whole line as a place first and the plan second. Further places joined
|
||||
the whole line as a place first and the plan second. When that keyword
|
||||
starts the line with no comma after it and the rest is only a word for a
|
||||
kind of place ("Fire Island", "Radio City"), it begins the name: the place
|
||||
and the layer are offered, and no plan goes to the rest ("earthquakes
|
||||
japan" and "traffic city hall" keep their plans). Further places joined
|
||||
with "and" are offered as their own rows. Things loaded on the map that
|
||||
match the line are offered too: a callsign, tail number or transponder
|
||||
code puts them first, and otherwise the place row keeps the top, so
|
||||
|
||||
@@ -4655,6 +4655,7 @@
|
||||
"Turn off": "إيقاف",
|
||||
"Command": "أمر",
|
||||
"No layers are on": "لا توجد طبقات مفعّلة",
|
||||
"No other layers are on": "لا توجد طبقات أخرى مفعّلة",
|
||||
"No matching layers": "لا توجد طبقات مطابقة",
|
||||
"Show me {thing} settings": "عرض إعدادات {thing}",
|
||||
"Show me how: {thing}": "طريقة الاستخدام: {thing}",
|
||||
|
||||
@@ -4243,6 +4243,7 @@
|
||||
"Turn off": "Ausschalten",
|
||||
"Command": "Befehl",
|
||||
"No layers are on": "Keine Ebenen aktiv",
|
||||
"No other layers are on": "Keine anderen Ebenen aktiv",
|
||||
"No matching layers": "Keine passenden Ebenen",
|
||||
"Show me {thing} settings": "Einstellungen für {thing} zeigen",
|
||||
"Show me how: {thing}": "Anleitung anzeigen: {thing}",
|
||||
|
||||
@@ -4346,6 +4346,7 @@
|
||||
"Turn off": "Desactivar",
|
||||
"Command": "Comando",
|
||||
"No layers are on": "No hay capas activas",
|
||||
"No other layers are on": "No hay otras capas activas",
|
||||
"No matching layers": "No se encontraron capas",
|
||||
"Show me {thing} settings": "Muéstrame los ajustes de {thing}",
|
||||
"Show me how: {thing}": "Muéstrame cómo: {thing}",
|
||||
|
||||
@@ -4346,6 +4346,7 @@
|
||||
"Turn off": "Désactiver",
|
||||
"Command": "Commande",
|
||||
"No layers are on": "Aucune couche active",
|
||||
"No other layers are on": "Aucune autre couche active",
|
||||
"No matching layers": "Aucune couche correspondante",
|
||||
"Show me {thing} settings": "Montrez-moi les réglages de {thing}",
|
||||
"Show me how: {thing}": "Montrez-moi comment faire : {thing}",
|
||||
|
||||
@@ -4346,6 +4346,7 @@
|
||||
"Turn off": "כיבוי",
|
||||
"Command": "פקודה",
|
||||
"No layers are on": "אין שכבות פעילות",
|
||||
"No other layers are on": "אין שכבות אחרות פעילות",
|
||||
"No matching layers": "אין שכבות תואמות",
|
||||
"Show me {thing} settings": "הצגת ההגדרות של {thing}",
|
||||
"Show me how: {thing}": "איך עושים זאת: {thing}",
|
||||
|
||||
@@ -4346,6 +4346,7 @@
|
||||
"Turn off": "Disattiva",
|
||||
"Command": "Comando",
|
||||
"No layers are on": "Nessun livello attivo",
|
||||
"No other layers are on": "Nessun altro livello attivo",
|
||||
"No matching layers": "Nessun livello corrispondente",
|
||||
"Show me {thing} settings": "Mostrami le impostazioni di {thing}",
|
||||
"Show me how: {thing}": "Mostrami come: {thing}",
|
||||
|
||||
@@ -4140,6 +4140,7 @@
|
||||
"Turn off": "オフにする",
|
||||
"Command": "コマンド",
|
||||
"No layers are on": "オンになっているレイヤーはありません",
|
||||
"No other layers are on": "他にオンになっているレイヤーはありません",
|
||||
"No matching layers": "該当するレイヤーはありません",
|
||||
"Show me {thing} settings": "{thing}の設定を表示",
|
||||
"Show me how: {thing}": "使い方を見る:{thing}",
|
||||
|
||||
@@ -4346,6 +4346,7 @@
|
||||
"Turn off": "Desativar",
|
||||
"Command": "Comando",
|
||||
"No layers are on": "Nenhuma camada ativa",
|
||||
"No other layers are on": "Não há outras camadas ativas",
|
||||
"No matching layers": "Nenhuma camada encontrada",
|
||||
"Show me {thing} settings": "Mostre as configurações de {thing}",
|
||||
"Show me how: {thing}": "Mostre como fazer: {thing}",
|
||||
|
||||
@@ -4449,6 +4449,7 @@
|
||||
"Turn off": "Выключить",
|
||||
"Command": "Команда",
|
||||
"No layers are on": "Нет включённых слоёв",
|
||||
"No other layers are on": "Других включённых слоёв нет",
|
||||
"No matching layers": "Подходящие слои не найдены",
|
||||
"Show me {thing} settings": "Показать настройки для {thing}",
|
||||
"Show me how: {thing}": "Показать как: {thing}",
|
||||
|
||||
@@ -4243,6 +4243,7 @@
|
||||
"Turn off": "Slå av",
|
||||
"Command": "Kommando",
|
||||
"No layers are on": "Inga lager är på",
|
||||
"No other layers are on": "Inga andra lager är på",
|
||||
"No matching layers": "Inga matchande lager",
|
||||
"Show me {thing} settings": "Visa inställningarna för {thing}",
|
||||
"Show me how: {thing}": "Visa hur: {thing}",
|
||||
|
||||
@@ -4449,6 +4449,7 @@
|
||||
"Turn off": "Вимкнути",
|
||||
"Command": "Команда",
|
||||
"No layers are on": "Немає увімкнених шарів",
|
||||
"No other layers are on": "Інших увімкнених шарів немає",
|
||||
"No matching layers": "Відповідних шарів не знайдено",
|
||||
"Show me {thing} settings": "Показати налаштування для {thing}",
|
||||
"Show me how: {thing}": "Показати як: {thing}",
|
||||
|
||||
@@ -4140,6 +4140,7 @@
|
||||
"Turn off": "关闭",
|
||||
"Command": "命令",
|
||||
"No layers are on": "没有已启用的图层",
|
||||
"No other layers are on": "没有其他已启用的图层",
|
||||
"No matching layers": "没有匹配的图层",
|
||||
"Show me {thing} settings": "显示{thing}的设置",
|
||||
"Show me how: {thing}": "查看操作方法:{thing}",
|
||||
|
||||
@@ -4140,6 +4140,7 @@
|
||||
"Turn off": "關閉",
|
||||
"Command": "命令",
|
||||
"No layers are on": "沒有已啟用的圖層",
|
||||
"No other layers are on": "沒有其他已啟用的圖層",
|
||||
"No matching layers": "沒有匹配的圖層",
|
||||
"Show me {thing} settings": "顯示{thing}的設置",
|
||||
"Show me how: {thing}": "查看操作方法:{thing}",
|
||||
|
||||
@@ -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);
|
||||
|
||||
+139
-4
@@ -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
|
||||
@@ -293,7 +299,25 @@ export function normalizeLine(text, { isRequest = isPlainRequest } = {}) {
|
||||
.replace(/(?:\s*,\s*|\s+)(?:please|pls|plz)$/i, '')
|
||||
.replace(end, '')
|
||||
.trim();
|
||||
return polite !== line && polite && isRequest(polite) ? polite : line;
|
||||
const read = polite !== line && polite && isRequest(polite) ? polite : line;
|
||||
// "remove flights from the map", "clear everything except ships from the
|
||||
// map": the map is where every layer is taken from. Not the verb's own
|
||||
// "off" ("turn off the screen" is no layer switch), not after "show"
|
||||
// ("show me the view from the map" is a question), and after "clear"
|
||||
// only for the whole map ("clear all flights" would read as a place).
|
||||
const bare = read.replace(
|
||||
/^((?:turn|switch) off|hide|remove|disable|clear)\s+(\S.*?)\s+(?:from|off) (?:the )?(?:map|globe|screen|view)$/i,
|
||||
'$1 $2',
|
||||
);
|
||||
if (bare === read || !/^clear\b/i.test(bare)) return bare;
|
||||
// "clear" takes the whole map: "clear flights" would read as a place.
|
||||
const lower = bare.toLowerCase();
|
||||
return CLEAR_ALL.test(lower) ||
|
||||
/^clear (?:everything|all(?: the)?(?: other)?(?: layers?)?|every layer) (?:except|but|other than|apart from|besides|save for)\b/.test(
|
||||
lower,
|
||||
)
|
||||
? bare
|
||||
: read;
|
||||
}
|
||||
|
||||
/** A request by its own words: a verb starting it, or a real question. */
|
||||
@@ -367,6 +391,74 @@ const GO_TAIL =
|
||||
const SEPARATORS =
|
||||
/(\s*(?:,|;(?!\s*[-+]?\d)|\+(?!\d)|&|\band then\b|\bthen\b|\band\b|\balso\b)\s*)/;
|
||||
|
||||
/**
|
||||
* Places whose own name holds "and" (or "&"), kept whole after "near" or
|
||||
* "in" instead of read as two places: "flights near Trinidad and Tobago".
|
||||
*/
|
||||
const COMPOUND_PLACES = new Set([
|
||||
'trinidad and tobago',
|
||||
'antigua and barbuda',
|
||||
'bosnia and herzegovina',
|
||||
'saint kitts and nevis',
|
||||
'st kitts and nevis',
|
||||
'st. kitts and nevis',
|
||||
'saint vincent and the grenadines',
|
||||
'st vincent and the grenadines',
|
||||
'st. vincent and the grenadines',
|
||||
'sao tome and principe',
|
||||
'são tomé and príncipe',
|
||||
'turks and caicos',
|
||||
'turks and caicos islands',
|
||||
'wallis and futuna',
|
||||
'saint pierre and miquelon',
|
||||
'heard island and mcdonald islands',
|
||||
'svalbard and jan mayen',
|
||||
'south georgia and the south sandwich islands',
|
||||
'newfoundland and labrador',
|
||||
'jammu and kashmir',
|
||||
'andaman and nicobar islands',
|
||||
'dadra and nagar haveli',
|
||||
'brighton and hove',
|
||||
]);
|
||||
/**
|
||||
* 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
|
||||
* "İstanbul" reads "istanbul" (not "i̇stanbul" with a combining dot).
|
||||
*/
|
||||
function lowerEach(text) {
|
||||
return Array.from(text, (char) =>
|
||||
char === 'İ' ? 'i' : char.toLowerCase().normalize('NFC'),
|
||||
).join('');
|
||||
}
|
||||
|
||||
/**
|
||||
* A place as it was typed: "İstanbul", "iPhone store", "McAllen" are kept,
|
||||
* where the line read them in lower case. A place the line put together
|
||||
* ("Trinidad and Tobago" from "Trinidad & Tobago") stays as read.
|
||||
*/
|
||||
export function asTypedIn(raw, place) {
|
||||
const lowered = lowerEach(raw).replace(/\s+/g, ' ');
|
||||
const spaced = raw.replace(/\s+/g, ' ');
|
||||
if (lowered.length !== spaced.length) return place;
|
||||
const at = lowered.indexOf(place);
|
||||
if (at < 0) return place;
|
||||
const before = lowered[at - 1];
|
||||
const after = lowered[at + place.length];
|
||||
if (/[\p{L}\p{N}]/u.test(before || '') || /[\p{L}\p{N}]/u.test(after || ''))
|
||||
return place;
|
||||
return spaced.slice(at, at + place.length);
|
||||
}
|
||||
|
||||
function tidy(text) {
|
||||
return text.replace(/\s+/g, ' ').trim();
|
||||
}
|
||||
@@ -415,7 +507,7 @@ export function parseOmnibar(
|
||||
{ isEntity = () => false } = {},
|
||||
) {
|
||||
const raw = String(text || '').trim();
|
||||
const line = tidy(raw.toLowerCase()).replace(
|
||||
const line = tidy(lowerEach(raw)).replace(
|
||||
/\b(black[- ]and[- ]white|b ?& ?w)\b/g,
|
||||
'noir',
|
||||
);
|
||||
@@ -448,6 +540,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.
|
||||
@@ -483,9 +578,12 @@ export function parseOmnibar(
|
||||
for (let i = 0; i < clauses.length; i += 2) {
|
||||
let clause = tidy(clauses[i]);
|
||||
const separator = clauses[i - 1]?.trim();
|
||||
const afterPlace = previousHadPlace;
|
||||
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;
|
||||
@@ -526,9 +624,35 @@ export function parseOmnibar(
|
||||
const addPlace = (value, { bare = false, leftover = false } = {}) => {
|
||||
if (!value) return;
|
||||
if (leftover) placeClauses.add(i);
|
||||
// "near Trinidad and Tobago", "in Bosnia & Herzegovina": one place.
|
||||
const joinsName =
|
||||
place &&
|
||||
afterPlace &&
|
||||
(separator === 'and' || separator === '&') &&
|
||||
compoundJoin(place.split(', ').at(-1), 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;
|
||||
@@ -834,7 +958,18 @@ export function parseOmnibar(
|
||||
// Thermal"): no plan runs on Enter; the line may still be a name.
|
||||
const unasked = steps.length > 0 && steps.every((step) => !asked.has(step));
|
||||
if (place && !placeFrom) placeFrom = placeBare ? 'bare' : 'near';
|
||||
if (place) steps.unshift({ kind: 'place', place });
|
||||
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.
|
||||
Object.defineProperty(step, 'shown', { value: asTypedIn(raw, place) });
|
||||
steps.unshift(step);
|
||||
}
|
||||
steps.verb = LAYER_OFF.test(line) || LAYER_ON.test(line) || GO.test(line);
|
||||
// Following happens once the camera has settled on the new view.
|
||||
steps.sort((a, b) => (a.kind === 'follow') - (b.kind === 'follow'));
|
||||
|
||||
+109
-12
@@ -22,6 +22,7 @@ import {
|
||||
hasActionVerb,
|
||||
isPanelText,
|
||||
isRealQuestion,
|
||||
asTypedIn,
|
||||
isWholeMapClear,
|
||||
magnitudeFloor,
|
||||
normalizeLine,
|
||||
@@ -152,6 +153,24 @@ 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/;
|
||||
/**
|
||||
* A word for a kind of place, alone: after a keyword it ends a name ("Fire
|
||||
* Island", "Ship Bottom", "Radio City"), and is no place to go to by itself.
|
||||
* Followed by more words it may begin one ("City Hall", "Peak District").
|
||||
*/
|
||||
const NAME_TAIL =
|
||||
/^(?: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)$/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.
|
||||
export const POPULAR_LAYERS = [
|
||||
'flights',
|
||||
@@ -393,12 +412,19 @@ const SMALL_WORDS = new Set([
|
||||
'da',
|
||||
'des',
|
||||
]);
|
||||
/**
|
||||
* A place's name for a row: as typed when it has a capital ("iPhone store",
|
||||
* "McAllen", "İstanbul"), else each word capitalised but the small joining
|
||||
* ones ("santa fe de bogotá" reads "Santa Fe de Bogotá").
|
||||
*/
|
||||
export const titleCase = (text) =>
|
||||
text.replace(/\S+/g, (word, at) =>
|
||||
at > 0 && SMALL_WORDS.has(word)
|
||||
? word
|
||||
: word[0].toUpperCase() + word.slice(1),
|
||||
);
|
||||
/\p{Lu}/u.test(text)
|
||||
? text
|
||||
: text.replace(/\S+/g, (word, at) =>
|
||||
at > 0 && SMALL_WORDS.has(word)
|
||||
? word
|
||||
: word[0].toUpperCase() + word.slice(1),
|
||||
);
|
||||
|
||||
const STYLE_LABELS = {
|
||||
noir: msg('Style: Noir'),
|
||||
@@ -707,7 +733,7 @@ export function matchCommands(text) {
|
||||
export function stepLabel(step) {
|
||||
switch (step.kind) {
|
||||
case 'place':
|
||||
return titleCase(step.place);
|
||||
return titleCase(step.shown ?? step.place);
|
||||
case 'layer':
|
||||
return step.enabled
|
||||
? t('{layer} on', { layer: step.layer.shown })
|
||||
@@ -819,12 +845,13 @@ const askRow = (text) => ({
|
||||
label: t('Ask GEV: “{query}”', { query: text }),
|
||||
hint: t('Opens chat'),
|
||||
});
|
||||
const placeRow = (place) => ({
|
||||
/** `shown`: the place as typed, for the label ("İstanbul", "iPhone store"). */
|
||||
const placeRow = (place, shown = place) => ({
|
||||
key: `place:${place}`,
|
||||
kind: 'place',
|
||||
icon: 'location_on',
|
||||
place,
|
||||
label: t('Go to {place}', { place: titleCase(place) }),
|
||||
label: t('Go to {place}', { place: titleCase(shown) }),
|
||||
hint: t('Place or coordinates'),
|
||||
});
|
||||
/**
|
||||
@@ -914,6 +941,60 @@ export function createOmnibar({ layers = [], isEntity = () => false } = {}) {
|
||||
return cache.get(line);
|
||||
}
|
||||
|
||||
/**
|
||||
* "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;
|
||||
// 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*/)
|
||||
.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));
|
||||
// Keeping either of a pair keeps both while the first is on: 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 (on && (keptIds.has(layer) || 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 }));
|
||||
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,
|
||||
// Asked for in so many words: Enter runs it.
|
||||
asked: true,
|
||||
label: steps.map(stepLabel).join(' · '),
|
||||
hint: t('Do all'),
|
||||
},
|
||||
ask,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* "turn on …", "hide …", "toggle …", alone or with a few letters: the
|
||||
* layers and features that switch that way, never places. Null when the
|
||||
@@ -921,6 +1002,8 @@ export function createOmnibar({ layers = [], isEntity = () => false } = {}) {
|
||||
* ("Show Low, AZ").
|
||||
*/
|
||||
function switchRows(line, ask) {
|
||||
const excepted = exceptRows(line, ask);
|
||||
if (excepted) return excepted;
|
||||
const switching = line.toLowerCase().match(SWITCH);
|
||||
if (
|
||||
!switching ||
|
||||
@@ -1049,7 +1132,7 @@ export function createOmnibar({ layers = [], isEntity = () => false } = {}) {
|
||||
realPlaces.length
|
||||
? realPlaces
|
||||
: place.trim().length >= minPlaceChars(place)
|
||||
? [placeRow(place)]
|
||||
? [placeRow(place, asTypedIn(text, place))]
|
||||
: [];
|
||||
|
||||
const titled = writtenAsName(text.split(/\s+/));
|
||||
@@ -1260,7 +1343,7 @@ export function createOmnibar({ layers = [], isEntity = () => false } = {}) {
|
||||
...(placeStep ? placeRows(placeStep.place).slice(0, 2) : []),
|
||||
// "near New York and Paris": the plan goes to the first; the others
|
||||
// are offered rather than dropped.
|
||||
...extraPlaces.map((extra) => placeRow(extra)),
|
||||
...extraPlaces.map((extra) => placeRow(extra, asTypedIn(text, extra))),
|
||||
...steps
|
||||
.filter((step) => step.kind === 'layer')
|
||||
.map((step) => layerRow(step.layer, step.enabled)),
|
||||
@@ -1269,11 +1352,25 @@ 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")
|
||||
// begins that name when what is left is only a word for a kind of
|
||||
// place: a fragment, not a place, so no plan goes there. "earthquakes
|
||||
// japan", "traffic city hall", "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()) &&
|
||||
NAME_TAIL.test(placeStep.place);
|
||||
if (ambiguous)
|
||||
return withEntities(
|
||||
[
|
||||
placeRow(peeled ? placeStep.place : text),
|
||||
plan,
|
||||
peeled ? placeRow(placeStep.place, placeStep.shown) : placeRow(text),
|
||||
...(fragment ? [] : [plan]),
|
||||
...alternatives.filter((row) => row.kind !== 'place'),
|
||||
ask,
|
||||
],
|
||||
|
||||
@@ -646,3 +646,242 @@ test('several switches in one line are one plan', () => {
|
||||
assert.equal(rows[defaultIndex].kind, 'plan', text);
|
||||
}
|
||||
});
|
||||
|
||||
test('a place named with "and" stays whole, and a place keeps how it was typed', () => {
|
||||
const omnibar = createOmnibar({
|
||||
layers: [{ id: 'flights', name: 'Live Flights', enabled: false }],
|
||||
});
|
||||
const first = (text) => omnibar.rows(text, { places: [] }).rows[0];
|
||||
const plan = first('flights near Trinidad and Tobago');
|
||||
assert.equal(plan.kind, 'plan');
|
||||
assert.equal(plan.steps[0].place, 'trinidad and tobago');
|
||||
assert.equal(
|
||||
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,
|
||||
'austin',
|
||||
);
|
||||
// "İstanbul" is searched without a stray combining dot, and labelled as typed.
|
||||
const istanbul = first('show flights in İstanbul');
|
||||
assert.equal(istanbul.steps[0].place, 'istanbul');
|
||||
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 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,
|
||||
'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', '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, or before a place that is no name's
|
||||
// fragment, still offers its plan.
|
||||
for (const text of [
|
||||
'tokyo traffic',
|
||||
'earthquakes japan',
|
||||
'radio London',
|
||||
'traffic city hall',
|
||||
'traffic county cork',
|
||||
'earthquakes valley forge',
|
||||
'traffic road to hana',
|
||||
]) {
|
||||
const { rows } = omnibar.rows(text, { places: [] });
|
||||
assert.ok(
|
||||
rows.some((row) => row.kind === 'plan'),
|
||||
text,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
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('"except" leaves Satellites to switch off with Space Missions off', () => {
|
||||
const omnibar = createOmnibar({
|
||||
layers: [
|
||||
{ id: 'flights', name: 'Live Flights', enabled: true },
|
||||
{ id: 'satellites', name: 'Satellites', enabled: true },
|
||||
{ id: 'rocket-launches', name: 'Space Missions', enabled: false },
|
||||
],
|
||||
});
|
||||
assert.deepEqual(
|
||||
omnibar
|
||||
.rows('hide everything except space missions', { places: [] })
|
||||
.rows[0].steps.map(stepOutcome),
|
||||
['layer(flights,off)', 'layer(satellites,off)'],
|
||||
);
|
||||
for (const text of [
|
||||
'hide everything except flights from the map',
|
||||
'clear everything except flights from the map',
|
||||
'please clear everything except flights from the map',
|
||||
'hide everything except flights from the map, please',
|
||||
])
|
||||
assert.deepEqual(
|
||||
omnibar.rows(text, { places: [] }).rows[0].steps.map(stepOutcome),
|
||||
['layer(satellites,off)'],
|
||||
text,
|
||||
);
|
||||
// "clear" takes the ending off only for the whole map: "clear flights
|
||||
// from the map" never offers to turn Flights on.
|
||||
for (const text of [
|
||||
'clear flights from the map',
|
||||
'clear all flights from the map',
|
||||
'clear all flights except ships from the map',
|
||||
])
|
||||
assert.ok(
|
||||
!omnibar
|
||||
.rows(text, { places: [] })
|
||||
.rows.some((row) =>
|
||||
(row.steps || []).some(
|
||||
(step) => step.kind === 'layer' && step.enabled,
|
||||
),
|
||||
),
|
||||
);
|
||||
// After "show" the ending is part of what is asked.
|
||||
assert.equal(
|
||||
omnibar.rows('show me the view from the map', { places: [] }).defaultIndex,
|
||||
-1,
|
||||
);
|
||||
// The whole map cleared "from the map" is the same plan, not a place.
|
||||
for (const text of [
|
||||
'hide everything from the map',
|
||||
'remove all layers from the map',
|
||||
'clear the layers from the map',
|
||||
]) {
|
||||
const { rows } = omnibar.rows(text, { places: [] });
|
||||
assert.equal(rows[0].kind, 'plan', text);
|
||||
assert.ok(!rows.some((row) => row.kind === 'place'), 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,
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user