-
-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Panagiotis Georgakopoulos <panagiotis.georgakopoulos@juliacomputing.com> Co-authored-by: Paul <paul@plutojl.org> Co-authored-by: Michiel Dral <m.c.dral@gmail.com>
- Loading branch information
1 parent
ffb38d2
commit 665d99a
Showing
21 changed files
with
2,276 additions
and
247 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { Decoration, ViewPlugin, EditorView, Facet } from "../../imports/CodemirrorPlutoSetup.js" | ||
|
||
const highlighted_line = Decoration.line({ | ||
attributes: { class: "cm-highlighted-line" }, | ||
}) | ||
|
||
/** | ||
* @param {EditorView} view | ||
*/ | ||
function create_line_decorations(view) { | ||
let line_number = view.state.facet(HighlightLineFacet) | ||
if (line_number == null || line_number == undefined || line_number > view.state.doc.lines) { | ||
return Decoration.set([]) | ||
} | ||
|
||
let line = view.state.doc.line(line_number) | ||
return Decoration.set([highlighted_line.range(line.from, line.from)]) | ||
} | ||
|
||
/** | ||
* @type Facet<number?, number?> | ||
*/ | ||
export const HighlightLineFacet = Facet.define({ | ||
combine: (values) => values[0], | ||
compare: (a, b) => a === b, | ||
}) | ||
|
||
export const highlightLinePlugin = () => | ||
ViewPlugin.fromClass( | ||
class { | ||
updateDecos(view) { | ||
this.decorations = create_line_decorations(view) | ||
} | ||
|
||
/** | ||
* @param {EditorView} view | ||
*/ | ||
constructor(view) { | ||
this.updateDecos(view) | ||
} | ||
|
||
/** | ||
* @param {ViewUpdate} update | ||
*/ | ||
update(update) { | ||
if (update.docChanged || update.state.facet(HighlightLineFacet) !== update.startState.facet(HighlightLineFacet)) { | ||
this.updateDecos(update.view) | ||
} | ||
} | ||
}, | ||
{ | ||
decorations: (v) => v.decorations, | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.