js: move buildKeyMap to utils.mjs (#69407)
gitea/godo.js/pipeline/head This commit looks good
Details
gitea/godo.js/pipeline/head This commit looks good
Details
This commit is contained in:
parent
052fb4ef04
commit
0cdf0ae4c7
|
@ -29,6 +29,10 @@ export default () => ({
|
|||
toDOM () { return ['br'] },
|
||||
},
|
||||
},
|
||||
|
||||
// * **Ctrl-Shift-0** for making the current textblock a paragraph
|
||||
// * **Ctrl-Shift-Backslash** to make the current textblock a code block
|
||||
// * **Mod-Enter** to insert a hard break
|
||||
keymap (schema) {
|
||||
const paragraph = schema.nodes.paragraph
|
||||
const hardBreak = schema.nodes.hardBreak
|
||||
|
|
|
@ -27,6 +27,10 @@ export default () => ({
|
|||
toDOM () { return ['strong', 0] },
|
||||
},
|
||||
},
|
||||
|
||||
// * **Mod-b** for toggling [strong](#schema-basic.StrongMark)
|
||||
// * **Mod-i** for toggling [emphasis](#schema-basic.EmMark)
|
||||
// * **Mod-`** for toggling [code font](#schema-basic.CodeMark)
|
||||
keymap (schema) {
|
||||
const strong = schema.marks.strong
|
||||
const em = schema.marks.em
|
||||
|
|
|
@ -25,6 +25,9 @@ export default function (options) {
|
|||
toDOM (node) { return ['h' + node.attrs.level, 0] },
|
||||
},
|
||||
},
|
||||
|
||||
// * **Ctrl-Shift-1** to **Ctrl-Shift-Digit6** for making the current
|
||||
// textblock a heading of the corresponding level
|
||||
keymap (schema) {
|
||||
const heading = schema.nodes.heading
|
||||
let keys = {}
|
||||
|
|
|
@ -22,6 +22,12 @@ export default () => ({
|
|||
defining: true,
|
||||
},
|
||||
},
|
||||
|
||||
// * **Enter** to split a non-empty textblock in a list item while at
|
||||
// the same time splitting the list item
|
||||
// * **Alt-ArrowUp** to `joinUp`
|
||||
// * **Alt-ArrowDown** to `joinDown`
|
||||
// * **Mod-BracketLeft** to `lift`
|
||||
keymap (schema) {
|
||||
const listItem = schema.nodes.listItem
|
||||
return {
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
// :: (Schema, ?Object) → Object
|
||||
// Inspect the given schema looking for marks and nodes from the
|
||||
// basic schema, and if found, add key bindings related to them.
|
||||
// This will add:
|
||||
//
|
||||
// * **Mod-b** for toggling [strong](#schema-basic.StrongMark)
|
||||
// * **Mod-i** for toggling [emphasis](#schema-basic.EmMark)
|
||||
// * **Mod-`** for toggling [code font](#schema-basic.CodeMark)
|
||||
// * **Ctrl-Shift-0** for making the current textblock a paragraph
|
||||
// * **Ctrl-Shift-1** to **Ctrl-Shift-Digit6** for making the current
|
||||
// textblock a heading of the corresponding level
|
||||
// * **Ctrl-Shift-Backslash** to make the current textblock a code block
|
||||
// * **Ctrl->** to wrap the selection in a block quote
|
||||
// * **Enter** to split a non-empty textblock in a list item while at
|
||||
// the same time splitting the list item
|
||||
// * **Mod-Enter** to insert a hard break
|
||||
// * **Mod-_** to insert a horizontal rule
|
||||
// * **Backspace** to undo an input rule
|
||||
// * **Alt-ArrowUp** to `joinUp`
|
||||
// * **Alt-ArrowDown** to `joinDown`
|
||||
// * **Mod-BracketLeft** to `lift`
|
||||
//
|
||||
// You can suppress or map these bindings by passing a `mapKeys`
|
||||
// argument, which maps key names (say `"Mod-B"` to either `false`, to
|
||||
// remove the binding, or a new key name string.
|
||||
export function buildKeymap (components, schema) {
|
||||
let keys = {}
|
||||
|
||||
for (const component of components) {
|
||||
if (component.keymap) {
|
||||
Object.assign(keys, component.keymap(schema))
|
||||
}
|
||||
}
|
||||
|
||||
return keys
|
||||
}
|
|
@ -5,10 +5,9 @@ import {keymap} from 'prosemirror-keymap'
|
|||
import {baseKeymap} from 'prosemirror-commands'
|
||||
import {DOMParser, DOMSerializer} from 'prosemirror-model'
|
||||
|
||||
import {buildKeymap} from './godo-additional-keymap.mjs'
|
||||
import {Menu, blocks, marks} from './godo-menus.mjs'
|
||||
import {dialog} from './godo-dialog.mjs'
|
||||
import {loadSchema} from './utils.mjs'
|
||||
import {loadSchema, buildKeymap} from './utils.mjs'
|
||||
import base from './components/base.mjs'
|
||||
import fontMarks from './components/font-marks.mjs'
|
||||
import heading from './components/heading.mjs'
|
||||
|
|
|
@ -25,3 +25,15 @@ export function icon (id) {
|
|||
menuicon.textContent = getLanguage(id).icon
|
||||
return menuicon
|
||||
}
|
||||
|
||||
export function buildKeymap (components, schema) {
|
||||
let keys = {}
|
||||
|
||||
for (const component of components) {
|
||||
if (component.keymap) {
|
||||
Object.assign(keys, component.keymap(schema))
|
||||
}
|
||||
}
|
||||
|
||||
return keys
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import {history} from 'prosemirror-history'
|
|||
import {vi} from 'vitest'
|
||||
|
||||
import {loadSchema} from '../src-js/utils'
|
||||
import {buildKeymap} from '../src-js/godo-additional-keymap.mjs'
|
||||
import {buildKeymap} from '../src-js/utils.mjs'
|
||||
import {blocks, marks} from '../src-js/godo-menus.mjs'
|
||||
|
||||
export function parse (schema, html) {
|
||||
|
|
Loading…
Reference in New Issue