[Editor] Reduce a bit of duplication on _keyboardManager
initialization
The way that the callback-methods are specified feels unnecessarily verbose, however we can introduce a short-hand to improve this. Also, adds a couple of new-lines to improve overall readability.
This commit is contained in:
parent
82faae26c0
commit
34f2e7d4f9
@ -65,9 +65,13 @@ class FreeTextEditor extends AnnotationEditor {
|
|||||||
static _defaultFontSize = 10;
|
static _defaultFontSize = 10;
|
||||||
|
|
||||||
static get _keyboardManager() {
|
static get _keyboardManager() {
|
||||||
|
const proto = FreeTextEditor.prototype;
|
||||||
|
|
||||||
const arrowChecker = self => self.isEmpty();
|
const arrowChecker = self => self.isEmpty();
|
||||||
|
|
||||||
const small = AnnotationEditorUIManager.TRANSLATE_SMALL;
|
const small = AnnotationEditorUIManager.TRANSLATE_SMALL;
|
||||||
const big = AnnotationEditorUIManager.TRANSLATE_BIG;
|
const big = AnnotationEditorUIManager.TRANSLATE_BIG;
|
||||||
|
|
||||||
return shadow(
|
return shadow(
|
||||||
this,
|
this,
|
||||||
"_keyboardManager",
|
"_keyboardManager",
|
||||||
@ -77,51 +81,51 @@ class FreeTextEditor extends AnnotationEditor {
|
|||||||
// The event must bubble in order to be caught by the viewer.
|
// The event must bubble in order to be caught by the viewer.
|
||||||
// See bug 1831574.
|
// See bug 1831574.
|
||||||
["ctrl+s", "mac+meta+s", "ctrl+p", "mac+meta+p"],
|
["ctrl+s", "mac+meta+s", "ctrl+p", "mac+meta+p"],
|
||||||
FreeTextEditor.prototype.commitOrRemove,
|
proto.commitOrRemove,
|
||||||
{ bubbles: true },
|
{ bubbles: true },
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
["ctrl+Enter", "mac+meta+Enter", "Escape", "mac+Escape"],
|
["ctrl+Enter", "mac+meta+Enter", "Escape", "mac+Escape"],
|
||||||
FreeTextEditor.prototype.commitOrRemove,
|
proto.commitOrRemove,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
["ArrowLeft", "mac+ArrowLeft"],
|
["ArrowLeft", "mac+ArrowLeft"],
|
||||||
FreeTextEditor.prototype._translateEmpty,
|
proto._translateEmpty,
|
||||||
{ args: [-small, 0], checker: arrowChecker },
|
{ args: [-small, 0], checker: arrowChecker },
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
["ctrl+ArrowLeft", "mac+shift+ArrowLeft"],
|
["ctrl+ArrowLeft", "mac+shift+ArrowLeft"],
|
||||||
FreeTextEditor.prototype._translateEmpty,
|
proto._translateEmpty,
|
||||||
{ args: [-big, 0], checker: arrowChecker },
|
{ args: [-big, 0], checker: arrowChecker },
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
["ArrowRight", "mac+ArrowRight"],
|
["ArrowRight", "mac+ArrowRight"],
|
||||||
FreeTextEditor.prototype._translateEmpty,
|
proto._translateEmpty,
|
||||||
{ args: [small, 0], checker: arrowChecker },
|
{ args: [small, 0], checker: arrowChecker },
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
["ctrl+ArrowRight", "mac+shift+ArrowRight"],
|
["ctrl+ArrowRight", "mac+shift+ArrowRight"],
|
||||||
FreeTextEditor.prototype._translateEmpty,
|
proto._translateEmpty,
|
||||||
{ args: [big, 0], checker: arrowChecker },
|
{ args: [big, 0], checker: arrowChecker },
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
["ArrowUp", "mac+ArrowUp"],
|
["ArrowUp", "mac+ArrowUp"],
|
||||||
FreeTextEditor.prototype._translateEmpty,
|
proto._translateEmpty,
|
||||||
{ args: [0, -small], checker: arrowChecker },
|
{ args: [0, -small], checker: arrowChecker },
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
["ctrl+ArrowUp", "mac+shift+ArrowUp"],
|
["ctrl+ArrowUp", "mac+shift+ArrowUp"],
|
||||||
FreeTextEditor.prototype._translateEmpty,
|
proto._translateEmpty,
|
||||||
{ args: [0, -big], checker: arrowChecker },
|
{ args: [0, -big], checker: arrowChecker },
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
["ArrowDown", "mac+ArrowDown"],
|
["ArrowDown", "mac+ArrowDown"],
|
||||||
FreeTextEditor.prototype._translateEmpty,
|
proto._translateEmpty,
|
||||||
{ args: [0, small], checker: arrowChecker },
|
{ args: [0, small], checker: arrowChecker },
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
["ctrl+ArrowDown", "mac+shift+ArrowDown"],
|
["ctrl+ArrowDown", "mac+shift+ArrowDown"],
|
||||||
FreeTextEditor.prototype._translateEmpty,
|
proto._translateEmpty,
|
||||||
{ args: [0, big], checker: arrowChecker },
|
{ args: [0, big], checker: arrowChecker },
|
||||||
],
|
],
|
||||||
])
|
])
|
||||||
|
@ -566,6 +566,8 @@ class AnnotationEditorUIManager {
|
|||||||
static TRANSLATE_BIG = 10; // page units.
|
static TRANSLATE_BIG = 10; // page units.
|
||||||
|
|
||||||
static get _keyboardManager() {
|
static get _keyboardManager() {
|
||||||
|
const proto = AnnotationEditorUIManager.prototype;
|
||||||
|
|
||||||
const arrowChecker = self => {
|
const arrowChecker = self => {
|
||||||
// If the focused element is an input, we don't want to handle the arrow.
|
// If the focused element is an input, we don't want to handle the arrow.
|
||||||
// For example, sliders can be controlled with the arrow keys.
|
// For example, sliders can be controlled with the arrow keys.
|
||||||
@ -576,17 +578,16 @@ class AnnotationEditorUIManager {
|
|||||||
self.hasSomethingToControl()
|
self.hasSomethingToControl()
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const small = this.TRANSLATE_SMALL;
|
const small = this.TRANSLATE_SMALL;
|
||||||
const big = this.TRANSLATE_BIG;
|
const big = this.TRANSLATE_BIG;
|
||||||
|
|
||||||
return shadow(
|
return shadow(
|
||||||
this,
|
this,
|
||||||
"_keyboardManager",
|
"_keyboardManager",
|
||||||
new KeyboardManager([
|
new KeyboardManager([
|
||||||
[
|
[["ctrl+a", "mac+meta+a"], proto.selectAll],
|
||||||
["ctrl+a", "mac+meta+a"],
|
[["ctrl+z", "mac+meta+z"], proto.undo],
|
||||||
AnnotationEditorUIManager.prototype.selectAll,
|
|
||||||
],
|
|
||||||
[["ctrl+z", "mac+meta+z"], AnnotationEditorUIManager.prototype.undo],
|
|
||||||
[
|
[
|
||||||
// On mac, depending of the OS version, the event.key is either "z" or
|
// On mac, depending of the OS version, the event.key is either "z" or
|
||||||
// "Z" when the user presses "meta+shift+z".
|
// "Z" when the user presses "meta+shift+z".
|
||||||
@ -597,7 +598,7 @@ class AnnotationEditorUIManager {
|
|||||||
"ctrl+shift+Z",
|
"ctrl+shift+Z",
|
||||||
"mac+meta+shift+Z",
|
"mac+meta+shift+Z",
|
||||||
],
|
],
|
||||||
AnnotationEditorUIManager.prototype.redo,
|
proto.redo,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
@ -613,50 +614,47 @@ class AnnotationEditorUIManager {
|
|||||||
"shift+Delete",
|
"shift+Delete",
|
||||||
"mac+Delete",
|
"mac+Delete",
|
||||||
],
|
],
|
||||||
AnnotationEditorUIManager.prototype.delete,
|
proto.delete,
|
||||||
],
|
|
||||||
[
|
|
||||||
["Escape", "mac+Escape"],
|
|
||||||
AnnotationEditorUIManager.prototype.unselectAll,
|
|
||||||
],
|
],
|
||||||
|
[["Escape", "mac+Escape"], proto.unselectAll],
|
||||||
[
|
[
|
||||||
["ArrowLeft", "mac+ArrowLeft"],
|
["ArrowLeft", "mac+ArrowLeft"],
|
||||||
AnnotationEditorUIManager.prototype.translateSelectedEditors,
|
proto.translateSelectedEditors,
|
||||||
{ args: [-small, 0], checker: arrowChecker },
|
{ args: [-small, 0], checker: arrowChecker },
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
["ctrl+ArrowLeft", "mac+shift+ArrowLeft"],
|
["ctrl+ArrowLeft", "mac+shift+ArrowLeft"],
|
||||||
AnnotationEditorUIManager.prototype.translateSelectedEditors,
|
proto.translateSelectedEditors,
|
||||||
{ args: [-big, 0], checker: arrowChecker },
|
{ args: [-big, 0], checker: arrowChecker },
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
["ArrowRight", "mac+ArrowRight"],
|
["ArrowRight", "mac+ArrowRight"],
|
||||||
AnnotationEditorUIManager.prototype.translateSelectedEditors,
|
proto.translateSelectedEditors,
|
||||||
{ args: [small, 0], checker: arrowChecker },
|
{ args: [small, 0], checker: arrowChecker },
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
["ctrl+ArrowRight", "mac+shift+ArrowRight"],
|
["ctrl+ArrowRight", "mac+shift+ArrowRight"],
|
||||||
AnnotationEditorUIManager.prototype.translateSelectedEditors,
|
proto.translateSelectedEditors,
|
||||||
{ args: [big, 0], checker: arrowChecker },
|
{ args: [big, 0], checker: arrowChecker },
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
["ArrowUp", "mac+ArrowUp"],
|
["ArrowUp", "mac+ArrowUp"],
|
||||||
AnnotationEditorUIManager.prototype.translateSelectedEditors,
|
proto.translateSelectedEditors,
|
||||||
{ args: [0, -small], checker: arrowChecker },
|
{ args: [0, -small], checker: arrowChecker },
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
["ctrl+ArrowUp", "mac+shift+ArrowUp"],
|
["ctrl+ArrowUp", "mac+shift+ArrowUp"],
|
||||||
AnnotationEditorUIManager.prototype.translateSelectedEditors,
|
proto.translateSelectedEditors,
|
||||||
{ args: [0, -big], checker: arrowChecker },
|
{ args: [0, -big], checker: arrowChecker },
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
["ArrowDown", "mac+ArrowDown"],
|
["ArrowDown", "mac+ArrowDown"],
|
||||||
AnnotationEditorUIManager.prototype.translateSelectedEditors,
|
proto.translateSelectedEditors,
|
||||||
{ args: [0, small], checker: arrowChecker },
|
{ args: [0, small], checker: arrowChecker },
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
["ctrl+ArrowDown", "mac+shift+ArrowDown"],
|
["ctrl+ArrowDown", "mac+shift+ArrowDown"],
|
||||||
AnnotationEditorUIManager.prototype.translateSelectedEditors,
|
proto.translateSelectedEditors,
|
||||||
{ args: [0, big], checker: arrowChecker },
|
{ args: [0, big], checker: arrowChecker },
|
||||||
],
|
],
|
||||||
])
|
])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user