Merge pull request #16516 from Snuffleupagus/lazy-KeyboardManager-init

[editor] Initialize `KeyboardManager`-instances lazily
This commit is contained in:
Jonas Jenwald 2023-06-02 16:17:31 +02:00 committed by GitHub
commit ba67bd717a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 30 deletions

View File

@ -21,6 +21,7 @@ import {
AnnotationEditorType, AnnotationEditorType,
assert, assert,
LINE_FACTOR, LINE_FACTOR,
shadow,
Util, Util,
} from "../../shared/util.js"; } from "../../shared/util.js";
import { bindEvents, KeyboardManager } from "./tools.js"; import { bindEvents, KeyboardManager } from "./tools.js";
@ -58,12 +59,18 @@ class FreeTextEditor extends AnnotationEditor {
static _defaultFontSize = 10; static _defaultFontSize = 10;
static _keyboardManager = new KeyboardManager([ static get _keyboardManager() {
[ return shadow(
["ctrl+Enter", "mac+meta+Enter", "Escape", "mac+Escape"], this,
FreeTextEditor.prototype.commitOrRemove, "_keyboardManager",
], new KeyboardManager([
]); [
["ctrl+Enter", "mac+meta+Enter", "Escape", "mac+Escape"],
FreeTextEditor.prototype.commitOrRemove,
],
])
);
}
static _type = "freetext"; static _type = "freetext";

View File

@ -396,30 +396,42 @@ class AnnotationEditorUIManager {
#container = null; #container = null;
static _keyboardManager = new KeyboardManager([ static get _keyboardManager() {
[["ctrl+a", "mac+meta+a"], AnnotationEditorUIManager.prototype.selectAll], return shadow(
[["ctrl+z", "mac+meta+z"], AnnotationEditorUIManager.prototype.undo], this,
[ "_keyboardManager",
["ctrl+y", "ctrl+shift+Z", "mac+meta+shift+Z"], new KeyboardManager([
AnnotationEditorUIManager.prototype.redo, [
], ["ctrl+a", "mac+meta+a"],
[ AnnotationEditorUIManager.prototype.selectAll,
[ ],
"Backspace", [["ctrl+z", "mac+meta+z"], AnnotationEditorUIManager.prototype.undo],
"alt+Backspace", [
"ctrl+Backspace", ["ctrl+y", "ctrl+shift+Z", "mac+meta+shift+Z"],
"shift+Backspace", AnnotationEditorUIManager.prototype.redo,
"mac+Backspace", ],
"mac+alt+Backspace", [
"mac+ctrl+Backspace", [
"Delete", "Backspace",
"ctrl+Delete", "alt+Backspace",
"shift+Delete", "ctrl+Backspace",
], "shift+Backspace",
AnnotationEditorUIManager.prototype.delete, "mac+Backspace",
], "mac+alt+Backspace",
[["Escape", "mac+Escape"], AnnotationEditorUIManager.prototype.unselectAll], "mac+ctrl+Backspace",
]); "Delete",
"ctrl+Delete",
"shift+Delete",
],
AnnotationEditorUIManager.prototype.delete,
],
[
["Escape", "mac+Escape"],
AnnotationEditorUIManager.prototype.unselectAll,
],
])
);
}
constructor(container, eventBus, annotationStorage) { constructor(container, eventBus, annotationStorage) {
this.#container = container; this.#container = container;