[Editor] Commit the text when the user hits ctrl+s (bug 1831574)
This commit is contained in:
parent
9cd84aa0b2
commit
3d98fb3c0b
@ -65,6 +65,14 @@ class FreeTextEditor extends AnnotationEditor {
|
|||||||
this,
|
this,
|
||||||
"_keyboardManager",
|
"_keyboardManager",
|
||||||
new KeyboardManager([
|
new KeyboardManager([
|
||||||
|
[
|
||||||
|
// Commit the text in case the user use ctrl+s to save the document.
|
||||||
|
// The event must bubble in order to be caught by the viewer.
|
||||||
|
// See bug 1831574.
|
||||||
|
["ctrl+s", "mac+meta+s", "ctrl+p", "mac+meta+p"],
|
||||||
|
FreeTextEditor.prototype.commitOrRemove,
|
||||||
|
/* bubbles = */ true,
|
||||||
|
],
|
||||||
[
|
[
|
||||||
["ctrl+Enter", "mac+meta+Enter", "Escape", "mac+Escape"],
|
["ctrl+Enter", "mac+meta+Enter", "Escape", "mac+Escape"],
|
||||||
FreeTextEditor.prototype.commitOrRemove,
|
FreeTextEditor.prototype.commitOrRemove,
|
||||||
|
@ -213,14 +213,14 @@ class KeyboardManager {
|
|||||||
this.allKeys = new Set();
|
this.allKeys = new Set();
|
||||||
|
|
||||||
const { isMac } = FeatureTest.platform;
|
const { isMac } = FeatureTest.platform;
|
||||||
for (const [keys, callback] of callbacks) {
|
for (const [keys, callback, bubbles = false] of callbacks) {
|
||||||
for (const key of keys) {
|
for (const key of keys) {
|
||||||
const isMacKey = key.startsWith("mac+");
|
const isMacKey = key.startsWith("mac+");
|
||||||
if (isMac && isMacKey) {
|
if (isMac && isMacKey) {
|
||||||
this.callbacks.set(key.slice(4), callback);
|
this.callbacks.set(key.slice(4), { callback, bubbles });
|
||||||
this.allKeys.add(key.split("+").at(-1));
|
this.allKeys.add(key.split("+").at(-1));
|
||||||
} else if (!isMac && !isMacKey) {
|
} else if (!isMac && !isMacKey) {
|
||||||
this.callbacks.set(key, callback);
|
this.callbacks.set(key, { callback, bubbles });
|
||||||
this.allKeys.add(key.split("+").at(-1));
|
this.allKeys.add(key.split("+").at(-1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -264,13 +264,19 @@ class KeyboardManager {
|
|||||||
if (!this.allKeys.has(event.key)) {
|
if (!this.allKeys.has(event.key)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const callback = this.callbacks.get(this.#serialize(event));
|
const info = this.callbacks.get(this.#serialize(event));
|
||||||
if (!callback) {
|
if (!info) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const { callback, bubbles } = info;
|
||||||
callback.bind(self)();
|
callback.bind(self)();
|
||||||
event.stopPropagation();
|
|
||||||
event.preventDefault();
|
// For example, ctrl+s in a FreeText must be handled by the viewer, hence
|
||||||
|
// the event must bubble.
|
||||||
|
if (!bubbles) {
|
||||||
|
event.stopPropagation();
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user