mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-09 10:25:32 +00:00
fix(web): prevent invalid longpress shortcut triggers
This commit is contained in:
parent
e8949831da
commit
d2a043ae43
3 changed files with 24 additions and 18 deletions
|
|
@ -93,11 +93,7 @@ export class PathMatcher<Type, StateToken = any> {
|
|||
}
|
||||
|
||||
// Check for validation as needed.
|
||||
if(!model.timer.validateItem) {
|
||||
this.finalize(true, 'timer');
|
||||
} else {
|
||||
this.finalize(model.timer.validateItem(this.source.path.stats.lastSample.item, this.baseItem), 'timer');
|
||||
}
|
||||
this.finalize(true, 'timer');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -108,6 +104,14 @@ export class PathMatcher<Type, StateToken = any> {
|
|||
}
|
||||
|
||||
const model = this.model;
|
||||
|
||||
// Check for validation as needed.
|
||||
if(model.validateItem && result) {
|
||||
// If we're finalizing on a positive note but there's an item-validation check, we need
|
||||
// to obey the results of that check.
|
||||
result = model.validateItem(this.source.path.stats.lastSample.item, this.baseItem);
|
||||
}
|
||||
|
||||
let retVal: PathMatchResult;
|
||||
if(result) {
|
||||
retVal = {
|
||||
|
|
|
|||
|
|
@ -23,6 +23,18 @@ export interface ContactModel<Type, StateToken = any> {
|
|||
// gesture-state updates and resolution. Higher = better.
|
||||
itemPriority: number;
|
||||
|
||||
/**
|
||||
* An optional function parameter. If specified and other conditions are met,
|
||||
* this function will validate the model on the basis of the associated 'items' when
|
||||
* a model match is being finalized.
|
||||
* @param currentItem
|
||||
* @param baseItem
|
||||
* @returns
|
||||
* - `true` if the model is valid for the associated items, resulting in a model match
|
||||
* - `false` if the model is invalid, leading to model rejection
|
||||
*/
|
||||
validateItem?: (currentItem: Type, baseItem: Type) => boolean
|
||||
|
||||
/**
|
||||
* Used for resolving or rejecting this component of a gesture based on a time threshold
|
||||
* for the touch contact point's lifetime.
|
||||
|
|
@ -41,17 +53,7 @@ export interface ContactModel<Type, StateToken = any> {
|
|||
* If `true`, the timer will use the inherited `path.stats.duration` stat as an
|
||||
* offset that has already elapsed, counting it against the timer.
|
||||
*/
|
||||
inheritElapsed?: boolean,
|
||||
/**
|
||||
* An optional timer-spec function parameter. If specified and other conditions are met,
|
||||
* this function will validate the model on the basis of the associated 'items'.
|
||||
* @param currentItem
|
||||
* @param baseItem
|
||||
* @returns
|
||||
* - `true` if the model is valid for the associated items, resulting in a model match
|
||||
* - `false` if the model is invalid, leading to model rejection
|
||||
*/
|
||||
validateItem?: (currentItem: Type, baseItem: Type) => boolean
|
||||
inheritElapsed?: boolean
|
||||
}
|
||||
|
||||
// This field is primarly used at the `GestureMatcher` level, rather than the
|
||||
|
|
|
|||
|
|
@ -441,9 +441,9 @@ export function longpressContactModel(params: GestureParams, enabledFlicks: bool
|
|||
pathResolutionAction: 'resolve',
|
||||
timer: {
|
||||
duration: spec.waitLength,
|
||||
expectedResult: true,
|
||||
validateItem: (key: KeyElement) => !!key?.key.spec.sk
|
||||
expectedResult: true
|
||||
},
|
||||
validateItem: (key: KeyElement) => !!key?.key.spec.sk,
|
||||
pathModel: {
|
||||
evaluate: (path) => {
|
||||
const stats = path.stats;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue