fix em input rule

This commit is contained in:
Philipp Kühn
2018-08-27 21:53:12 +02:00
parent 7d60a084a4
commit 1de45acef5
2 changed files with 9 additions and 4 deletions

View File

@@ -6,11 +6,16 @@ export default function (regexp, markType, getAttrs) {
let tr = state.tr let tr = state.tr
if (match[1]) { if (match[1]) {
const startSpaces = match[0].search(/\S/)
let textStart = start + match[0].indexOf(match[1]) let textStart = start + match[0].indexOf(match[1])
let textEnd = textStart + match[1].length let textEnd = textStart + match[1].length
if (textEnd < end) tr.delete(textEnd, end) if (textEnd < end) {
if (textStart > start) tr.delete(start, textStart) tr.delete(textEnd, end)
end = start + match[1].length }
if (textStart > start) {
tr.delete(start + startSpaces, textStart)
}
end = start + startSpaces + match[1].length
} }
tr.addMark(start, end, markType.create(attrs)) tr.addMark(start, end, markType.create(attrs))

View File

@@ -30,7 +30,7 @@ export default class ItalicMark extends Mark {
inputRules({ type }) { inputRules({ type }) {
return [ return [
markInputRule(/(?:\*|_)([^\*_]+)(?:\*|_)$/, type), markInputRule(/(?:^|[^\*_])(?:\*|_)([^\*_]+)(?:\*|_)$/, type),
] ]
} }