Compare commits

...

1 Commits

Author SHA1 Message Date
Felix Roos 2375a7c1a2 almost working custom background layer behind selection 2024-01-07 00:09:30 +01:00
4 changed files with 46 additions and 3 deletions
+38
View File
@@ -0,0 +1,38 @@
// import { SelectionRange } from '@codemirror/state';
import { RectangleMarker } from '@codemirror/view';
import { layer } from '@codemirror/view';
// currently stuck with: https://discuss.codemirror.net/t/line-background-layer/7666
export const backlayer = layer({
update: (update) => {
return update.docChanged;
},
markers: (view) => {
const offsetTop = 14; // how to know this number ? .view.documentTop is scroll relative..
const offsetLeft = 4; // how to know this number ?
return view.viewportLineBlocks.map((block) => {
const { left } = view.coordsAtPos(block.to);
return new RectangleMarker('cm-backlayer', offsetLeft, block.top + offsetTop, left, block.height);
});
},
});
/* const len = view.state.doc.length;
const markers = RectangleMarker.forRange(
view,
'cm-backlayer',
SelectionRange.fromJSON({
from: 0,
to: len,
anchor: 0,
head: len,
empty: true,
assoc: -1,
bidiLevel: null,
}),
);
console.log('markser', markers);
return markers;
*/
+2
View File
@@ -21,6 +21,7 @@ import { keybindings } from './keybindings.mjs';
import { initTheme, activateTheme, theme } from './themes.mjs';
import { updateWidgets, sliderPlugin } from './slider.mjs';
import { persistentAtom } from '@nanostores/persistent';
import { backlayer } from './backlayer.mjs';
const extensions = {
isLineWrappingEnabled: (on) => (on ? EditorView.lineWrapping : []),
@@ -76,6 +77,7 @@ export function initEditor({ initialCode = '', onChange, onEvaluate, onStop, roo
history(),
EditorView.updateListener.of((v) => onChange(v)),
drawSelection({ cursorBlinkRate: 0 }),
backlayer,
Prec.highest(
keymap.of([
{
+1
View File
@@ -3,3 +3,4 @@ export * from './highlight.mjs';
export * from './flash.mjs';
export * from './slider.mjs';
export * from './themes.mjs';
export * from './backlayer.mjs';
+5 -3
View File
@@ -10,6 +10,11 @@
--gutterForeground: #8a919966;
}
.cm-backlayer {
background: #00ff0050;
/* background: var(--lineBackground) */
}
.darken::before {
content: ' ';
position: fixed;
@@ -30,9 +35,6 @@
#code .cm-content {
padding-bottom: 50vh;
}
#code .cm-line > * {
background: var(--lineBackground);
}
#code .cm-editor {
background-color: transparent !important;