Fly to coordinates after "go to", and count a layer only in a place

- "go to 30.27, -97.74", "go to 14R PU 2090 4906" and "flights near
  30.27, -97.74" were refused as private (their digits) or sent to the
  place service as text; coordinates named as the line's place are now a
  spot to fly to, and the rest of the line is what the privacy rules read.
- A count ("flights over Texas") is offered only for a layer in or near
  a place: "Ship Bottom", "Radio City Music Hall" and "radio settings"
  are no longer counts that Enter would run.
- "go to ," sends nothing to the place service.

Co-authored-by: Manjunath Paparaju <[email protected]>
This commit is contained in:
Sameh KhamisandManjunath Paparaju authored and Sameh Khamis committed 2026-11-18 14:31:45 -08:00
1 parent 8f577eb0c3
commit 9a0bccf09b
2 files changed
+72 -3

No files matched your search

+35 -3
View File
@@ -787,6 +787,23 @@ export function coordinateTarget(text) {
return { ...point, kind: grid ? 'MGRS' : t('Coordinates') };
}
/**
* The coordinates a line names as its place ("go to 30.27, -97.74", "flights
* near 48.85 2.35"), as typed, or null.
*/
function placeCoordinates(text, parsed) {
const place = parsed.steps.find((step) => step.kind === 'place')?.place;
if (!place || !coordinateTarget(place)) return null;
const at = text.toLowerCase().indexOf(place.toLowerCase());
return at < 0 ? null : text.slice(at, at + place.length);
}
/** The line without the coordinates it names, for the privacy rules. */
function withoutCoordinates(text, parsed) {
const coordinates = placeCoordinates(text, parsed);
return coordinates ? text.replace(coordinates, ' ').trim() : text;
}
function coordinateRow(target, text) {
const where = `${Math.abs(target.lat).toFixed(4)}°${target.lat >= 0 ? 'N' : 'S'} ${Math.abs(target.lon).toFixed(4)}°${target.lon >= 0 ? 'E' : 'W'}`;
return {
@@ -1412,19 +1429,26 @@ export function createOmnibar({ layers = [], isEntity = () => false } = {}) {
defaultIndex: enterDefault(ordered, line, parsed, enterContext),
};
};
const target = coordinateTarget(line);
const coordinates = placeCoordinates(text, parsed);
const onlyPlace = parsed.steps.length === 1 && coordinates;
const target =
coordinateTarget(line) ??
(onlyPlace ? coordinateTarget(coordinates) : null);
// Coordinates are a spot, not a secret; nothing about them leaves the
// app unless GEV is asked.
if (target)
return finish([
coordinateRow(target, line),
coordinateRow(target, onlyPlace ? coordinates : line),
...(mayBePrivate(text) ? [] : [askRow(text)]),
]);
// Coordinates named as a line's place ("flights near 30.27, -97.74") are
// no secret either: the rest of the line is what the rules read.
const privateText = withoutCoordinates(text, parsed);
// Text that may be private (an email address, a card, phone, SSN or
// account number, a password or key) is never offered to the place
// service, the place search or GEV: only things already loaded on the
// map may match it.
if (mayBePrivate(text))
if (mayBePrivate(privateText))
return finish([
...withEntities([], line, context.entities),
// An address may look like a number to keep; a bare number never
@@ -1500,7 +1524,11 @@ export function createOmnibar({ layers = [], isEntity = () => false } = {}) {
if (switchRows(line, askRow(text))) return null;
const { parsed } = read(line);
if (parsed.question || parsed.sentence) return null;
// Coordinates are flown to as they are, never looked up as a name.
if (placeCoordinates(text, parsed)) return null;
const place = parsed.steps.find((step) => step.kind === 'place');
// "go to ,": punctuation names no place.
if (place && !/[\p{L}\p{N}]/u.test(place.place)) return null;
// A line of commands with no place in it ("night vision", "zoom in").
if (parsed.steps.length && !place) return null;
// After "go to … , noir" the place read is the one to look up.
@@ -1524,6 +1552,10 @@ export function createOmnibar({ layers = [], isEntity = () => false } = {}) {
const layer = parsed.steps.find((step) => step.kind === 'layer');
const place = parsed.steps.find((step) => step.kind === 'place');
if (!layer || !place || layer.enabled === false) return null;
// Only a layer counted in or near a place ("flights over Texas"): a
// line that may be one name ("Ship Bottom", "Satellite Beach") or asks
// for something else ("radio settings") is no count.
if (parsed.ambiguous || parsed.placeFrom !== 'near') return null;
return { layer: layer.layer, minMagnitude };
}
+37
View File
@@ -564,3 +564,40 @@ test('the rows the parser and the Enter rule agree on come from one place', () =
});
assert.equal(rows[0].source, 'photon');
});
test('coordinates named as the place are flown to, never refused or looked up', () => {
const omnibar = createOmnibar({ layers: layers() });
for (const text of [
'go to 30.27, -97.74',
'go to 48.85 2.35',
'go to 14R PU 2090 4906',
]) {
const { rows, defaultIndex } = omnibar.rows(text);
assert.equal(rows[defaultIndex]?.kind, 'place', text);
assert.match(rows[defaultIndex].label, /°[NS] .*°[EW]/, text);
assert.equal(omnibar.placeQuery(text), null, text);
}
const { rows, defaultIndex } = omnibar.rows(
'show flights near 30.27, -97.74',
);
assert.equal(rows[defaultIndex].kind, 'plan');
assert.equal(omnibar.placeQuery('show flights near 30.27, -97.74'), null);
// A card number is still no spot.
assert.equal(omnibar.rows('go to 4111 1111 1111 1111').defaultIndex, -1);
assert.equal(omnibar.placeQuery('go to ,'), null);
});
test('only a layer in or near a place is counted, never a name', () => {
const omnibar = createOmnibar({
layers: [...layers(), { id: 'ships', name: 'Ships', enabled: false }],
});
assert.ok(omnibar.countRequest('flights over Texas'));
assert.ok(omnibar.countRequest('quakes above M5 in Japan'));
for (const text of [
'Ship Bottom',
'Radio City Music Hall',
'radio settings',
'show me how to turn off flights',
])
assert.equal(omnibar.countRequest(text), null, text);
});