From 1b9605daf6ad5284055b5d2cd60ff6aedf7b48d2 Mon Sep 17 00:00:00 2001 From: Ethan Graf Date: Tue, 21 Jul 2026 21:13:47 -0400 Subject: [PATCH] Reveal raw --- (no rule) when cursor is on the HR line MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The cm-hr line decoration that draws the rule was applied unconditionally, so placing the cursor on a horizontal rule showed both the rule and the raw "---". Only style the line (and hide its glyphs) when the cursor is on a different line; on the rule's own line, emit nothing so the raw "---" shows for editing — matching how headings/blockquotes reveal their markers. Co-Authored-By: Claude Opus 4.8 --- src/editors/automerge/livePreview/hrDecoration.ts | 8 +++++--- src/editors/automerge/livePreview/livePreview.test.ts | 7 +++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/editors/automerge/livePreview/hrDecoration.ts b/src/editors/automerge/livePreview/hrDecoration.ts index dca4157..32633dd 100644 --- a/src/editors/automerge/livePreview/hrDecoration.ts +++ b/src/editors/automerge/livePreview/hrDecoration.ts @@ -37,10 +37,12 @@ export function buildHrDecorations( enter(node) { if (node.name !== 'HorizontalRule') return; const line = state.doc.lineAt(node.from); + // When the cursor is on the rule's line, show the raw `---` and draw + // no rule at all — so editing the line is unambiguous. Off the line, + // apply the line style and hide the glyphs so the rule alone shows. + if (line.number === cursorLine) return; decos.push({ from: line.from, to: line.from, deco: hrLine }); - // Hide the whole line's text (including any leading whitespace) so - // the border alone reads as the rule. - if (line.number !== cursorLine && line.to > line.from) { + if (line.to > line.from) { decos.push({ from: line.from, to: line.to, deco: hrLineHiddenMark }); } }, diff --git a/src/editors/automerge/livePreview/livePreview.test.ts b/src/editors/automerge/livePreview/livePreview.test.ts index 0cf45e2..643e651 100644 --- a/src/editors/automerge/livePreview/livePreview.test.ts +++ b/src/editors/automerge/livePreview/livePreview.test.ts @@ -251,6 +251,13 @@ describe('hrDecoration', () => { expect(hidden).toHaveLength(1); expect(hidden[0].text).toBe('---'); }); + + it('shows raw --- with no rule when the cursor is on the line', () => { + const state = makeState('para\n\n---\n\nmore', 7); // on the "---" line + const list = decos(state, buildHrDecorations(state)); + expect(withClass(list, 'cm-hr')).toHaveLength(0); + expect(withClass(list, 'cm-hr-line-hidden')).toHaveLength(0); + }); }); describe('listDecoration', () => { -- 2.51.2