mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-21 14:41:23 +02:00
Insert outside inline when selection is at the end (#3260)
* Insert outside inline when selection is at the end * Move inline edge check to insert_text * Fix selection point after deleting text
This commit is contained in:
committed by
Ian Storm Taylor
parent
e1918a7cf4
commit
b4268647a2
@@ -128,7 +128,26 @@ export const createEditor = (): Editor => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case 'insert_text': {
|
case 'insert_text': {
|
||||||
Editor.insertText(editor, command.text)
|
if (selection) {
|
||||||
|
const { anchor } = selection
|
||||||
|
|
||||||
|
// If the cursor is at the end of an inline, move it outside
|
||||||
|
// of the inline before inserting
|
||||||
|
if (Range.isCollapsed(selection)) {
|
||||||
|
const inline = Editor.match(editor, anchor, 'inline')
|
||||||
|
|
||||||
|
if (inline) {
|
||||||
|
const [, inlinePath] = inline
|
||||||
|
|
||||||
|
if (Editor.isEnd(editor, anchor, inlinePath)) {
|
||||||
|
const point = Editor.after(editor, inlinePath)!
|
||||||
|
Editor.setSelection(editor, { anchor: point, focus: point })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Editor.insertText(editor, command.text)
|
||||||
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -392,6 +392,7 @@ export const TextTransforms = {
|
|||||||
const pointRef = Editor.pointRef(editor, end)
|
const pointRef = Editor.pointRef(editor, end)
|
||||||
Editor.delete(editor, { at, voids })
|
Editor.delete(editor, { at, voids })
|
||||||
at = pointRef.unref()!
|
at = pointRef.unref()!
|
||||||
|
Editor.setSelection(editor, { anchor: at, focus: at })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -0,0 +1,31 @@
|
|||||||
|
/** @jsx jsx */
|
||||||
|
|
||||||
|
import { jsx } from '../../..'
|
||||||
|
|
||||||
|
export const run = editor => {
|
||||||
|
editor.exec({ type: 'insert_text', text: 'four' })
|
||||||
|
}
|
||||||
|
|
||||||
|
export const input = (
|
||||||
|
<editor>
|
||||||
|
<block>
|
||||||
|
one
|
||||||
|
<inline>
|
||||||
|
two
|
||||||
|
<cursor />
|
||||||
|
</inline>
|
||||||
|
three
|
||||||
|
</block>
|
||||||
|
</editor>
|
||||||
|
)
|
||||||
|
|
||||||
|
export const output = (
|
||||||
|
<editor>
|
||||||
|
<block>
|
||||||
|
one
|
||||||
|
<inline>two</inline>
|
||||||
|
fourthree
|
||||||
|
<cursor />
|
||||||
|
</block>
|
||||||
|
</editor>
|
||||||
|
)
|
Reference in New Issue
Block a user