@marianmeres/stuic 3.138.0 → 3.139.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -12,7 +12,7 @@ import { defaultKeymap, history, historyKeymap, redo, undo } from "@codemirror/c
|
|
|
12
12
|
import { markdown } from "@codemirror/lang-markdown";
|
|
13
13
|
import { languages } from "@codemirror/language-data";
|
|
14
14
|
import { EditorState } from "@codemirror/state";
|
|
15
|
-
import { EditorView, keymap, placeholder as cmPlaceholder } from "@codemirror/view";
|
|
15
|
+
import { drawSelection, EditorView, keymap, placeholder as cmPlaceholder, } from "@codemirror/view";
|
|
16
16
|
/** Theme that inherits STUIC look via CSS vars rather than hard-coded values. */
|
|
17
17
|
const stuicTheme = EditorView.theme({
|
|
18
18
|
"&": {
|
|
@@ -23,7 +23,6 @@ const stuicTheme = EditorView.theme({
|
|
|
23
23
|
".cm-content": {
|
|
24
24
|
fontFamily: "var(--stuic-markdown-editor-font-mono, ui-monospace, SFMono-Regular, Menlo, monospace)",
|
|
25
25
|
padding: "0",
|
|
26
|
-
caretColor: "currentColor",
|
|
27
26
|
},
|
|
28
27
|
"&.cm-focused": { outline: "none" },
|
|
29
28
|
".cm-line": { padding: "0" },
|
|
@@ -33,6 +32,30 @@ const stuicTheme = EditorView.theme({
|
|
|
33
32
|
color: "var(--stuic-input-placeholder, currentColor)",
|
|
34
33
|
opacity: "0.5",
|
|
35
34
|
},
|
|
35
|
+
// Caret + selection are DRAWN by `drawSelection()` (see the extensions below)
|
|
36
|
+
// instead of left to the browser. The native caret is unreliable on an EMPTY
|
|
37
|
+
// document that carries a placeholder widget — Chrome/Safari won't render it
|
|
38
|
+
// (the cursor sits before a `contenteditable=false` widget with no editable
|
|
39
|
+
// text beside it) until you start typing, which reads as a broken focus.
|
|
40
|
+
// Drawing the caret ourselves fixes that. Colors use `currentColor` / a
|
|
41
|
+
// mode-neutral translucent selection on purpose: CM's own light/dark detection
|
|
42
|
+
// is inert here (STUIC themes via `:root.dark`, not CM's dark facet), so its
|
|
43
|
+
// built-in dark caret/selection colors would never kick in.
|
|
44
|
+
//
|
|
45
|
+
// `borderLeftWidth: 2px` is deliberate: CM's default ~1.2px caret lands on a
|
|
46
|
+
// fractional device-pixel boundary at many layout offsets (the cursor also
|
|
47
|
+
// carries a `-0.6px` margin) and anti-aliases into invisibility on a light
|
|
48
|
+
// background — the very "no caret" symptom this fix targets. 2px always paints.
|
|
49
|
+
".cm-cursor, .cm-dropCursor": {
|
|
50
|
+
borderLeftColor: "currentColor",
|
|
51
|
+
borderLeftWidth: "2px",
|
|
52
|
+
},
|
|
53
|
+
"& .cm-selectionBackground": {
|
|
54
|
+
background: "var(--stuic-markdown-editor-selection-bg, rgb(128 128 128 / 0.3))",
|
|
55
|
+
},
|
|
56
|
+
"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground": {
|
|
57
|
+
background: "var(--stuic-markdown-editor-selection-bg, rgb(128 128 128 / 0.3))",
|
|
58
|
+
},
|
|
36
59
|
});
|
|
37
60
|
/** Wrap the current selection with `before`/`after` markers (e.g. `**bold**`). */
|
|
38
61
|
function wrapSelection(view, before, after = before) {
|
|
@@ -162,6 +185,7 @@ export function mountCodeMirror(host, opts) {
|
|
|
162
185
|
keymap.of([...defaultKeymap, ...historyKeymap]),
|
|
163
186
|
markdown({ codeLanguages: languages }),
|
|
164
187
|
EditorView.lineWrapping,
|
|
188
|
+
drawSelection(),
|
|
165
189
|
EditorView.editable.of(!opts.disabled),
|
|
166
190
|
EditorState.readOnly.of(!!opts.disabled),
|
|
167
191
|
...(opts.placeholder ? [cmPlaceholder(opts.placeholder)] : []),
|