From 4bf4c1228c0bb74823ec4f517112c858ae0440c7 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Thu, 16 Jun 2022 19:01:46 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/5155 --- app/src/layout/dock/Bookmark.ts | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/app/src/layout/dock/Bookmark.ts b/app/src/layout/dock/Bookmark.ts index da372ab32..21771cb4c 100644 --- a/app/src/layout/dock/Bookmark.ts +++ b/app/src/layout/dock/Bookmark.ts @@ -77,7 +77,7 @@ export class Bookmark extends Model { element: this.element.lastElementChild as HTMLElement, data: null, click(element: HTMLElement) { - const id = element.getAttribute("data-node-id"); + const id = element.getAttribute("data-node-id"); fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => { openFileById({ id, @@ -88,7 +88,8 @@ export class Bookmark extends Model { }, rightClick: (element: HTMLElement, event: MouseEvent) => { window.siyuan.menus.menu.remove(); - if (!element.getAttribute("data-node-id")) { + const id = element.getAttribute("data-node-id") + if (!id) { window.siyuan.menus.menu.append(new MenuItem({ label: window.siyuan.languages.rename, click: () => { @@ -123,13 +124,14 @@ export class Bookmark extends Model { }); } }).element); - } else { - window.siyuan.menus.menu.append(new MenuItem({ - icon: "iconTrashcan", - label: window.siyuan.languages.remove, - click: () => { - confirmDialog(window.siyuan.languages.delete, `${window.siyuan.languages.confirmDelete} ${escapeHtml(element.parentElement.previousElementSibling.querySelector(".b3-list-item__text").textContent)}?`, () => { - const id = element.getAttribute("data-node-id"); + } + window.siyuan.menus.menu.append(new MenuItem({ + icon: "iconTrashcan", + label: window.siyuan.languages.remove, + click: () => { + const bookmark = (id ? element.parentElement.previousElementSibling : element).querySelector(".b3-list-item__text").textContent + confirmDialog(window.siyuan.languages.delete, `${window.siyuan.languages.confirmDelete} ${escapeHtml(bookmark)}?`, () => { + if (id) { fetchPost("/api/attr/setBlockAttrs", {id, attrs: {bookmark: ""}}, () => { this.update(); }); @@ -140,10 +142,14 @@ export class Bookmark extends Model { bookmarkElement.remove(); } }); - }); - } - }).element); - } + } else { + fetchPost("/api/bookmark/removeBookmark", {bookmark}, () => { + this.update(); + }); + } + }); + } + }).element); window.siyuan.menus.menu.popup({x: event.clientX, y: event.clientY}); }, ctrlClick(element: HTMLElement) {