Widget: alt-click to move cursor into widget
parent
413855c180
commit
5765540a3a
|
@ -49,7 +49,7 @@ export class LuaWidget extends WidgetType {
|
|||
if (cacheItem) {
|
||||
div.innerHTML = cacheItem.html;
|
||||
if (cacheItem.html) {
|
||||
attachWidgetEventHandlers(div, this.client);
|
||||
attachWidgetEventHandlers(div, this.client, this.from);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,7 +92,7 @@ export class LuaWidget extends WidgetType {
|
|||
} else {
|
||||
div.style.display = "inline";
|
||||
}
|
||||
attachWidgetEventHandlers(div, this.client);
|
||||
attachWidgetEventHandlers(div, this.client, this.from);
|
||||
this.client.setWidgetCache(
|
||||
this.cacheKey,
|
||||
{ height: div.clientHeight, html },
|
||||
|
@ -157,7 +157,7 @@ export class LuaWidget extends WidgetType {
|
|||
}
|
||||
div.innerHTML = html;
|
||||
if (html) {
|
||||
attachWidgetEventHandlers(div, this.client);
|
||||
attachWidgetEventHandlers(div, this.client, this.from);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -187,7 +187,8 @@ export class LuaWidget extends WidgetType {
|
|||
override eq(other: WidgetType): boolean {
|
||||
return (
|
||||
other instanceof LuaWidget &&
|
||||
other.bodyText === this.bodyText && other.cacheKey === this.cacheKey
|
||||
other.bodyText === this.bodyText && other.cacheKey === this.cacheKey &&
|
||||
this.from === other.from
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -181,7 +181,7 @@ export class MarkdownWidget extends WidgetType {
|
|||
}
|
||||
|
||||
private attachListeners(div: HTMLElement, buttons?: CodeWidgetButton[]) {
|
||||
attachWidgetEventHandlers(div, this.client);
|
||||
attachWidgetEventHandlers(div, this.client, this.from);
|
||||
|
||||
if (!buttons) {
|
||||
buttons = [];
|
||||
|
@ -225,7 +225,8 @@ export class MarkdownWidget extends WidgetType {
|
|||
override eq(other: WidgetType): boolean {
|
||||
return (
|
||||
other instanceof MarkdownWidget &&
|
||||
other.bodyText === this.bodyText && other.cacheKey === this.cacheKey
|
||||
other.bodyText === this.bodyText && other.cacheKey === this.cacheKey &&
|
||||
this.from === other.from
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,8 +2,18 @@ import { parsePageRef } from "@silverbulletmd/silverbullet/lib/page_ref";
|
|||
import type { Client } from "../client.ts";
|
||||
import { tagPrefix } from "../../plugs/index/constants.ts";
|
||||
|
||||
export function attachWidgetEventHandlers(div: HTMLElement, client: Client) {
|
||||
export function attachWidgetEventHandlers(
|
||||
div: HTMLElement,
|
||||
client: Client,
|
||||
pos?: number,
|
||||
) {
|
||||
div.addEventListener("mousedown", (e) => {
|
||||
if (e.altKey) {
|
||||
// Move cursor there
|
||||
client.editorView.dispatch({ selection: { anchor: pos! } });
|
||||
client.editorView.focus();
|
||||
e.preventDefault();
|
||||
}
|
||||
// CodeMirror overrides mousedown on parent elements to implement its own selection highlighting.
|
||||
// That's nice, but not for markdown widgets, so let's not propagate the event to CodeMirror here.
|
||||
e.stopPropagation();
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
> **warning** Warning
|
||||
> **warning** Experimental
|
||||
> This is a **highly experimental** feature still under active development. It is documented here primarily for the real early adopters as this feature develops.
|
||||
|
||||
Space Lua is a custom implementation of the [Lua programming language](https://lua.org/) embedded in SilverBullet.
|
||||
|
@ -25,7 +25,7 @@ Each `space-lua` block has its own local scope, however when functions and varia
|
|||
|
||||
A new syntax introduced with Space Lua is the `${lua expression}` syntax that you can use in your pages, this syntax will [[Live Preview]] to the evaluation of that expression.
|
||||
|
||||
Example: 10 + 2 = ${adder(10, 2)} (move into this value to see the expression using the just defined `adder` function to calculate this).
|
||||
Example: 10 + 2 = ${adder(10, 2)} (Alt-click on this value to see the expression using the just defined `adder` function to calculate this).
|
||||
|
||||
## Widgets
|
||||
The `${lua expression}` syntax can be used to implement simple widgets. If the lua expression evaluates to a simple string, it will live preview as that string rendered as simple markdown. However, if the expression returns a Lua table with specific keys, you can do some cooler stuff. The following keys are supported:
|
||||
|
|
Loading…
Reference in New Issue