in src/component/handlers/edit/commands/keyCommandBackspaceToStartOfLine.js [23:61]
function keyCommandBackspaceToStartOfLine(
editorState: EditorState,
e: SyntheticKeyboardEvent<HTMLElement>,
): EditorState {
const afterRemoval = removeTextWithStrategy(
editorState,
strategyState => {
const selection = strategyState.getSelection();
if (selection.isCollapsed() && selection.getAnchorOffset() === 0) {
return moveSelectionBackward(strategyState, 1);
}
const {ownerDocument} = e.currentTarget;
const domSelection: SelectionObject =
ownerDocument.defaultView.getSelection();
// getRangeAt can technically throw if there's no selection, but we know
// there is one here because text editor has focus (the cursor is a
// selection of length 0). Therefore, we don't need to wrap this in a
// try-catch block.
let range = domSelection.getRangeAt(0);
range = expandRangeToStartOfLine(range);
return getDraftEditorSelectionWithNodes(
strategyState,
null,
range.endContainer,
range.endOffset,
range.startContainer,
range.startOffset,
).selectionState;
},
'backward',
);
if (afterRemoval === editorState.getCurrentContent()) {
return editorState;
}
return EditorState.push(editorState, afterRemoval, 'remove-range');
}