diff --git a/src/extensions/behavior/Selection/commands.ts b/src/extensions/behavior/Selection/commands.ts index 1d92ec7a..f6e99d3b 100644 --- a/src/extensions/behavior/Selection/commands.ts +++ b/src/extensions/behavior/Selection/commands.ts @@ -1,5 +1,6 @@ import type {Node, ResolvedPos} from 'prosemirror-model'; import type {Command, NodeSelection, TextSelection, Transaction} from 'prosemirror-state'; +import {Selection} from 'prosemirror-state'; import {isCodeBlock} from '../../../utils/nodes'; import {isNodeSelection, isTextSelection} from '../../../utils/selection'; @@ -174,3 +175,15 @@ export const arrowLeft = arrow('left'); export const arrowDown = arrow('down'); export const arrowUp = arrow('up'); export const arrowRight = arrow('right'); + +export const backspace: Command = (state, dispatch) => { + const sel = state.selection; + if (isGapCursorSelection(sel)) { + const newSel = Selection.findFrom(sel.$pos, -1); + if (newSel) { + dispatch?.(state.tr.setSelection(newSel).scrollIntoView()); + return true; + } + } + return false; +}; diff --git a/src/extensions/behavior/Selection/selection.ts b/src/extensions/behavior/Selection/selection.ts index 29d224a9..90a13f25 100644 --- a/src/extensions/behavior/Selection/selection.ts +++ b/src/extensions/behavior/Selection/selection.ts @@ -14,7 +14,7 @@ import { import {isSelectableNode} from '../../../utils/nodes'; import {isNodeSelection} from '../../../utils/selection'; -import {arrowDown, arrowLeft, arrowRight, arrowUp} from './commands'; +import {arrowDown, arrowLeft, arrowRight, arrowUp, backspace} from './commands'; import './selection.scss'; @@ -26,6 +26,7 @@ export const selection = () => ArrowRight: arrowRight, ArrowUp: arrowUp, ArrowDown: arrowDown, + Backspace: backspace, }), decorations(state) { return getDecorations(state.tr);