mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 13:47:58 +01:00
feat: use keyCode for markdown shortcuts
This commit is contained in:
parent
9ca1a50a0a
commit
b442d983b0
1 changed files with 9 additions and 9 deletions
|
@ -7,19 +7,19 @@ import { $, $$ } from './utils/dom';
|
||||||
const markdownSyntax = {
|
const markdownSyntax = {
|
||||||
bold: {
|
bold: {
|
||||||
action: wrapSelection,
|
action: wrapSelection,
|
||||||
options: { prefix: '**', shortcutKey: 'b' },
|
options: { prefix: '**', shortcutKeyCode: 66 },
|
||||||
},
|
},
|
||||||
italics: {
|
italics: {
|
||||||
action: wrapSelection,
|
action: wrapSelection,
|
||||||
options: { prefix: '*', shortcutKey: 'i' },
|
options: { prefix: '*', shortcutKeyCode: 73 },
|
||||||
},
|
},
|
||||||
under: {
|
under: {
|
||||||
action: wrapSelection,
|
action: wrapSelection,
|
||||||
options: { prefix: '__', shortcutKey: 'u' },
|
options: { prefix: '__', shortcutKeyCode: 85 },
|
||||||
},
|
},
|
||||||
spoiler: {
|
spoiler: {
|
||||||
action: wrapSelection,
|
action: wrapSelection,
|
||||||
options: { prefix: '||', shortcutKey: 's' },
|
options: { prefix: '||', shortcutKeyCode: 83 },
|
||||||
},
|
},
|
||||||
code: {
|
code: {
|
||||||
action: wrapSelectionOrLines,
|
action: wrapSelectionOrLines,
|
||||||
|
@ -29,7 +29,7 @@ const markdownSyntax = {
|
||||||
prefixMultiline: '```\n',
|
prefixMultiline: '```\n',
|
||||||
suffixMultiline: '\n```',
|
suffixMultiline: '\n```',
|
||||||
singleWrap: true,
|
singleWrap: true,
|
||||||
shortcutKey: 'e',
|
shortcutKeyCode: 69,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
strike: {
|
strike: {
|
||||||
|
@ -50,11 +50,11 @@ const markdownSyntax = {
|
||||||
},
|
},
|
||||||
link: {
|
link: {
|
||||||
action: insertLink,
|
action: insertLink,
|
||||||
options: { shortcutKey: 'l' },
|
options: { shortcutKeyCode: 76 },
|
||||||
},
|
},
|
||||||
image: {
|
image: {
|
||||||
action: insertLink,
|
action: insertLink,
|
||||||
options: { image: true, shortcutKey: 'k' },
|
options: { image: true, shortcutKeyCode: 75 },
|
||||||
},
|
},
|
||||||
escape: {
|
escape: {
|
||||||
action: escapeSelection,
|
action: escapeSelection,
|
||||||
|
@ -257,10 +257,10 @@ function shortcutHandler(event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const textarea = event.target,
|
const textarea = event.target,
|
||||||
key = event.key.toLowerCase();
|
keyCode = event.keyCode;
|
||||||
|
|
||||||
for (const id in markdownSyntax) {
|
for (const id in markdownSyntax) {
|
||||||
if (key === markdownSyntax[id].options.shortcutKey) {
|
if (keyCode === markdownSyntax[id].options.shortcutKeyCode) {
|
||||||
markdownSyntax[id].action(textarea, markdownSyntax[id].options);
|
markdownSyntax[id].action(textarea, markdownSyntax[id].options);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue