mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-23 00:28:06 +02:00
Merge pull request #16750 from calixteman/editor_keeboard_freetext
[Editor] Add the possibility to move an empty freetext editor with the keyboard (bug 1845088)
This commit is contained in:
commit
82faae26c0
3 changed files with 175 additions and 36 deletions
|
@ -24,7 +24,11 @@ import {
|
|||
shadow,
|
||||
Util,
|
||||
} from "../../shared/util.js";
|
||||
import { bindEvents, KeyboardManager } from "./tools.js";
|
||||
import {
|
||||
AnnotationEditorUIManager,
|
||||
bindEvents,
|
||||
KeyboardManager,
|
||||
} from "./tools.js";
|
||||
import { AnnotationEditor } from "./editor.js";
|
||||
import { FreeTextAnnotationElement } from "../annotation_layer.js";
|
||||
|
||||
|
@ -61,6 +65,9 @@ class FreeTextEditor extends AnnotationEditor {
|
|||
static _defaultFontSize = 10;
|
||||
|
||||
static get _keyboardManager() {
|
||||
const arrowChecker = self => self.isEmpty();
|
||||
const small = AnnotationEditorUIManager.TRANSLATE_SMALL;
|
||||
const big = AnnotationEditorUIManager.TRANSLATE_BIG;
|
||||
return shadow(
|
||||
this,
|
||||
"_keyboardManager",
|
||||
|
@ -77,6 +84,46 @@ class FreeTextEditor extends AnnotationEditor {
|
|||
["ctrl+Enter", "mac+meta+Enter", "Escape", "mac+Escape"],
|
||||
FreeTextEditor.prototype.commitOrRemove,
|
||||
],
|
||||
[
|
||||
["ArrowLeft", "mac+ArrowLeft"],
|
||||
FreeTextEditor.prototype._translateEmpty,
|
||||
{ args: [-small, 0], checker: arrowChecker },
|
||||
],
|
||||
[
|
||||
["ctrl+ArrowLeft", "mac+shift+ArrowLeft"],
|
||||
FreeTextEditor.prototype._translateEmpty,
|
||||
{ args: [-big, 0], checker: arrowChecker },
|
||||
],
|
||||
[
|
||||
["ArrowRight", "mac+ArrowRight"],
|
||||
FreeTextEditor.prototype._translateEmpty,
|
||||
{ args: [small, 0], checker: arrowChecker },
|
||||
],
|
||||
[
|
||||
["ctrl+ArrowRight", "mac+shift+ArrowRight"],
|
||||
FreeTextEditor.prototype._translateEmpty,
|
||||
{ args: [big, 0], checker: arrowChecker },
|
||||
],
|
||||
[
|
||||
["ArrowUp", "mac+ArrowUp"],
|
||||
FreeTextEditor.prototype._translateEmpty,
|
||||
{ args: [0, -small], checker: arrowChecker },
|
||||
],
|
||||
[
|
||||
["ctrl+ArrowUp", "mac+shift+ArrowUp"],
|
||||
FreeTextEditor.prototype._translateEmpty,
|
||||
{ args: [0, -big], checker: arrowChecker },
|
||||
],
|
||||
[
|
||||
["ArrowDown", "mac+ArrowDown"],
|
||||
FreeTextEditor.prototype._translateEmpty,
|
||||
{ args: [0, small], checker: arrowChecker },
|
||||
],
|
||||
[
|
||||
["ctrl+ArrowDown", "mac+shift+ArrowDown"],
|
||||
FreeTextEditor.prototype._translateEmpty,
|
||||
{ args: [0, big], checker: arrowChecker },
|
||||
],
|
||||
])
|
||||
);
|
||||
}
|
||||
|
@ -209,6 +256,15 @@ class FreeTextEditor extends AnnotationEditor {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to translate the editor with the keyboard when it's empty.
|
||||
* @param {number} x in page units.
|
||||
* @param {number} y in page units.
|
||||
*/
|
||||
_translateEmpty(x, y) {
|
||||
this._uiManager.translateSelectedEditors(x, y, /* noCommit = */ true);
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
getInitialTranslation() {
|
||||
// The start of the base line is where the user clicked.
|
||||
|
|
|
@ -561,9 +561,9 @@ class AnnotationEditorUIManager {
|
|||
|
||||
#container = null;
|
||||
|
||||
static #TRANSLATE_SMALL = 1; // page units.
|
||||
static TRANSLATE_SMALL = 1; // page units.
|
||||
|
||||
static #TRANSLATE_BIG = 10; // page units.
|
||||
static TRANSLATE_BIG = 10; // page units.
|
||||
|
||||
static get _keyboardManager() {
|
||||
const arrowChecker = self => {
|
||||
|
@ -576,8 +576,8 @@ class AnnotationEditorUIManager {
|
|||
self.hasSomethingToControl()
|
||||
);
|
||||
};
|
||||
const small = this.#TRANSLATE_SMALL;
|
||||
const big = this.#TRANSLATE_BIG;
|
||||
const small = this.TRANSLATE_SMALL;
|
||||
const big = this.TRANSLATE_BIG;
|
||||
return shadow(
|
||||
this,
|
||||
"_keyboardManager",
|
||||
|
@ -1379,8 +1379,10 @@ class AnnotationEditorUIManager {
|
|||
});
|
||||
}
|
||||
|
||||
translateSelectedEditors(x, y) {
|
||||
this.commitOrRemove();
|
||||
translateSelectedEditors(x, y, noCommit = false) {
|
||||
if (!noCommit) {
|
||||
this.commitOrRemove();
|
||||
}
|
||||
if (!this.hasSelection) {
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue