[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,
 | 
			
		||||
  assert,
 | 
			
		||||
  LINE_FACTOR,
 | 
			
		||||
  shadow,
 | 
			
		||||
  Util,
 | 
			
		||||
} from "../../shared/util.js";
 | 
			
		||||
import { bindEvents, KeyboardManager } from "./tools.js";
 | 
			
		||||
@ -58,12 +59,18 @@ class FreeTextEditor extends AnnotationEditor {
 | 
			
		||||
 | 
			
		||||
  static _defaultFontSize = 10;
 | 
			
		||||
 | 
			
		||||
  static _keyboardManager = new KeyboardManager([
 | 
			
		||||
    [
 | 
			
		||||
      ["ctrl+Enter", "mac+meta+Enter", "Escape", "mac+Escape"],
 | 
			
		||||
      FreeTextEditor.prototype.commitOrRemove,
 | 
			
		||||
    ],
 | 
			
		||||
  ]);
 | 
			
		||||
  static get _keyboardManager() {
 | 
			
		||||
    return shadow(
 | 
			
		||||
      this,
 | 
			
		||||
      "_keyboardManager",
 | 
			
		||||
      new KeyboardManager([
 | 
			
		||||
        [
 | 
			
		||||
          ["ctrl+Enter", "mac+meta+Enter", "Escape", "mac+Escape"],
 | 
			
		||||
          FreeTextEditor.prototype.commitOrRemove,
 | 
			
		||||
        ],
 | 
			
		||||
      ])
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  static _type = "freetext";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -396,30 +396,42 @@ class AnnotationEditorUIManager {
 | 
			
		||||
 | 
			
		||||
  #container = null;
 | 
			
		||||
 | 
			
		||||
  static _keyboardManager = new KeyboardManager([
 | 
			
		||||
    [["ctrl+a", "mac+meta+a"], AnnotationEditorUIManager.prototype.selectAll],
 | 
			
		||||
    [["ctrl+z", "mac+meta+z"], AnnotationEditorUIManager.prototype.undo],
 | 
			
		||||
    [
 | 
			
		||||
      ["ctrl+y", "ctrl+shift+Z", "mac+meta+shift+Z"],
 | 
			
		||||
      AnnotationEditorUIManager.prototype.redo,
 | 
			
		||||
    ],
 | 
			
		||||
    [
 | 
			
		||||
      [
 | 
			
		||||
        "Backspace",
 | 
			
		||||
        "alt+Backspace",
 | 
			
		||||
        "ctrl+Backspace",
 | 
			
		||||
        "shift+Backspace",
 | 
			
		||||
        "mac+Backspace",
 | 
			
		||||
        "mac+alt+Backspace",
 | 
			
		||||
        "mac+ctrl+Backspace",
 | 
			
		||||
        "Delete",
 | 
			
		||||
        "ctrl+Delete",
 | 
			
		||||
        "shift+Delete",
 | 
			
		||||
      ],
 | 
			
		||||
      AnnotationEditorUIManager.prototype.delete,
 | 
			
		||||
    ],
 | 
			
		||||
    [["Escape", "mac+Escape"], AnnotationEditorUIManager.prototype.unselectAll],
 | 
			
		||||
  ]);
 | 
			
		||||
  static get _keyboardManager() {
 | 
			
		||||
    return shadow(
 | 
			
		||||
      this,
 | 
			
		||||
      "_keyboardManager",
 | 
			
		||||
      new KeyboardManager([
 | 
			
		||||
        [
 | 
			
		||||
          ["ctrl+a", "mac+meta+a"],
 | 
			
		||||
          AnnotationEditorUIManager.prototype.selectAll,
 | 
			
		||||
        ],
 | 
			
		||||
        [["ctrl+z", "mac+meta+z"], AnnotationEditorUIManager.prototype.undo],
 | 
			
		||||
        [
 | 
			
		||||
          ["ctrl+y", "ctrl+shift+Z", "mac+meta+shift+Z"],
 | 
			
		||||
          AnnotationEditorUIManager.prototype.redo,
 | 
			
		||||
        ],
 | 
			
		||||
        [
 | 
			
		||||
          [
 | 
			
		||||
            "Backspace",
 | 
			
		||||
            "alt+Backspace",
 | 
			
		||||
            "ctrl+Backspace",
 | 
			
		||||
            "shift+Backspace",
 | 
			
		||||
            "mac+Backspace",
 | 
			
		||||
            "mac+alt+Backspace",
 | 
			
		||||
            "mac+ctrl+Backspace",
 | 
			
		||||
            "Delete",
 | 
			
		||||
            "ctrl+Delete",
 | 
			
		||||
            "shift+Delete",
 | 
			
		||||
          ],
 | 
			
		||||
          AnnotationEditorUIManager.prototype.delete,
 | 
			
		||||
        ],
 | 
			
		||||
        [
 | 
			
		||||
          ["Escape", "mac+Escape"],
 | 
			
		||||
          AnnotationEditorUIManager.prototype.unselectAll,
 | 
			
		||||
        ],
 | 
			
		||||
      ])
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  constructor(container, eventBus, annotationStorage) {
 | 
			
		||||
    this.#container = container;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user