chore: address requested changes

This commit is contained in:
Elian Doran
2026-04-18 12:21:27 +03:00
parent 81a54d8398
commit 4876d4b8c6
5 changed files with 17 additions and 10 deletions

View File

@@ -50,13 +50,10 @@ export default function AddLinkDialog() {
setLinkTitle(title);
}
function resetExternalLink() {
if (linkType === "external-link") {
setLinkType("reference-link");
}
}
useEffect(() => {
const resetExternalLink = () =>
setLinkType((prev) => prev === "external-link" ? "reference-link" : prev);
if (!suggestion) {
resetExternalLink();
setBookmarks([]);
@@ -64,11 +61,14 @@ export default function AddLinkDialog() {
return;
}
let cancelled = false;
if (suggestion.notePath) {
const noteId = tree.getNoteIdFromUrl(suggestion.notePath);
if (noteId) {
setDefaultLinkTitle(noteId);
froca.getNote(noteId).then((note) => {
if (cancelled) return;
const bkms = note?.getLabels("internalBookmark").map((l) => l.value) ?? [];
setBookmarks(bkms);
setSelectedBookmark("");
@@ -81,6 +81,8 @@ export default function AddLinkDialog() {
setLinkTitle(suggestion.externalLink);
setLinkType("external-link");
}
return () => { cancelled = true; };
}, [suggestion]);
useEffect(() => {

View File

@@ -480,7 +480,7 @@ export function findBookmarks(content: string): string[] {
function saveBookmarks(note: BNote, content: string) {
const foundBookmarks = findBookmarks(content);
const existingBookmarks = note.getLabels("internalBookmark");
const existingBookmarks = note.getOwnedLabels("internalBookmark");
for (const bookmarkId of foundBookmarks) {
const existing = existingBookmarks.find((l) => l.value === bookmarkId);

View File

@@ -1,5 +1,6 @@
import { ButtonView, Plugin, isWidget } from "ckeditor5";
import { ButtonView, Plugin } from "ckeditor5";
import copyIcon from "../icons/copy.svg?raw";
import { escapeHtml } from "../utils";
/**
* Adds a "Copy anchor link" button to the bookmark/anchor widget toolbar.
@@ -32,7 +33,7 @@ export default class CopyAnchorLinkButton extends Plugin {
if (noteId && bookmarkId) {
const href = `#root/${noteId}?bookmark=${encodeURIComponent(bookmarkId)}`;
const title = glob.getReferenceLinkTitleSync(href);
const html = `<a class="reference-link" href="${href}">${title}</a>`;
const html = `<a class="reference-link" href="${escapeHtml(href)}">${escapeHtml(title)}</a>`;
navigator.clipboard.write([
new ClipboardItem({
"text/html": new Blob([html], { type: "text/html" }),

View File

@@ -1,5 +1,9 @@
import type { DifferItemAttribute, Editor, ModelDocumentFragment, ModelElement, ModelNode } from "ckeditor5";
export function escapeHtml(str: string): string {
return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
}
function hasHeadingAncestor(node: ModelElement | ModelNode | ModelDocumentFragment | null): boolean {
let current: ModelElement | ModelNode | ModelDocumentFragment | null = node;
while (current) {

View File

@@ -106,7 +106,7 @@ function handleH1(content: string, title: string): string {
});
}
function extractCodeBlocks(text: string): { processedText: string; placeholderMap: Map<string, string> } {
export function extractCodeBlocks(text: string): { processedText: string; placeholderMap: Map<string, string> } {
const codeMap = new Map<string, string>();
let id = 0;
const timestamp = Date.now();