Skip to content

Commit 42ea6ff

Browse files
fix(web): let arrows move when stored marks match neither edge stop
Marks the user toggled at a styled edge are kept, and the arrow key moves the caret as usual instead of resetting them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent aa39b76 commit 42ea6ff

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

‎apps/web/src/composer-rich-text-doc.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,15 @@ describe("caret stops at styled edges", () => {
440440
expect(stepCaretAcrossStyledEdge(outside, 1)).toBeNull();
441441
});
442442

443+
it("keeps marks the user toggled at an edge and lets the arrow move", () => {
444+
const inside = stateAt("a **b** c", 3);
445+
const toggled = inside.apply(
446+
inside.tr.setStoredMarks([schema.marks.bold!.create(), schema.marks.italic!.create()]),
447+
);
448+
expect(stepCaretAcrossStyledEdge(toggled, 1)).toBeNull();
449+
expect(stepCaretAcrossStyledEdge(toggled, -1)).toBeNull();
450+
});
451+
443452
it("leaves arrow keys alone away from styled edges", () => {
444453
expect(stepCaretAcrossStyledEdge(stateAt("**bold** tail", 3), -1)).toBeNull();
445454
expect(stepCaretAcrossStyledEdge(stateAt("plain text", 1), -1)).toBeNull();

‎apps/web/src/composer-rich-text-doc.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,10 @@ export function stepCaretAcrossStyledEdge(
694694
): Transaction | null {
695695
const edge = styledEdge(state);
696696
if (!edge) return null;
697+
// Marks the user toggled by hand (neither stop) are theirs: move as usual.
698+
if (!Mark.sameSet(edge.current, edge.before) && !Mark.sameSet(edge.current, edge.after)) {
699+
return null;
700+
}
697701
const target = direction === -1 ? edge.before : edge.after;
698702
if (Mark.sameSet(edge.current, target)) return null;
699703
return state.tr.setStoredMarks(target);

0 commit comments

Comments
 (0)