Skip to content
This repository was archived by the owner on Oct 11, 2022. It is now read-only.

Commit 8693ae5

Browse files
committed
fix selection
1 parent 59e0b5e commit 8693ae5

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/modifiers/changeCurrentBlockType.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,27 @@ const changeCurrentBlockType = (
77
blockMetadata = {}
88
) => {
99
const currentContent = editorState.getCurrentContent();
10-
const selection = editorState.getSelection();
10+
let selection = editorState.getSelection();
1111
const key = selection.getStartKey();
1212
const blockMap = currentContent.getBlockMap();
1313
const block = blockMap.get(key);
1414
const data = block.getData().merge(blockMetadata);
1515
const newBlock = block.merge({ type, data, text: text });
16+
17+
const lastOffset = text.length;
18+
19+
if (selection.getFocusOffset() > lastOffset) {
20+
selection = selection.merge({
21+
anchorOffset: lastOffset,
22+
focusOffset: lastOffset,
23+
});
24+
}
25+
1626
const newContentState = currentContent.merge({
1727
blockMap: blockMap.set(key, newBlock),
1828
selectionAfter: selection,
1929
});
30+
2031
return EditorState.push(editorState, newContentState, "change-block-type");
2132
};
2233

0 commit comments

Comments
 (0)