Skip to content
Snippets Groups Projects
Commit 7411fc97 authored by Antoine Guenet's avatar Antoine Guenet
Browse files

[FIX] web_editor: use styling commands on shortcut too

When pressing the italic or underline buttons, we pass through a command
in the editor. Their corresponding keyboard shortcuts however were not
intercepted by the editor and were therefore triggering the default
browser behavior. As a result we had different behaviors when using the
buttons and the shortcuts.

X-original-commit: 2e3c3b3a15fa6ff4fa209fc7dbac10864f8898a2
Part-of: odoo/odoo#86930
parent 9caf5ed0
No related branches found
No related tags found
No related merge requests found
...@@ -70,6 +70,8 @@ const KEYBOARD_TYPES = { VIRTUAL: 'VIRTUAL', PHYSICAL: 'PHYSICAL', UNKNOWN: 'UKN ...@@ -70,6 +70,8 @@ const KEYBOARD_TYPES = { VIRTUAL: 'VIRTUAL', PHYSICAL: 'PHYSICAL', UNKNOWN: 'UKN
const IS_KEYBOARD_EVENT_UNDO = ev => ev.key === 'z' && (ev.ctrlKey || ev.metaKey); const IS_KEYBOARD_EVENT_UNDO = ev => ev.key === 'z' && (ev.ctrlKey || ev.metaKey);
const IS_KEYBOARD_EVENT_REDO = ev => ev.key === 'y' && (ev.ctrlKey || ev.metaKey); const IS_KEYBOARD_EVENT_REDO = ev => ev.key === 'y' && (ev.ctrlKey || ev.metaKey);
const IS_KEYBOARD_EVENT_BOLD = ev => ev.key === 'b' && (ev.ctrlKey || ev.metaKey); const IS_KEYBOARD_EVENT_BOLD = ev => ev.key === 'b' && (ev.ctrlKey || ev.metaKey);
const IS_KEYBOARD_EVENT_ITALIC = ev => ev.key === 'i' && (ev.ctrlKey || ev.metaKey);
const IS_KEYBOARD_EVENT_UNDERLINE = ev => ev.key === 'u' && (ev.ctrlKey || ev.metaKey);
const IS_KEYBOARD_EVENT_STRIKETHROUGH = ev => ev.key === '5' && (ev.ctrlKey || ev.metaKey); const IS_KEYBOARD_EVENT_STRIKETHROUGH = ev => ev.key === '5' && (ev.ctrlKey || ev.metaKey);
const CLIPBOARD_BLACKLISTS = { const CLIPBOARD_BLACKLISTS = {
...@@ -2362,6 +2364,16 @@ export class OdooEditor extends EventTarget { ...@@ -2362,6 +2364,16 @@ export class OdooEditor extends EventTarget {
ev.preventDefault(); ev.preventDefault();
ev.stopPropagation(); ev.stopPropagation();
this.execCommand('bold'); this.execCommand('bold');
} else if (IS_KEYBOARD_EVENT_ITALIC(ev)) {
// Ctrl-I
ev.preventDefault();
ev.stopPropagation();
this.execCommand('italic');
} else if (IS_KEYBOARD_EVENT_UNDERLINE(ev)) {
// Ctrl-U
ev.preventDefault();
ev.stopPropagation();
this.execCommand('underline');
} else if (IS_KEYBOARD_EVENT_STRIKETHROUGH(ev)) { } else if (IS_KEYBOARD_EVENT_STRIKETHROUGH(ev)) {
// Ctrl-5 / Ctrl-shift-( // Ctrl-5 / Ctrl-shift-(
ev.preventDefault(); ev.preventDefault();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment