|
1 | 1 | import {EditorSelection, Extension, Facet, combineConfig, Prec, EditorState} from "@codemirror/state" |
2 | | -import {StyleSpec} from "style-mod" |
3 | 2 | import {ViewUpdate, nativeSelectionHidden} from "./extension" |
4 | 3 | import {EditorView} from "./editorview" |
5 | 4 | import {layer, RectangleMarker} from "./layer" |
6 | | -import browser from "./browser" |
7 | | - |
8 | | -const CanHidePrimary = !(browser.ios && browser.webkit && browser.webkit_version < 534) |
9 | 5 |
|
10 | 6 | type SelectionConfig = { |
11 | 7 | /// The length of a full cursor blink cycle, in milliseconds. |
@@ -72,7 +68,7 @@ const cursorLayer = layer({ |
72 | 68 | let cursors = [] |
73 | 69 | for (let r of state.selection.ranges) { |
74 | 70 | let prim = r == state.selection.main |
75 | | - if (r.empty ? !prim || CanHidePrimary : conf.drawRangeCursor) { |
| 71 | + if (r.empty || conf.drawRangeCursor) { |
76 | 72 | let className = prim ? "cm-cursor cm-cursor-primary" : "cm-cursor cm-cursor-secondary" |
77 | 73 | let cursor = r.empty ? r : EditorSelection.cursor(r.head, r.head > r.anchor ? -1 : 1) |
78 | 74 | for (let piece of RectangleMarker.forRange(view, className, cursor)) cursors.push(piece) |
@@ -109,19 +105,18 @@ const selectionLayer = layer({ |
109 | 105 | class: "cm-selectionLayer" |
110 | 106 | }) |
111 | 107 |
|
112 | | -const themeSpec: {[selector: string]: StyleSpec} = { |
| 108 | +const hideNativeSelection = Prec.highest(EditorView.theme({ |
113 | 109 | ".cm-line": { |
114 | 110 | "& ::selection, &::selection": {backgroundColor: "transparent !important"}, |
| 111 | + caretColor: "transparent !important" |
115 | 112 | }, |
116 | 113 | ".cm-content": { |
| 114 | + caretColor: "transparent !important", |
117 | 115 | "& :focus": { |
118 | 116 | caretColor: "initial !important", |
119 | 117 | "&::selection, & ::selection": { |
120 | 118 | backgroundColor: "Highlight !important" |
121 | 119 | } |
122 | 120 | } |
123 | 121 | } |
124 | | -} |
125 | | -if (CanHidePrimary) |
126 | | - themeSpec[".cm-line"].caretColor = themeSpec[".cm-content"].caretColor = "transparent !important" |
127 | | -const hideNativeSelection = Prec.highest(EditorView.theme(themeSpec)) |
| 122 | +})) |
0 commit comments