Skip to content

fix: allow backspace to move to next run#2201

Closed
palmer-cl wants to merge 3 commits intomainfrom
fix/backspace-tc-ff
Closed

fix: allow backspace to move to next run#2201
palmer-cl wants to merge 3 commits intomainfrom
fix/backspace-tc-ff

Conversation

@palmer-cl
Copy link
Copy Markdown
Collaborator

This is related to: #2175

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d31ddfd06c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/super-editor/src/core/commands/backspaceNextToRun.js Outdated
Copy link
Copy Markdown
Contributor

@caio-pizzol caio-pizzol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@palmer-cl makes sense to widen the scan past single-char runs, but removing the bound entirely can delete into a previous paragraph outside of TC mode. left two inline comments — main suggestion is using paragraph start as the bound instead of no bound.

const findPreviousTextDeleteRange = (doc, cursorPos, minPos) => {
for (let pos = cursorPos - 1; pos >= minPos; pos -= 1) {
const findPreviousTextDeleteRange = (doc, cursorPos) => {
for (let pos = cursorPos - 1; pos > 0; pos -= 1) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without a lower bound, this scan can walk past paragraph boundaries and delete a character from the wrong paragraph. that only gets caught by normalizeReplaceStepSingleCharDelete in track-changes mode — in normal editing it goes through silently.

instead of removing minPos entirely, scope it to the current paragraph:

const paragraphStart = $pos.start($pos.depth);
const deleteRange = findPreviousTextDeleteRange(state.doc, $pos.pos, paragraphStart);

that still lets you cross sibling runs (fixing the single-char run issue) without leaving the paragraph.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did try this as a solution:

image

here were the results:

Screen Cast 2026-02-27 at 9 49 35 AM

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@caio-pizzol what are your thoughts?

Copy link
Copy Markdown
Contributor

@caio-pizzol caio-pizzol Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the reason $pos.start($pos.depth) didn't work is that $pos.depth points to different levels depending on cursor position:

  • between runs (case 1: $pos.nodeBefore is a run) → $pos.depth is the paragraph depth → $pos.start($pos.depth) = paragraph start ✓
  • at the start of a run (case 2: $pos.pos === $pos.start()) → $pos.depth is the run's depth → $pos.start($pos.depth) = run content start ✗

so in case 2 the bound collapses back to the run, which is why backspace still couldn't cross into the previous run in your video.

we already solve this exact problem in backspaceAcrossRuns.js:32 — just need to compute paraDepth the same way:

const paragraphDepth = $pos.parent.type === runType ? $pos.depth - 1 : $pos.depth;
const paragraphStart = $pos.start(paragraphDepth);
const deleteRange = findPreviousTextDeleteRange(state.doc, $pos.pos, paragraphStart);

that gives paragraph-scoped bounds for both cursor positions — crosses sibling runs but not paragraph boundaries.

check: #2225

@@ -109,27 +109,4 @@ describe('backspaceNextToRun', () => {
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test covers the cross-paragraph case — with a paragraph-scoped bound it should still pass. worth keeping.

@palmer-cl
Copy link
Copy Markdown
Collaborator Author

Closing this PR this is no longer an issue in Firefox post merging main, it looks like findPreviousTextDeleteRange was updated.

@palmer-cl palmer-cl closed this Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants