[editor] Initialize KeyboardManager
-instances lazily
As far as I can tell there's no particular reason for initializing `KeyboardManager`-instances eagerly, since the user may never use editing, and we can easily do this lazily instead by utilizing shadowed getters.
This commit is contained in:
parent
0023c4a511
commit
ea93c507f5
@ -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(
|
||||||
|
this,
|
||||||
|
"_keyboardManager",
|
||||||
|
new KeyboardManager([
|
||||||
[
|
[
|
||||||
["ctrl+Enter", "mac+meta+Enter", "Escape", "mac+Escape"],
|
["ctrl+Enter", "mac+meta+Enter", "Escape", "mac+Escape"],
|
||||||
FreeTextEditor.prototype.commitOrRemove,
|
FreeTextEditor.prototype.commitOrRemove,
|
||||||
],
|
],
|
||||||
]);
|
])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
static _type = "freetext";
|
static _type = "freetext";
|
||||||
|
|
||||||
|
@ -396,8 +396,15 @@ class AnnotationEditorUIManager {
|
|||||||
|
|
||||||
#container = null;
|
#container = null;
|
||||||
|
|
||||||
static _keyboardManager = new KeyboardManager([
|
static get _keyboardManager() {
|
||||||
[["ctrl+a", "mac+meta+a"], AnnotationEditorUIManager.prototype.selectAll],
|
return shadow(
|
||||||
|
this,
|
||||||
|
"_keyboardManager",
|
||||||
|
new KeyboardManager([
|
||||||
|
[
|
||||||
|
["ctrl+a", "mac+meta+a"],
|
||||||
|
AnnotationEditorUIManager.prototype.selectAll,
|
||||||
|
],
|
||||||
[["ctrl+z", "mac+meta+z"], AnnotationEditorUIManager.prototype.undo],
|
[["ctrl+z", "mac+meta+z"], AnnotationEditorUIManager.prototype.undo],
|
||||||
[
|
[
|
||||||
["ctrl+y", "ctrl+shift+Z", "mac+meta+shift+Z"],
|
["ctrl+y", "ctrl+shift+Z", "mac+meta+shift+Z"],
|
||||||
@ -418,8 +425,13 @@ class AnnotationEditorUIManager {
|
|||||||
],
|
],
|
||||||
AnnotationEditorUIManager.prototype.delete,
|
AnnotationEditorUIManager.prototype.delete,
|
||||||
],
|
],
|
||||||
[["Escape", "mac+Escape"], AnnotationEditorUIManager.prototype.unselectAll],
|
[
|
||||||
]);
|
["Escape", "mac+Escape"],
|
||||||
|
AnnotationEditorUIManager.prototype.unselectAll,
|
||||||
|
],
|
||||||
|
])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
constructor(container, eventBus, annotationStorage) {
|
constructor(container, eventBus, annotationStorage) {
|
||||||
this.#container = container;
|
this.#container = container;
|
||||||
|
Loading…
Reference in New Issue
Block a user