🐛 fix selection offset
This commit is contained in:
@@ -177,7 +177,22 @@ export function MarkdownEditor(): JSX.Element {
|
||||
return (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', height: '100%', position: 'relative' }}>
|
||||
<WordCountBar />
|
||||
<div style={{ flex: 1, overflow: 'hidden', position: 'relative' }}>
|
||||
<div
|
||||
style={{ flex: 1, overflow: 'hidden', position: 'relative' }}
|
||||
onMouseDown={(e) => {
|
||||
const view = viewRef.current
|
||||
if (!view) return
|
||||
const target = e.target as Element
|
||||
// Let clicks directly on text content (inside a line) be handled natively
|
||||
if (target.closest('.cm-line')) return
|
||||
const pos = view.posAtCoords({ x: e.clientX, y: e.clientY }, false)
|
||||
if (pos !== null) {
|
||||
view.dispatch({ selection: { anchor: pos } })
|
||||
view.focus()
|
||||
e.preventDefault()
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div ref={editorRef} style={{ height: '100%' }} />
|
||||
{revisionPanelOpen && activeStoryPath && (
|
||||
<RevisionPanel
|
||||
|
||||
@@ -304,8 +304,8 @@ textarea { resize: vertical; }
|
||||
.cm-editor.cm-focused { outline: none; }
|
||||
.cm-scroller { font-family: 'Georgia', 'Times New Roman', serif; line-height: 1.8; font-size: 16px; transition: font-size 0.4s cubic-bezier(0.4, 0, 0.2, 1); overscroll-behavior: none; }
|
||||
.cm-content { max-width: 680px; margin: 0 auto; padding: 48px 24px 24px; transition: max-width 0.4s cubic-bezier(0.4, 0, 0.2, 1), padding 0.4s cubic-bezier(0.4, 0, 0.2, 1); }
|
||||
.cm-line { padding: 0; margin-bottom: 0.75em; }
|
||||
.cm-line:last-child { margin-bottom: 0; }
|
||||
.cm-line { padding: 0 0 0.75em; margin: 0; }
|
||||
.cm-line:last-child { padding-bottom: 0; }
|
||||
.cm-cursor { border-left-color: var(--accent) !important; }
|
||||
.cm-selectionBackground { background: rgba(200, 169, 110, 0.25) !important; }
|
||||
.cm-focused .cm-selectionBackground { background: rgba(200, 169, 110, 0.35) !important; }
|
||||
|
||||
Reference in New Issue
Block a user