From 2b8c2ddcfefebdce9fdcc3e65476f6abc8b7e832 Mon Sep 17 00:00:00 2001 From: Sam Wilkins Date: Wed, 31 Jul 2019 14:49:15 -0400 Subject: none-filter --- src/client/util/DictationManager.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/client/util/DictationManager.ts b/src/client/util/DictationManager.ts index 9c539e86a..e14000555 100644 --- a/src/client/util/DictationManager.ts +++ b/src/client/util/DictationManager.ts @@ -23,7 +23,7 @@ const { webkitSpeechRecognition }: CORE.IWindow = window as CORE.IWindow; export type IndependentAction = (target: DocumentView) => any | Promise; export type DependentAction = (target: DocumentView, matches: RegExpExecArray) => any | Promise; export type RegexEntry = { key: RegExp, value: DependentAction }; -export type RegistrationUnit = { filter: Predicate, action: T }; +export type RegistrationUnit = { action: T, filter?: Predicate }; export default class DictationManager { public static Instance = new DictationManager(); @@ -104,31 +104,32 @@ export default class DictationManager { if (!target) { return; } - let batch = UndoManager.StartBatch("Dictation Action"); phrase = this.sanitize(phrase); let unit = RegisteredCommands.Independent.get(phrase); - if (unit && unit.filter(target)) { - await unit.action(target); - batch.end(); - return true; + if (unit) { + if (!unit.filter || unit.filter(target)) { + let batch = UndoManager.StartBatch("Dictation Independent Action"); + await unit.action(target); + batch.end(); + return true; + } } - let success = false; for (let entry of RegisteredCommands.Dependent) { let regex = entry.key; let dependentAction = entry.value; let matches = regex.exec(phrase); regex.lastIndex = 0; if (matches !== null) { + let batch = UndoManager.StartBatch("Dictation Dependent Action"); await dependentAction(target, matches); - success = true; - break; + batch.end(); + return true; } } - batch.end(); - return success; + return false; } } @@ -203,5 +204,4 @@ export namespace Filters { export const isImageView: Predicate = (target: DocumentView) => tryCast(target, ImageField) !== undefined; - } \ No newline at end of file -- cgit v1.2.3-70-g09d2