Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Selecion): support backspace action for fake paragraph #100

Merged
merged 1 commit into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/extensions/behavior/Selection/commands.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
};
3 changes: 2 additions & 1 deletion src/extensions/behavior/Selection/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -26,6 +26,7 @@ export const selection = () =>
ArrowRight: arrowRight,
ArrowUp: arrowUp,
ArrowDown: arrowDown,
Backspace: backspace,
}),
decorations(state) {
return getDecorations(state.tr);
Expand Down