diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 64207f325a..32be325a74 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -7970,7 +7970,12 @@ 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, or says no other layers are on. "remove flights from the +map" is "remove flights", 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 @@ -7998,7 +8003,10 @@ 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 ("Fire Island", "Radio City Music +Hall"), it begins the name: the place and the layer are offered, and no +plan goes to the rest of the name. 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 diff --git a/src/i18n/locales/ar.json b/src/i18n/locales/ar.json index 66e47080a5..438338cdc7 100644 --- a/src/i18n/locales/ar.json +++ b/src/i18n/locales/ar.json @@ -4648,6 +4648,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}", diff --git a/src/i18n/locales/de.json b/src/i18n/locales/de.json index cfec5e6e84..d47cbf6324 100644 --- a/src/i18n/locales/de.json +++ b/src/i18n/locales/de.json @@ -4236,6 +4236,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}", diff --git a/src/i18n/locales/es.json b/src/i18n/locales/es.json index 37e4a2dc4e..489fd34eba 100644 --- a/src/i18n/locales/es.json +++ b/src/i18n/locales/es.json @@ -4339,6 +4339,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}", diff --git a/src/i18n/locales/fr.json b/src/i18n/locales/fr.json index 0f6c0ae519..aec90d6fd9 100644 --- a/src/i18n/locales/fr.json +++ b/src/i18n/locales/fr.json @@ -4339,6 +4339,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}", diff --git a/src/i18n/locales/he.json b/src/i18n/locales/he.json index 5332a9a18f..0dcb7f001d 100644 --- a/src/i18n/locales/he.json +++ b/src/i18n/locales/he.json @@ -4339,6 +4339,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}", diff --git a/src/i18n/locales/it.json b/src/i18n/locales/it.json index dd71b4270b..f517b67208 100644 --- a/src/i18n/locales/it.json +++ b/src/i18n/locales/it.json @@ -4339,6 +4339,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}", diff --git a/src/i18n/locales/ja.json b/src/i18n/locales/ja.json index 6146800f19..2bebb3bcc9 100644 --- a/src/i18n/locales/ja.json +++ b/src/i18n/locales/ja.json @@ -4133,6 +4133,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}", diff --git a/src/i18n/locales/pt.json b/src/i18n/locales/pt.json index 7511af4391..950f139a4b 100644 --- a/src/i18n/locales/pt.json +++ b/src/i18n/locales/pt.json @@ -4339,6 +4339,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}", diff --git a/src/i18n/locales/ru.json b/src/i18n/locales/ru.json index 4c65538e23..0cf2d61122 100644 --- a/src/i18n/locales/ru.json +++ b/src/i18n/locales/ru.json @@ -4442,6 +4442,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}", diff --git a/src/i18n/locales/sv.json b/src/i18n/locales/sv.json index ea3c8b277b..25b5f37976 100644 --- a/src/i18n/locales/sv.json +++ b/src/i18n/locales/sv.json @@ -4236,6 +4236,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}", diff --git a/src/i18n/locales/uk.json b/src/i18n/locales/uk.json index caf2a0aa7f..4293477add 100644 --- a/src/i18n/locales/uk.json +++ b/src/i18n/locales/uk.json @@ -4442,6 +4442,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}", diff --git a/src/i18n/locales/zh-CN.json b/src/i18n/locales/zh-CN.json index 94bcbce7e4..a7e5f73b91 100644 --- a/src/i18n/locales/zh-CN.json +++ b/src/i18n/locales/zh-CN.json @@ -4133,6 +4133,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}", diff --git a/src/i18n/locales/zh-Hant.json b/src/i18n/locales/zh-Hant.json index e4ae873337..9af1d69dfe 100644 --- a/src/i18n/locales/zh-Hant.json +++ b/src/i18n/locales/zh-Hant.json @@ -4133,6 +4133,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}", diff --git a/src/ui/omnibarIntent.js b/src/ui/omnibarIntent.js index b5b222ccd6..9f0f3c59f5 100644 --- a/src/ui/omnibarIntent.js +++ b/src/ui/omnibarIntent.js @@ -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 = /(? 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. diff --git a/src/ui/omnibarRows.js b/src/ui/omnibarRows.js index 0103cf137e..fb37c346f6 100644 --- a/src/ui/omnibarRows.js +++ b/src/ui/omnibarRows.js @@ -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, ], diff --git a/src/ui/omnibarRows.test.mjs b/src/ui/omnibarRows.test.mjs index 648d3b4479..8cdc302250 100644 --- a/src/ui/omnibarRows.test.mjs +++ b/src/ui/omnibarRows.test.mjs @@ -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')); +}); diff --git a/src/ui/views/panels/Omnibar.vue b/src/ui/views/panels/Omnibar.vue index 20a4327b92..7962cb346b 100644 --- a/src/ui/views/panels/Omnibar.vue +++ b/src/ui/views/panels/Omnibar.vue @@ -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;