mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-23 11:37:02 -04:00
Restructure repository (#426)
organized repository Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Co-authored-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Co-authored-by: Philip Molares <git@molar.es>
This commit is contained in:
parent
66258ca615
commit
0fadc09f2b
254 changed files with 384 additions and 403 deletions
93
src/components/editor/editor-pane/key-map.ts
Normal file
93
src/components/editor/editor-pane/key-map.ts
Normal file
|
@ -0,0 +1,93 @@
|
|||
import CodeMirror, { Editor, KeyMap, Pass } from 'codemirror'
|
||||
import {
|
||||
makeSelectionBold,
|
||||
makeSelectionItalic,
|
||||
markSelection,
|
||||
strikeThroughSelection,
|
||||
underlineSelection
|
||||
} from './tool-bar/utils/toolbarButtonUtils'
|
||||
|
||||
const isMac = navigator.platform.toLowerCase().includes('mac')
|
||||
|
||||
const isVim = (keyMapName?: string) => (keyMapName?.substr(0, 3) === 'vim')
|
||||
|
||||
const f10 = (editor: Editor): void | typeof Pass => editor.setOption('fullScreen', !editor.getOption('fullScreen'))
|
||||
const esc = (editor: Editor): void | typeof Pass => {
|
||||
if (editor.getOption('fullScreen') && !isVim(editor.getOption('keyMap'))) {
|
||||
editor.setOption('fullScreen', false)
|
||||
} else {
|
||||
return CodeMirror.Pass
|
||||
}
|
||||
}
|
||||
const suppressSave = (): undefined => undefined
|
||||
const tab = (editor: Editor) => {
|
||||
const tab = '\t'
|
||||
|
||||
// contruct x length spaces
|
||||
const spaces = Array((editor.getOption('indentUnit') ?? 0) + 1).join(' ')
|
||||
|
||||
// auto indent whole line when in list or blockquote
|
||||
const cursor = editor.getCursor()
|
||||
const line = editor.getLine(cursor.line)
|
||||
|
||||
// this regex match the following patterns
|
||||
// 1. blockquote starts with "> " or ">>"
|
||||
// 2. unorder list starts with *+-parseInt
|
||||
// 3. order list starts with "1." or "1)"
|
||||
const regex = /^(\s*)(>[> ]*|[*+-]\s|(\d+)([.)]))/
|
||||
|
||||
let match
|
||||
const multiple = editor.getSelection().split('\n').length > 1 ||
|
||||
editor.getSelections().length > 1
|
||||
|
||||
if (multiple) {
|
||||
editor.execCommand('defaultTab')
|
||||
} else if ((match = regex.exec(line)) !== null) {
|
||||
const ch = match[1].length
|
||||
const pos = {
|
||||
line: cursor.line,
|
||||
ch: ch
|
||||
}
|
||||
if (editor.getOption('indentWithTabs')) {
|
||||
editor.replaceRange(tab, pos, pos, '+input')
|
||||
} else {
|
||||
editor.replaceRange(spaces, pos, pos, '+input')
|
||||
}
|
||||
} else {
|
||||
if (editor.getOption('indentWithTabs')) {
|
||||
editor.execCommand('defaultTab')
|
||||
} else {
|
||||
editor.replaceSelection(spaces)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const defaultKeyMap: KeyMap = !isMac ? {
|
||||
F10: f10,
|
||||
Esc: esc,
|
||||
'Ctrl-S': suppressSave,
|
||||
Enter: 'newlineAndIndentContinueMarkdownList',
|
||||
Tab: tab,
|
||||
Home: 'goLineLeftSmart',
|
||||
End: 'goLineRight',
|
||||
'Ctrl-I': makeSelectionItalic,
|
||||
'Ctrl-B': makeSelectionBold,
|
||||
'Ctrl-U': underlineSelection,
|
||||
'Ctrl-D': strikeThroughSelection,
|
||||
'Ctrl-M': markSelection
|
||||
} : {
|
||||
F10: f10,
|
||||
Esc: esc,
|
||||
'Cmd-S': suppressSave,
|
||||
Enter: 'newlineAndIndentContinueMarkdownList',
|
||||
Tab: tab,
|
||||
'Cmd-Left': 'goLineLeftSmart',
|
||||
'Cmd-Right': 'goLineRight',
|
||||
Home: 'goLineLeftSmart',
|
||||
End: 'goLineRight',
|
||||
'Cmd-I': makeSelectionItalic,
|
||||
'Cmd-B': makeSelectionBold,
|
||||
'Cmd-U': underlineSelection,
|
||||
'Cmd-D': strikeThroughSelection,
|
||||
'Cmd-M': markSelection
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue