refactoring
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
|||||||
Slice,
|
Slice,
|
||||||
} from 'prosemirror-model'
|
} from 'prosemirror-model'
|
||||||
import { canSplit } from 'prosemirror-transform'
|
import { canSplit } from 'prosemirror-transform'
|
||||||
|
import { TextSelection } from 'prosemirror-state'
|
||||||
import { Command } from '../types'
|
import { Command } from '../types'
|
||||||
import getNodeType from '../helpers/getNodeType'
|
import getNodeType from '../helpers/getNodeType'
|
||||||
|
|
||||||
@@ -52,8 +53,7 @@ export const splitListItem = (typeOrName: string | NodeType): Command => ({ stat
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add a second list item with an empty default start node
|
// Add a second list item with an empty default start node
|
||||||
// @ts-ignore
|
wrap = wrap.append(Fragment.from(type.createAndFill() || undefined))
|
||||||
wrap = wrap.append(Fragment.from(type.createAndFill()))
|
|
||||||
|
|
||||||
const tr = state.tr.replace(
|
const tr = state.tr.replace(
|
||||||
$from.before(keepItem ? undefined : -1),
|
$from.before(keepItem ? undefined : -1),
|
||||||
@@ -62,8 +62,7 @@ export const splitListItem = (typeOrName: string | NodeType): Command => ({ stat
|
|||||||
)
|
)
|
||||||
|
|
||||||
tr
|
tr
|
||||||
// @ts-ignore
|
.setSelection(TextSelection.near(tr.doc.resolve($from.pos + (keepItem ? 3 : 2))))
|
||||||
.setSelection(state.selection.constructor.near(tr.doc.resolve($from.pos + (keepItem ? 3 : 2))))
|
|
||||||
.scrollIntoView()
|
.scrollIntoView()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,13 +108,11 @@ export const splitListItem = (typeOrName: string | NodeType): Command => ({ stat
|
|||||||
? [{ type, attrs: newTypeAttributes }, { type: nextType, attrs: newNextTypeAttributes }]
|
? [{ type, attrs: newTypeAttributes }, { type: nextType, attrs: newNextTypeAttributes }]
|
||||||
: [{ type, attrs: newTypeAttributes }]
|
: [{ type, attrs: newTypeAttributes }]
|
||||||
|
|
||||||
// @ts-ignore
|
if (!canSplit(tr.doc, $from.pos, 2)) {
|
||||||
if (!canSplit(tr.doc, $from.pos, 2, nextType && [null])) {
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dispatch) {
|
if (dispatch) {
|
||||||
// @ts-ignore
|
|
||||||
tr.split($from.pos, 2, types).scrollIntoView()
|
tr.split($from.pos, 2, types).scrollIntoView()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,16 +57,6 @@ export const TextAlign = Extension.create({
|
|||||||
|
|
||||||
addKeyboardShortcuts() {
|
addKeyboardShortcuts() {
|
||||||
return {
|
return {
|
||||||
// TODO: re-use only 'textAlign' attribute
|
|
||||||
// TODO: use custom splitBlock only for `this.options.types`
|
|
||||||
// Enter: () => this.editor.commands.first(({ commands }) => [
|
|
||||||
// () => commands.newlineInCode(),
|
|
||||||
// () => commands.createParagraphNear(),
|
|
||||||
// () => commands.liftEmptyBlock(),
|
|
||||||
// () => commands.splitBlock({
|
|
||||||
// withAttributes: true,
|
|
||||||
// }),
|
|
||||||
// ]),
|
|
||||||
'Mod-Shift-l': () => this.editor.commands.setTextAlign('left'),
|
'Mod-Shift-l': () => this.editor.commands.setTextAlign('left'),
|
||||||
'Mod-Shift-e': () => this.editor.commands.setTextAlign('center'),
|
'Mod-Shift-e': () => this.editor.commands.setTextAlign('center'),
|
||||||
'Mod-Shift-r': () => this.editor.commands.setTextAlign('right'),
|
'Mod-Shift-r': () => this.editor.commands.setTextAlign('right'),
|
||||||
|
|||||||
Reference in New Issue
Block a user