mirror of
https://github.com/doocs/md.git
synced 2024-11-24 19:10:34 +08:00
feat: support keyboard shortcuts on Mac (#248)
Co-authored-by: hoollyzhang <hoollyzhang@tencent.com>
This commit is contained in:
parent
aed86de910
commit
806c4c086d
@ -88,6 +88,9 @@ export const useStore = defineStore(`store`, {
|
|||||||
editorDom.value =
|
editorDom.value =
|
||||||
localStorage.getItem(`__editor_content`) || formatDoc(DEFAULT_CONTENT)
|
localStorage.getItem(`__editor_content`) || formatDoc(DEFAULT_CONTENT)
|
||||||
}
|
}
|
||||||
|
const defaultKeyMap = CodeMirror.keyMap[`default`]
|
||||||
|
const modPrefix =
|
||||||
|
defaultKeyMap === CodeMirror.keyMap[`macDefault`] ? `Cmd` : `Ctrl`
|
||||||
this.editor = CodeMirror.fromTextArea(editorDom, {
|
this.editor = CodeMirror.fromTextArea(editorDom, {
|
||||||
mode: `text/x-markdown`,
|
mode: `text/x-markdown`,
|
||||||
theme: `xq-light`,
|
theme: `xq-light`,
|
||||||
@ -96,24 +99,27 @@ export const useStore = defineStore(`store`, {
|
|||||||
styleActiveLine: true,
|
styleActiveLine: true,
|
||||||
autoCloseBrackets: true,
|
autoCloseBrackets: true,
|
||||||
extraKeys: {
|
extraKeys: {
|
||||||
'Ctrl-F': function autoFormat(editor) {
|
[`${modPrefix}-F`]: function autoFormat(editor) {
|
||||||
const doc = formatDoc(editor.getValue(0))
|
const doc = formatDoc(editor.getValue(0))
|
||||||
localStorage.setItem(`__editor_content`, doc)
|
localStorage.setItem(`__editor_content`, doc)
|
||||||
editor.setValue(doc)
|
editor.setValue(doc)
|
||||||
},
|
},
|
||||||
'Ctrl-S': function save(editor) {},
|
[[`${modPrefix}-B`]]: function bold(editor) {
|
||||||
'Ctrl-B': function bold(editor) {
|
|
||||||
const selected = editor.getSelection()
|
const selected = editor.getSelection()
|
||||||
editor.replaceSelection(`**${selected}**`)
|
editor.replaceSelection(`**${selected}**`)
|
||||||
},
|
},
|
||||||
'Ctrl-D': function del(editor) {
|
[`${modPrefix}-D`]: function del(editor) {
|
||||||
const selected = editor.getSelection()
|
const selected = editor.getSelection()
|
||||||
editor.replaceSelection(`~~${selected}~~`)
|
editor.replaceSelection(`~~${selected}~~`)
|
||||||
},
|
},
|
||||||
'Ctrl-I': function italic(editor) {
|
[`${modPrefix}-I`]: function italic(editor) {
|
||||||
const selected = editor.getSelection()
|
const selected = editor.getSelection()
|
||||||
editor.replaceSelection(`*${selected}*`)
|
editor.replaceSelection(`*${selected}*`)
|
||||||
},
|
},
|
||||||
|
[`${modPrefix}-L`]: function code(editor) {
|
||||||
|
const selected = editor.getSelection()
|
||||||
|
editor.replaceSelection(`\`${selected}\``)
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user