Fixes #133
parent
a0670768e8
commit
477f021644
|
@ -40,15 +40,37 @@ export function cleanWikiLinkPlugin(editor: Editor) {
|
|||
if (type.name !== "WikiLink") {
|
||||
return;
|
||||
}
|
||||
if (isCursorInRange(view.state, [from, to])) {
|
||||
return;
|
||||
}
|
||||
|
||||
const text = view.state.sliceDoc(from, to);
|
||||
const match = pageLinkRegex.exec(text);
|
||||
if (!match) return;
|
||||
const [_fullMatch, page, pipePart, alias] = match;
|
||||
|
||||
const allPages = editor.space.listPages();
|
||||
let pageExists = false;
|
||||
let cleanPage = page;
|
||||
if (page.includes("@")) {
|
||||
cleanPage = page.split("@")[0];
|
||||
}
|
||||
for (const pageMeta of allPages) {
|
||||
if (pageMeta.name === cleanPage) {
|
||||
pageExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isCursorInRange(view.state, [from, to])) {
|
||||
// Only attach a CSS class, then get out
|
||||
if (!pageExists) {
|
||||
widgets.push(
|
||||
Decoration.mark({
|
||||
class: "sb-wiki-link-page-missing",
|
||||
}).range(from + 2, from + page.length + 2),
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Hide the whole thing
|
||||
widgets.push(
|
||||
invisibleDecoration.range(
|
||||
|
@ -68,8 +90,10 @@ export function cleanWikiLinkPlugin(editor: Editor) {
|
|||
Decoration.widget({
|
||||
widget: new LinkWidget(
|
||||
linkText,
|
||||
page,
|
||||
"sb-wiki-link-page",
|
||||
pageExists ? `Navigate to ${page}` : `Create ${page}`,
|
||||
pageExists
|
||||
? "sb-wiki-link-page"
|
||||
: "sb-wiki-link-page-missing",
|
||||
(e) => {
|
||||
if (e.altKey) {
|
||||
// Move cursor into the link
|
||||
|
|
|
@ -348,6 +348,15 @@
|
|||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
.sb-wiki-link-page-missing, .sb-wiki-link-page-missing > .sb-wiki-link-page {
|
||||
color: #9e4705;
|
||||
background-color: rgba(77, 141, 255, 0.07);
|
||||
border-radius: 5px;
|
||||
padding: 0 5px;
|
||||
white-space: nowrap;
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.sb-wiki-link {
|
||||
cursor: pointer;
|
||||
|
|
|
@ -7,6 +7,7 @@ release.
|
|||
|
||||
* New page link aliasing syntax (Obsidian compatible) is here: `[[page link|alias]]` e.g. [[CHANGELOG|this is a link to this changelog]]. Also supported for command links: `{[Plugs: Add|add a plug]}`
|
||||
* Less "floppy" behavior when clicking links (regular, wiki and command): just navigates there right away. Note: use `Alt-click` to move the cursor inside of a link.
|
||||
* Page reference to non-existing pages are now higlighted in a (red-ish) color
|
||||
* Added `invokeFunction` `silverbullet` CLI sub-command to run arbitrary plug functions from the CLI.
|
||||
|
||||
---
|
||||
|
|
Loading…
Reference in New Issue