aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSam Wilkins <samwilkins333@gmail.com>2019-07-31 14:49:15 -0400
committerSam Wilkins <samwilkins333@gmail.com>2019-07-31 14:49:15 -0400
commit2b8c2ddcfefebdce9fdcc3e65476f6abc8b7e832 (patch)
tree53dd14b2b3611c276ced2facbaead0a55e4acc73 /src
parentdf444357c153abf8daf87d9f80f4fe2bcfba00b9 (diff)
none-filter
Diffstat (limited to 'src')
-rw-r--r--src/client/util/DictationManager.ts24
1 files changed, 12 insertions, 12 deletions
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<any>;
export type DependentAction = (target: DocumentView, matches: RegExpExecArray) => any | Promise<any>;
export type RegexEntry = { key: RegExp, value: DependentAction };
-export type RegistrationUnit<T extends IndependentAction | DependentAction> = { filter: Predicate, action: T };
+export type RegistrationUnit<T extends IndependentAction | DependentAction> = { 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