mirror of
https://github.com/penpot/penpot.git
synced 2025-08-01 14:38:40 +02:00
✨ Moves cursor to position when clicking in the text box
This commit is contained in:
parent
b4b12e68bf
commit
69e256ab86
4 changed files with 44 additions and 2 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue