Moves cursor to position when clicking in the text box

This commit is contained in:
alonso.torres 2021-07-12 12:38:41 +02:00
parent b4b12e68bf
commit 69e256ab86
4 changed files with 44 additions and 2 deletions

View file

@ -56,6 +56,18 @@ function getSelectAllSelection(state) {
});
}
function getCursorInEndPosition(state) {
const content = state.getCurrentContent();
const lastBlock = content.getBlockMap().last();
return new SelectionState({
"anchorKey": lastBlock.getKey(),
"anchorOffset": lastBlock.getLength(),
"focusKey": lastBlock.getKey(),
"focusOffset": lastBlock.getLength()
});
}
export function selectAll(state) {
return EditorState.forceSelection(state, getSelectAllSelection(state));
}
@ -209,3 +221,16 @@ export function removeInlineStylePrefix(contentState, selectionState, stylePrefi
return block.set("characterList", chars);
});
}
export function cursorToEnd(state) {
const newSelection = getCursorInEndPosition(state);
const selection = state.getSelection();
let content = state.getCurrentContent();
content = Modifier.applyEntity(content, newSelection, null);
state = EditorState.forceSelection(state, newSelection);
state = EditorState.push(state, content, "apply-entity");
return state;
}