Live editor: link clicks land right, tidy variable results

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
sarahandClaude Opus 5.5 committed 2026-10-13 18:30:26 +02:00
1 parent f3287b207e
commit 76e6786af5
2 files changed
+27 -5

No files matched your search

+13 -5
View File
@@ -311,6 +311,10 @@ function BuildDecorations(View) {
return;
}
if (Name === "URL" && ParentName !== "Link" && ParentName !== "Image" && Node.to > Node.from) {
Ranges.push(Decoration.mark({ class: "cm-LiveLink" }).range(Node.from, Node.to));
}
if (InlineClasses[Name] && Node.to > Node.from) {
Ranges.push(Decoration.mark({ class: InlineClasses[Name] }).range(Node.from, Node.to));
}
@@ -434,7 +438,7 @@ function BuildProperties(State) {
if (CursorIn(State, 0, To)) return Decoration.none;
const Parsed = ParseProperties(State.doc.sliceString(0, To));
if (!Parsed || Parsed.Properties.length === 0) return Decoration.none;
const Html = PropertiesHtml(Parsed, EscapeHtml, EscapeHtml, true);
const Html = PropertiesHtml(Parsed, (Value) => VariableRenderer.renderInline(Value), EscapeHtml, true);
return Decoration.set([Decoration.replace({ widget: new PropertiesWidget(Html), block: true }).range(0, To)]);
}
@@ -561,7 +565,7 @@ function ToEditorOffsets(Text, Found) {
}
// Asks the server for the spans when the note opens, and again once typing
// pauses; an answer for text that's changed since is dropped.
// pauses (0.3 s); an answer for text that's changed since is dropped.
function FetchVariables(RootName, FilePath) {
return ViewPlugin.fromClass(
class {
@@ -572,7 +576,7 @@ function FetchVariables(RootName, FilePath) {
}
update(Update) {
if (Update.docChanged) this.Request(500);
if (Update.docChanged) this.Request(300);
}
Request(Delay) {
@@ -616,11 +620,15 @@ function LinkAt(State, Position) {
return null;
}
// Where in the text the clicked link is comes from its element (posAtDOM),
// not the mouse position: the editor maps coordinates through estimated line
// heights, which a tall widget above (the properties panel) throws off.
const ClickLinks = EditorView.domEventHandlers({
mousedown(Event, View) {
if (Event.button !== 0) return false;
const Position = View.posAtCoords({ x: Event.clientX, y: Event.clientY });
if (Position === null) return false;
const Mark = Event.target.closest(".cm-LiveLink");
if (!Mark || !View.contentDOM.contains(Mark)) return false;
const Position = View.posAtDOM(Mark, 0);
const Link = LinkAt(View.state, Position);
if (!Link) return false;
const Editing =