Skip to content

Commit efaa359

Browse files
authored
feat(Selecion): support backspace action for fake paragraph (#100)
1 parent 8b40679 commit efaa359

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/extensions/behavior/Selection/commands.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type {Node, ResolvedPos} from 'prosemirror-model';
22
import type {Command, NodeSelection, TextSelection, Transaction} from 'prosemirror-state';
3+
import {Selection} from 'prosemirror-state';
34

45
import {isCodeBlock} from '../../../utils/nodes';
56
import {isNodeSelection, isTextSelection} from '../../../utils/selection';
@@ -174,3 +175,15 @@ export const arrowLeft = arrow('left');
174175
export const arrowDown = arrow('down');
175176
export const arrowUp = arrow('up');
176177
export const arrowRight = arrow('right');
178+
179+
export const backspace: Command = (state, dispatch) => {
180+
const sel = state.selection;
181+
if (isGapCursorSelection(sel)) {
182+
const newSel = Selection.findFrom(sel.$pos, -1);
183+
if (newSel) {
184+
dispatch?.(state.tr.setSelection(newSel).scrollIntoView());
185+
return true;
186+
}
187+
}
188+
return false;
189+
};

src/extensions/behavior/Selection/selection.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414

1515
import {isSelectableNode} from '../../../utils/nodes';
1616
import {isNodeSelection} from '../../../utils/selection';
17-
import {arrowDown, arrowLeft, arrowRight, arrowUp} from './commands';
17+
import {arrowDown, arrowLeft, arrowRight, arrowUp, backspace} from './commands';
1818

1919
import './selection.scss';
2020

@@ -26,6 +26,7 @@ export const selection = () =>
2626
ArrowRight: arrowRight,
2727
ArrowUp: arrowUp,
2828
ArrowDown: arrowDown,
29+
Backspace: backspace,
2930
}),
3031
decorations(state) {
3132
return getDecorations(state.tr);

0 commit comments

Comments
 (0)