Add `drawSelection()` (#917)
parent
5c28b1a73f
commit
c412bed98e
|
@ -19,15 +19,14 @@ import {
|
||||||
LanguageSupport,
|
LanguageSupport,
|
||||||
syntaxHighlighting,
|
syntaxHighlighting,
|
||||||
} from "@codemirror/language";
|
} from "@codemirror/language";
|
||||||
import { EditorSelection, EditorState } from "@codemirror/state";
|
import { EditorState } from "@codemirror/state";
|
||||||
import {
|
import {
|
||||||
|
drawSelection,
|
||||||
dropCursor,
|
dropCursor,
|
||||||
EditorView,
|
EditorView,
|
||||||
highlightSpecialChars,
|
highlightSpecialChars,
|
||||||
KeyBinding,
|
KeyBinding,
|
||||||
keymap,
|
keymap,
|
||||||
layer,
|
|
||||||
RectangleMarker,
|
|
||||||
ViewPlugin,
|
ViewPlugin,
|
||||||
ViewUpdate,
|
ViewUpdate,
|
||||||
} from "@codemirror/view";
|
} from "@codemirror/view";
|
||||||
|
@ -124,46 +123,7 @@ export function createEditorState(
|
||||||
...cleanModePlugins(client),
|
...cleanModePlugins(client),
|
||||||
EditorView.lineWrapping,
|
EditorView.lineWrapping,
|
||||||
plugLinter(client),
|
plugLinter(client),
|
||||||
// Taken from https://github.com/codemirror/view/blob/main/src/draw-selection.ts
|
drawSelection(),
|
||||||
layer({
|
|
||||||
above: true,
|
|
||||||
markers(view) {
|
|
||||||
const safari = /Apple Computer/.test(navigator.vendor);
|
|
||||||
const ios = safari &&
|
|
||||||
(/Mobile\/\w+/.test(navigator.userAgent) ||
|
|
||||||
navigator.maxTouchPoints > 2);
|
|
||||||
|
|
||||||
const { state } = view;
|
|
||||||
const cursors = [];
|
|
||||||
for (const r of state.selection.ranges) {
|
|
||||||
const prim = r == state.selection.main;
|
|
||||||
if (!r.empty || !prim || !ios) {
|
|
||||||
const className = prim
|
|
||||||
? "cm-cursor cm-cursor-primary"
|
|
||||||
: "cm-cursor cm-cursor-secondary";
|
|
||||||
const cursor = r.empty
|
|
||||||
? r
|
|
||||||
: EditorSelection.cursor(r.head, r.head > r.anchor ? -1 : 1);
|
|
||||||
for (
|
|
||||||
const piece of RectangleMarker.forRange(view, className, cursor)
|
|
||||||
) cursors.push(piece);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cursors;
|
|
||||||
},
|
|
||||||
update(update, dom) {
|
|
||||||
if (update.transactions.some((tr) => tr.selection)) {
|
|
||||||
dom.style.animationName = dom.style.animationName == "cm-blink"
|
|
||||||
? "cm-blink2"
|
|
||||||
: "cm-blink";
|
|
||||||
}
|
|
||||||
return update.docChanged || update.selectionSet;
|
|
||||||
},
|
|
||||||
mount(dom) {
|
|
||||||
dom.style.animationDuration = "1200ms";
|
|
||||||
},
|
|
||||||
class: "cm-cursorLayer",
|
|
||||||
}),
|
|
||||||
postScriptPrefacePlugin(client),
|
postScriptPrefacePlugin(client),
|
||||||
lineWrapper([
|
lineWrapper([
|
||||||
{ selector: "ATXHeading1", class: "sb-line-h1" },
|
{ selector: "ATXHeading1", class: "sb-line-h1" },
|
||||||
|
|
|
@ -175,10 +175,9 @@
|
||||||
#sb-editor {
|
#sb-editor {
|
||||||
.cm-content {
|
.cm-content {
|
||||||
font-family: var(--editor-font);
|
font-family: var(--editor-font);
|
||||||
caret-color: transparent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
::selection {
|
.cm-selectionBackground {
|
||||||
background-color: var(--editor-selection-background-color);
|
background-color: var(--editor-selection-background-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -401,10 +401,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.sb-line-code-outside .sb-code-info {
|
.sb-line-code-outside .sb-code-info {
|
||||||
&::selection {
|
|
||||||
background-color: transparent;
|
|
||||||
}
|
|
||||||
|
|
||||||
display: block;
|
display: block;
|
||||||
float: right;
|
float: right;
|
||||||
font-size: 90%;
|
font-size: 90%;
|
||||||
|
@ -412,10 +408,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.sb-code-copy-button {
|
.sb-code-copy-button {
|
||||||
&::selection {
|
|
||||||
background-color: transparent;
|
|
||||||
}
|
|
||||||
|
|
||||||
float: right;
|
float: right;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
margin: 0 3px;
|
margin: 0 3px;
|
||||||
|
|
Loading…
Reference in New Issue