in src/component/handlers/edit/commands/moveSelectionBackward.js [27:62]
function moveSelectionBackward(
editorState: EditorState,
maxDistance: number,
): SelectionState {
const selection = editorState.getSelection();
// Should eventually make this an invariant
warning(
selection.isCollapsed(),
'moveSelectionBackward should only be called with a collapsed SelectionState',
);
const content = editorState.getCurrentContent();
const key = selection.getStartKey();
const offset = selection.getStartOffset();
let focusKey = key;
let focusOffset = 0;
if (maxDistance > offset) {
const keyBefore = content.getKeyBefore(key);
if (keyBefore == null) {
focusKey = key;
} else {
focusKey = keyBefore;
const blockBefore = content.getBlockForKey(keyBefore);
focusOffset = blockBefore.getText().length;
}
} else {
focusOffset = offset - maxDistance;
}
return selection.merge({
focusKey,
focusOffset,
isBackward: true,
});
}