Skip to content
Closed
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
12 changes: 1 addition & 11 deletions packages/super-editor/src/core/commands/backspaceNextToRun.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,7 @@ export const backspaceNextToRun =
if (prevNode?.type !== runType || prevNode.content.size === 0) return false;
}

// Constrain the text scan to the adjacent run so we never delete
// text from a previous paragraph or an unrelated run.
let runContentStart;
if ($pos.nodeBefore) {
runContentStart = $pos.pos - $pos.nodeBefore.nodeSize + 1;
} else {
const prevNode = state.doc.resolve($pos.start() - 1).nodeBefore;
runContentStart = $pos.start() - 1 - prevNode.nodeSize + 1;
}

const deleteRange = findPreviousTextDeleteRange(state.doc, $pos.pos, runContentStart);
const deleteRange = findPreviousTextDeleteRange(state.doc, $pos.pos);
if (!deleteRange) return false;

tr.delete(deleteRange.from, deleteRange.to).setSelection(Selection.near(tr.doc.resolve(deleteRange.from)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

const ok = backspaceNextToRun()({ state, tr, dispatch: (t) => (dispatched = t) });

expect(ok).toBe(true);

Check failure on line 49 in packages/super-editor/src/core/commands/backspaceNextToRun.test.js

View workflow job for this annotation

GitHub Actions / validate

src/core/commands/backspaceNextToRun.test.js > backspaceNextToRun > deletes the last character of the run immediately before the cursor

AssertionError: expected false to be true // Object.is equality - Expected + Received - true + false ❯ src/core/commands/backspaceNextToRun.test.js:49:16

Check failure on line 49 in packages/super-editor/src/core/commands/backspaceNextToRun.test.js

View workflow job for this annotation

GitHub Actions / validate

src/core/commands/backspaceNextToRun.test.js > backspaceNextToRun > deletes the last character of the run immediately before the cursor

AssertionError: expected false to be true // Object.is equality - Expected + Received - true + false ❯ src/core/commands/backspaceNextToRun.test.js:49:16

Check failure on line 49 in packages/super-editor/src/core/commands/backspaceNextToRun.test.js

View workflow job for this annotation

GitHub Actions / validate

src/core/commands/backspaceNextToRun.test.js > backspaceNextToRun > deletes the last character of the run immediately before the cursor

AssertionError: expected false to be true // Object.is equality - Expected + Received - true + false ❯ src/core/commands/backspaceNextToRun.test.js:49:16
expect(dispatched).toBeDefined();
expect(dispatched.doc.textContent).toBe('BC');
// Selection is moved near the deleted position
Expand Down Expand Up @@ -99,7 +99,7 @@
let dispatched;
const ok = backspaceNextToRun()({ state, tr: state.tr, dispatch: (t) => (dispatched = t) });

expect(ok).toBe(true);

Check failure on line 102 in packages/super-editor/src/core/commands/backspaceNextToRun.test.js

View workflow job for this annotation

GitHub Actions / validate

src/core/commands/backspaceNextToRun.test.js > backspaceNextToRun > skips non-text inline nodes and deletes the previous text character

AssertionError: expected false to be true // Object.is equality - Expected + Received - true + false ❯ src/core/commands/backspaceNextToRun.test.js:102:16

Check failure on line 102 in packages/super-editor/src/core/commands/backspaceNextToRun.test.js

View workflow job for this annotation

GitHub Actions / validate

src/core/commands/backspaceNextToRun.test.js > backspaceNextToRun > skips non-text inline nodes and deletes the previous text character

AssertionError: expected false to be true // Object.is equality - Expected + Received - true + false ❯ src/core/commands/backspaceNextToRun.test.js:102:16

Check failure on line 102 in packages/super-editor/src/core/commands/backspaceNextToRun.test.js

View workflow job for this annotation

GitHub Actions / validate

src/core/commands/backspaceNextToRun.test.js > backspaceNextToRun > skips non-text inline nodes and deletes the previous text character

AssertionError: expected false to be true // Object.is equality - Expected + Received - true + false ❯ src/core/commands/backspaceNextToRun.test.js:102:16
expect(dispatched).toBeDefined();
// Should remove "A", not the bookmark node.
expect(dispatched.doc.textContent).toBe('.');
Expand All @@ -109,27 +109,4 @@
});
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.

expect(bookmarkCount).toBe(1);
});

it('does not scan into previous paragraphs when adjacent run has only non-text inline content', () => {
const schema = makeSchema();
const doc = schema.node('doc', null, [
schema.node('paragraph', null, [schema.node('run', null, schema.text('A'))]),
schema.node('paragraph', null, [
schema.node('run', null, [schema.node('bookmarkEnd')]),
schema.node('run', null, schema.text('B')),
]),
]);

const boundary = posBetweenRuns(doc, '');
expect(boundary).not.toBeNull();

const state = EditorState.create({ schema, doc, selection: TextSelection.create(doc, boundary ?? 1) });
const dispatch = vi.fn();

const ok = backspaceNextToRun()({ state, tr: state.tr, dispatch });

expect(ok).toBe(false);
expect(dispatch).not.toHaveBeenCalled();
expect(state.doc.textContent).toBe('AB');
});
});
Loading