Skip to content

Commit 540fa5a

Browse files
committed
Multi line selection
1 parent 6b93628 commit 540fa5a

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

index.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
<body>
1010
<main x-data="app">
1111
<div id="editor" @doc-changed.camel.debounce="calcExpressions"
12-
@selection-changed.camel="getCurrentLine"
12+
@selection-changed.camel="getSelection"
1313
></div>
1414
<article id="output" class="markdown-body">
1515
<template x-for="expression in expressions">
1616
<div class="results"
17-
:class=" (currentLine >= expression.from) && (currentLine <= expression.to) ? 'highligted' : ''"
17+
:class="
18+
((expression.from >= currentLineFrom) && (expression.from <= currentLineTo) ||
19+
(expression.to >= currentLineFrom) && (expression.to <= currentLineTo)) ? 'highligted' : ''"
1820
x-html="expression.outputs" x-show="expression.visible"
1921
x-effect="if((currentLine >= expression.from) && (currentLine <= expression.to)) $el.scrollIntoView({ block: 'nearest', inline: 'start'})">
2022
</div>

main.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,15 @@ Alpine.data(
7575
get calcExpressions() {
7676
this.expressions = makeDoc(editor.state.doc.toString())
7777
},
78-
get getCurrentLine() {
79-
this.currentLine = editor.state.doc.lineAt(
78+
get getSelection() {
79+
this.currentLineFrom = editor.state.doc.lineAt(
8080
editor.state.selection.ranges[editor.state.selection.mainIndex].from
8181
).number - 1
82-
}
82+
this.currentLineTo = editor.state.doc.lineAt(
83+
editor.state.selection.ranges[editor.state.selection.mainIndex].to
84+
).number - 1
85+
},
86+
8387
})
8488
)
8589

0 commit comments

Comments
 (0)