tabs to spaces whitespace
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
export default function (text = '') {
|
||||
return (state, dispatch) => {
|
||||
const { $from } = state.selection
|
||||
const { pos } = $from.pos
|
||||
return (state, dispatch) => {
|
||||
const { $from } = state.selection
|
||||
const { pos } = $from.pos
|
||||
|
||||
dispatch(state.tr.insertText(text, pos))
|
||||
dispatch(state.tr.insertText(text, pos))
|
||||
|
||||
return true
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
import { InputRule } from 'prosemirror-inputrules'
|
||||
|
||||
export default function (regexp, markType, getAttrs) {
|
||||
return new InputRule(regexp, (state, match, start, end) => {
|
||||
const attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs
|
||||
return new InputRule(regexp, (state, match, start, end) => {
|
||||
const attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs
|
||||
const { tr } = state
|
||||
let markEnd = end
|
||||
|
||||
if (match[1]) {
|
||||
const startSpaces = match[0].search(/\S/)
|
||||
const textStart = start + match[0].indexOf(match[1])
|
||||
const textEnd = textStart + match[1].length
|
||||
if (textEnd < end) {
|
||||
tr.delete(textEnd, end)
|
||||
}
|
||||
if (textStart > start) {
|
||||
tr.delete(start + startSpaces, textStart)
|
||||
}
|
||||
markEnd = start + startSpaces + match[1].length
|
||||
}
|
||||
if (match[1]) {
|
||||
const startSpaces = match[0].search(/\S/)
|
||||
const textStart = start + match[0].indexOf(match[1])
|
||||
const textEnd = textStart + match[1].length
|
||||
if (textEnd < end) {
|
||||
tr.delete(textEnd, end)
|
||||
}
|
||||
if (textStart > start) {
|
||||
tr.delete(start + startSpaces, textStart)
|
||||
}
|
||||
markEnd = start + startSpaces + match[1].length
|
||||
}
|
||||
|
||||
tr.addMark(start, markEnd, markType.create(attrs))
|
||||
tr.removeStoredMark(markType) // Do not continue with mark.
|
||||
return tr
|
||||
})
|
||||
tr.addMark(start, markEnd, markType.create(attrs))
|
||||
tr.removeStoredMark(markType) // Do not continue with mark.
|
||||
return tr
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export default function (type) {
|
||||
return (state, dispatch) => {
|
||||
const { from, to } = state.selection
|
||||
return dispatch(state.tr.removeMark(from, to, type))
|
||||
}
|
||||
const { from, to } = state.selection
|
||||
return dispatch(state.tr.removeMark(from, to, type))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
export default function (range, type, attrs = {}) {
|
||||
return (state, dispatch) => {
|
||||
const { $from } = state.selection
|
||||
const index = $from.index()
|
||||
return (state, dispatch) => {
|
||||
const { $from } = state.selection
|
||||
const index = $from.index()
|
||||
|
||||
if (!$from.parent.canReplaceWith(index, index, type)) {
|
||||
return false
|
||||
}
|
||||
if (!$from.parent.canReplaceWith(index, index, type)) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (dispatch) {
|
||||
dispatch(state.tr.replaceWith(range.from, range.to, type.create(attrs)))
|
||||
}
|
||||
if (dispatch) {
|
||||
dispatch(state.tr.replaceWith(range.from, range.to, type.create(attrs)))
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
export default function (type, attrs = {}) {
|
||||
return (state, dispatch) => {
|
||||
const { $from } = state.selection
|
||||
const index = $from.index()
|
||||
return (state, dispatch) => {
|
||||
const { $from } = state.selection
|
||||
const index = $from.index()
|
||||
|
||||
if (!$from.parent.canReplaceWith(index, index, type)) {
|
||||
return false
|
||||
}
|
||||
if (!$from.parent.canReplaceWith(index, index, type)) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (dispatch) {
|
||||
dispatch(state.tr.replaceSelectionWith(type.create(attrs)))
|
||||
}
|
||||
if (dispatch) {
|
||||
dispatch(state.tr.replaceSelectionWith(type.create(attrs)))
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,13 +16,13 @@ index = $pos.index(d)
|
||||
if (node.type.spec.isolating) return false
|
||||
let rest = node.content.cutByIndex(index, node.childCount)
|
||||
const after = (typesAfter && typesAfter[i]) || node
|
||||
if (after != node) rest = rest.replaceChild(0, after.type.create(after.attrs))
|
||||
if (after != node) rest = rest.replaceChild(0, after.type.create(after.attrs))
|
||||
|
||||
/* Change starts from here */
|
||||
// if (!node.canReplace(index + 1, node.childCount) || !after.type.validContent(rest))
|
||||
/* Change starts from here */
|
||||
// if (!node.canReplace(index + 1, node.childCount) || !after.type.validContent(rest))
|
||||
// return false
|
||||
if (!node.canReplace(index + 1, node.childCount)) return false
|
||||
/* Change ends here */
|
||||
/* Change ends here */
|
||||
}
|
||||
const index = $pos.indexAfter(base)
|
||||
const baseType = typesAfter && typesAfter[0]
|
||||
@@ -43,7 +43,7 @@ export default function splitListItem(itemType) {
|
||||
// list item should be split. Otherwise, bail out and let next
|
||||
// command handle lifting.
|
||||
if ($from.depth == 2 || $from.node(-3).type != itemType
|
||||
|| $from.index(-2) != $from.node(-2).childCount - 1) return false
|
||||
|| $from.index(-2) != $from.node(-2).childCount - 1) return false
|
||||
|
||||
if (dispatch) {
|
||||
let wrap = Fragment.empty; const
|
||||
@@ -52,23 +52,23 @@ keepItem = $from.index(-1) > 0
|
||||
// from the outer list item to the parent node of the cursor
|
||||
for (let d = $from.depth - (keepItem ? 1 : 2); d >= $from.depth - 3; d--) wrap = Fragment.from($from.node(d).copy(wrap))
|
||||
// Add a second list item with an empty default start node
|
||||
wrap = wrap.append(Fragment.from(itemType.createAndFill()))
|
||||
wrap = wrap.append(Fragment.from(itemType.createAndFill()))
|
||||
const tr = state.tr.replace($from.before(keepItem ? null : -1), $from.after(-3), new Slice(wrap, keepItem ? 3 : 2, 2))
|
||||
tr.setSelection(state.selection.constructor.near(tr.doc.resolve($from.pos + (keepItem ? 3 : 2))))
|
||||
dispatch(tr.scrollIntoView())
|
||||
}
|
||||
return true
|
||||
}
|
||||
const nextType = $to.pos == $from.end() ? grandParent.contentMatchAt($from.indexAfter(-1)).defaultType : null
|
||||
const tr = state.tr.delete($from.pos, $to.pos)
|
||||
const nextType = $to.pos == $from.end() ? grandParent.contentMatchAt($from.indexAfter(-1)).defaultType : null
|
||||
const tr = state.tr.delete($from.pos, $to.pos)
|
||||
|
||||
/* Change starts from here */
|
||||
// let types = nextType && [null, {type: nextType}]
|
||||
/* Change starts from here */
|
||||
// let types = nextType && [null, {type: nextType}]
|
||||
let types = nextType && [{ type: itemType }, { type: nextType }]
|
||||
if (!types) types = [{ type: itemType }, null]
|
||||
/* Change ends here */
|
||||
/* Change ends here */
|
||||
|
||||
if (!canSplit(tr.doc, $from.pos, 2, types)) return false
|
||||
if (!canSplit(tr.doc, $from.pos, 2, types)) return false
|
||||
if (dispatch) dispatch(tr.split($from.pos, 2, [{ type: state.schema.nodes.todo_item, attrs: { done: false } }]).scrollIntoView())
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -2,13 +2,13 @@ import { setBlockType } from 'prosemirror-commands'
|
||||
import { nodeIsActive } from 'tiptap-utils'
|
||||
|
||||
export default function (type, toggletype, attrs = {}) {
|
||||
return (state, dispatch, view) => {
|
||||
const isActive = nodeIsActive(state, type, attrs)
|
||||
return (state, dispatch, view) => {
|
||||
const isActive = nodeIsActive(state, type, attrs)
|
||||
|
||||
if (isActive) {
|
||||
return setBlockType(toggletype)(state, dispatch, view)
|
||||
}
|
||||
if (isActive) {
|
||||
return setBlockType(toggletype)(state, dispatch, view)
|
||||
}
|
||||
|
||||
return setBlockType(type, attrs)(state, dispatch, view)
|
||||
}
|
||||
return setBlockType(type, attrs)(state, dispatch, view)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,13 @@ import { wrapIn, lift } from 'prosemirror-commands'
|
||||
import { nodeIsActive } from 'tiptap-utils'
|
||||
|
||||
export default function (type) {
|
||||
return (state, dispatch, view) => {
|
||||
const isActive = nodeIsActive(state, type)
|
||||
return (state, dispatch, view) => {
|
||||
const isActive = nodeIsActive(state, type)
|
||||
|
||||
if (isActive) {
|
||||
return lift(state, dispatch)
|
||||
}
|
||||
if (isActive) {
|
||||
return lift(state, dispatch)
|
||||
}
|
||||
|
||||
return wrapIn(type)(state, dispatch, view)
|
||||
}
|
||||
return wrapIn(type)(state, dispatch, view)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export default function (type, attrs) {
|
||||
return (state, dispatch) => {
|
||||
const { from, to } = state.selection
|
||||
return dispatch(state.tr.addMark(from, to, type.create(attrs)))
|
||||
}
|
||||
const { from, to } = state.selection
|
||||
return dispatch(state.tr.addMark(from, to, type.create(attrs)))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user