Skip to content

Commit

Permalink
Assume that features are accepted when using the key to move and rotate
Browse files Browse the repository at this point in the history
(closes #1336)

This adds some support for having the hotkeys work a bit more efficiently
for the Rapid features.

When a Rapid feature is selected _or hovered_ the following will apply:
- If it was selected and we hit 'A', accept and select the newly added feature
- If it was just hovering and we hit 'A', hover (but don't select) the newly added feature
- If we hit 'M' to move or 'R' to rotate, accept, then select and enter that mode
  • Loading branch information
bhousel committed Dec 18, 2024
1 parent 517e297 commit 9fc86ba
Showing 1 changed file with 52 additions and 5 deletions.
57 changes: 52 additions & 5 deletions modules/ui/UiRapidInspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { uiIcon } from './icon.js';
import { uiFlash } from './flash.js';
//import { uiRapidFirstEditDialog } from './rapid_first_edit_dialog.js';
import { uiTooltip } from './tooltip.js';
import { utilKeybinding } from '../util/keybinding.js';

const ACCEPT_FEATURES_LIMIT = 50;

Expand Down Expand Up @@ -34,6 +35,10 @@ export class UiRapidInspector {

this.datum = null;
this._keys = null;
// Need a "private" keybinding for this component because these keys conflict with
// the main keys used by the operations when editing OSM. ('A','D','M','R')
this._keybinding = utilKeybinding('UiRapidInspector');
select(document).call(this._keybinding);

// D3 selections
this.$parent = null;
Expand All @@ -55,6 +60,10 @@ export class UiRapidInspector {
this.ignoreFeature = this.ignoreFeature.bind(this);
this._setupKeybinding = this._setupKeybinding.bind(this);

// accept and enter one of these modes:
this.moveFeature = (e) => this.acceptFeature(e, 'move');
this.rotateFeature = (e) => this.acceptFeature(e, 'rotate');

// Setup event handlers
const l10n = context.systems.l10n;
l10n.on('localechange', this._setupKeybinding);
Expand Down Expand Up @@ -149,16 +158,18 @@ export class UiRapidInspector {
/**
* acceptFeature
* Called when the user presses Add Feature.
* @param {Event} e? - triggering event (if any)
* @param {Event} e? - triggering event (if any)
* @param {string} nextMode? - optional next mode to enter after accepting ('move' or 'rotate')
*/
acceptFeature(e) {
acceptFeature(e, nextMode) {
const datum = this.datum;
if (!datum) return;

const context = this.context;
const editor = context.systems.editor;
const l10n = context.systems.l10n;
const rapid = context.systems.rapid;
const scene = context.systems.gfx.scene;

if (this.isAcceptFeatureDisabled()) {
const flash = uiFlash(context)
Expand Down Expand Up @@ -189,7 +200,39 @@ export class UiRapidInspector {

editor.perform(actionRapidAcceptFeature(datum.id, graph));
editor.commit({ annotation: annotation, selectedIDs: [datum.id] });
context.enter('select-osm', { selection: { osm: [datum.id] }} );

// What next
// - If we were in select mode, stay in select mode
// - Or, if we are passed a `nextMode` do that.
// - Or, if the feature was hovered, keep it hovered
const currMode = context.mode?.id || '';
if (!nextMode && /^select/.test(currMode)) { // if it is selected, stay selected
nextMode = 'select-osm';
}

if (nextMode) { // should be one of 'select-osm', 'move', or 'rotate'
context.enter(nextMode, { selection: { osm: [datum.id] }} );

} else { // if it was hovered, hover the newly added item (this is hacky):
// 1. get the `lastMove` event, and make it appear to target the new entity on the 'osm' layer
// 2. tell the hover behavior to emit a new 'hoverchange' event.
const hover = context.behaviors.hover;
const lastMove = hover.lastMove;
const graph = editor.staging.graph;
const entity = graph.entity(datum.id); // get the newly accepted entity
const layer = scene.layers.get('osm');
lastMove.target = {
displayObject: null,
feature: null,
featureID: null,
layer: layer,
layerID: layer.id,
data: entity,
dataID: entity.id
};
hover._doHover();
}

this.datum = null;

if (context.inIntro) return;
Expand Down Expand Up @@ -546,7 +589,7 @@ export class UiRapidInspector {
*/
_setupKeybinding() {
const context = this.context;
const keybinding = context.keybinding();
const keybinding = this._keybinding;
const l10n = context.systems.l10n;

if (Array.isArray(this._keys)) {
Expand All @@ -555,10 +598,14 @@ export class UiRapidInspector {

const acceptKey = l10n.t('shortcuts.command.accept_feature.key');
const ignoreKey = l10n.t('shortcuts.command.ignore_feature.key');
this._keys = [acceptKey, ignoreKey];
const moveKey = l10n.t('shortcuts.command.move.key');
const rotateKey = l10n.t('shortcuts.command.rotate.key');
this._keys = [acceptKey, ignoreKey, moveKey, rotateKey];

keybinding.on(acceptKey, this.acceptFeature);
keybinding.on(ignoreKey, this.ignoreFeature);
keybinding.on(moveKey, this.moveFeature);
keybinding.on(rotateKey, this.rotateFeature);
}

}

0 comments on commit 9fc86ba

Please sign in to comment.