Skip to content

Commit cf9ed24

Browse files
Clip selection highlight to content area and fix focus-click drag
Selection layer now uses clip-path to prevent the highlight from extending into the editor's horizontal padding. The mousedown handler no longer prevents default on focus-clicks or padding-clicks, so CM's native drag tracking works on the first click into the editor.
1 parent f1545ff commit cf9ed24

2 files changed

Lines changed: 10 additions & 56 deletions

File tree

app/src/features/editor/lib/note-editor-config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ export const MARKDOWN_EDITOR_THEME = EditorView.theme({
9595
".cm-selectionLayer": {
9696
zIndex: "1 !important",
9797
pointerEvents: "none",
98+
// Override baseTheme's `contain: size style` so the layer can be
99+
// stretched by the bottom/right offsets, giving clip-path a real
100+
// reference box to clip selection backgrounds out of the padding.
101+
contain: "style",
102+
bottom: "0",
103+
right: "0",
104+
clipPath:
105+
"inset(0 max(clamp(1rem, 5vw, 3.5rem), calc((100% - 42rem) / 2)))",
98106
},
99107
".cm-cursorLayer": {
100108
zIndex: "2 !important",

app/src/features/editor/note-editor.tsx

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ import { ensureNoteEditorVimNavigation } from "@/features/editor/lib/note-editor
5959
import { EditorToolbar } from "@/features/editor/ui/editor-toolbar";
6060
import { HighlightSyntax } from "@/features/editor/extensions/markdown-decorations";
6161
import { getInlineSyntaxRightBoundaryAtCursor } from "@/features/editor/extensions/markdown-decorations/builders/inline-boundaries";
62-
import { getSnappedCursorPosition } from "@/features/editor/extensions/markdown-decorations/snap-cursor";
6362
import {
6463
TagGrammar,
6564
tagHighlightStyle,
@@ -254,11 +253,7 @@ function dispatchPointerCursorSelection(view: EditorView, pos: number) {
254253
});
255254
}
256255

257-
function handleSpecialMouseDownSelection(
258-
view: EditorView,
259-
event: MouseEvent,
260-
leadingPaddingLineStart: number | null,
261-
) {
256+
function handleSpecialMouseDownSelection(view: EditorView, event: MouseEvent) {
262257
if (trySnapInlineSyntaxRightBoundaryClick(view, event)) {
263258
return true;
264259
}
@@ -296,17 +291,6 @@ function handleSpecialMouseDownSelection(
296291
return true;
297292
}
298293

299-
if (leadingPaddingLineStart != null) {
300-
event.preventDefault();
301-
event.stopPropagation();
302-
303-
if (!view.hasFocus) {
304-
focusEditorPreservingScroll(view);
305-
}
306-
307-
return true;
308-
}
309-
310294
return false;
311295
}
312296

@@ -445,52 +429,14 @@ export const NoteEditor = forwardRef<NoteEditorHandle, NoteEditorProps>(
445429
search(),
446430
EditorView.domEventHandlers({
447431
mousedown(event, view) {
448-
const leadingPaddingLineStart = getLeadingPaddingClickLineStart(
449-
view,
450-
event,
451-
);
452-
453-
if (
454-
handleSpecialMouseDownSelection(
455-
view,
456-
event,
457-
leadingPaddingLineStart,
458-
)
459-
) {
432+
if (handleSpecialMouseDownSelection(view, event)) {
460433
return true;
461434
}
462435

463436
event.stopPropagation();
464-
const directPos = view.posAtCoords(
465-
{
466-
x: event.clientX,
467-
y: event.clientY,
468-
},
469-
false,
470-
);
471437

472438
if (!view.hasFocus) {
473-
event.preventDefault();
474-
475-
const clickedInsideTable =
476-
event.target instanceof HTMLElement &&
477-
event.target.closest(".cm-md-table-wrapper");
478-
479439
focusEditorPreservingScroll(view);
480-
481-
if (clickedInsideTable) {
482-
return false;
483-
}
484-
485-
if (directPos != null) {
486-
const snappedPos =
487-
getSnappedCursorPosition(view.state, directPos) ??
488-
directPos;
489-
490-
dispatchPointerCursorSelection(view, snappedPos);
491-
}
492-
493-
return true;
494440
}
495441

496442
return false;

0 commit comments

Comments
 (0)