Skip to content

Commit

Permalink
fix(web): roaming disables longpress up-flick
Browse files Browse the repository at this point in the history
  • Loading branch information
jahorton committed Oct 9, 2023
1 parent 33a173d commit e7fa856
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 6 deletions.
60 changes: 55 additions & 5 deletions web/src/engine/osk/src/input/gestures/specsForLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ export function gestureSetForLayout(layerGroup: OSKLayerGroup, params: GesturePa
// gestureModels.push // flick-end

// defaultSet.push('flick-start');
} else {
// A post-roam version of longpress with the up-flick shortcut disabled but roaming still on.
gestureModels.push(withKeySpecFiltering(longpressModelWithRoaming(params), 0));
}

return {
Expand Down Expand Up @@ -244,7 +247,7 @@ export function BasicLongpressContactModel(params: GestureParams): ContactModel
};
}

export function LongpressContactModelWithShortcut(params: GestureParams): ContactModel {
export function LongpressContactModelWithShortcut(params: GestureParams, enabledFlicks?: false | undefined): ContactModel {
const spec = params.longpress;
const base = BasicLongpressContactModel(params);

Expand All @@ -263,7 +266,7 @@ export function LongpressContactModelWithShortcut(params: GestureParams): Contac
* The 'indexOf' allows 'n', 'nw', and 'ne' - approx 67.5 degrees on
* each side of due N in total.
*/
if(spec.permitFlick && (stats.cardinalDirection?.indexOf('n') != -1 ?? false)) {
if((enabledFlicks ?? spec.permitFlick) && (stats.cardinalDirection?.indexOf('n') != -1 ?? false)) {
if(stats.netDistance > spec.flickDist) {
return 'resolve';
}
Expand Down Expand Up @@ -433,7 +436,6 @@ export function longpressModelWithShortcut(params: GestureParams): GestureModel
contacts: [
{
model: {
// Is the version without the up-flick shortcut.
...LongpressContactModelWithShortcut(params),
itemPriority: 1,
pathInheritance: 'chop'
Expand All @@ -457,16 +459,64 @@ export function longpressModelWithShortcut(params: GestureParams): GestureModel
rejectionActions: {
item: {
type: 'replace',
replace: 'longpress'
replace: 'longpress-roam'
},
path: {
type: 'replace',
replace: 'longpress'
replace: 'longpress-roam'
}
}
}
}

/**
* For use when a layout doesn't have flicks; has the up-flick shortcut
* and facilitates roaming-touch.
*/
export function longpressModelWithRoaming(params: GestureParams): GestureModel {
return {
...basicLongpressModel(params),

id: 'longpress-roam',
resolutionPriority: 0,
contacts: [
{
model: {
// false - disabled shortcut regardless of params
...LongpressContactModelWithShortcut(params, false),
itemPriority: 1,
pathInheritance: 'chop'
},
endOnResolve: false
}, {
model: InstantContactRejectionModel
}
],
resolutionAction: {
type: 'chain',
next: 'subkey-select',
selectionMode: 'none',
item: 'none'
},

/*
* Note: these actions make sense in a 'roaming-touch' context, but not when
* flicks are also enabled.
*/
rejectionActions: {
item: {
type: 'replace',
replace: 'longpress-roam'
},
path: {
type: 'replace',
replace: 'longpress-roam'
}
}
}
}


export const MultitapModel: GestureModel = {
id: 'multitap',
resolutionPriority: 2,
Expand Down
3 changes: 2 additions & 1 deletion web/src/engine/osk/src/visualKeyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,8 @@ export default class VisualKeyboard extends EventEmitter<EventMap> implements Ke
// Merely constructing the instance is enough; it'll link into the sequence's events and
// handle everything that remains for the backspace from here.
new HeldRepeater(gestureSequence, () => this.modelKeyClick(gestureKey, coord));
} else if(gestureStage.matchedId == 'longpress') {
} else if(gestureStage.matchedId.indexOf('longpress') > -1) {
// Matches: 'longpress', 'longpress-reset'.
// Likewise.
new SubkeyPopup(gestureSequence, configChanger, this, gestureSequence.stageReports[0].sources[0].baseItem);
}
Expand Down

0 comments on commit e7fa856

Please sign in to comment.