fix: link section jump to note

This commit is contained in:
windingwind 2024-04-12 22:59:07 +08:00
parent 25ab026700
commit 20ad713bc6
4 changed files with 24 additions and 12 deletions

View File

@ -56,6 +56,10 @@ item-pane-custom-section .bn-link-body {
width: 0;
flex: 1;
overflow: hidden;
.position-label {
color: var(--fill-secondary);
}
}
.icon,

View File

@ -28,7 +28,7 @@ async function rebuildLinkForNote(
links: LinkModel[],
) {
console.log("rebuildLinkForNote", fromLibID, fromKey, links);
const collection = db.link.where({ fromLibID, fromKey });
const oldOutboundLinks = await collection.toArray();
collection.delete().then((deleteCount) => {

View File

@ -122,16 +122,20 @@ async function renderSection(
.getGlobal("require")("components/icons")
.getCSSItemTypeIcon("note");
const label = doc.createElement("span");
const label = doc.createElement("div");
label.className = "label";
let content = targetItem.getNoteTitle();
const title = doc.createElement("span");
title.textContent = targetItem.getNoteTitle();
const position = doc.createElement("span");
position.className = "position-label";
if (typeof linkData.toLine === "number") {
content += ` > Line ${linkData.toLine}`;
position.textContent = `>Line ${linkData.toLine}`;
}
if (typeof linkData.toSection === "string") {
content += `#${linkData.toSection}`;
position.textContent = `#${linkData.toSection}`;
}
label.append(content);
label.append(title, position);
label.title = linkData.url;
const box = doc.createElement("div");
box.addEventListener("click", () =>
@ -159,10 +163,6 @@ async function renderSection(
setCount(count);
}
function handleShowItem(id: number) {
ZoteroPane.selectItem(id);
}
function makeSetCount(setL10nArgs: (str: string) => void) {
return (count: number) => {
setL10nArgs(`{"count": "${count}"}`);

View File

@ -73,11 +73,12 @@ async function updateNoteLinkRelation(noteID: number) {
const lines = addon.api.note.getLinesInNote(note);
const linkToData: LinkModel[] = [];
for (let i = 0; i < lines.length; i++) {
const linkMatches = lines[i].match(/zotero:\/\/note\/\w+\/\w+\//g);
const linkMatches = lines[i].match(/href="zotero:\/\/note\/[^"]+"/g);
if (!linkMatches) {
continue;
}
for (const link of linkMatches) {
for (const match of linkMatches) {
const link = decodeHTMLEntities(match.slice(6, -1));
const { noteItem, libraryID, noteKey, lineIndex, sectionName } =
getNoteLinkParams(link);
if (noteItem && noteItem.isNote() && noteItem.id !== note.id) {
@ -140,6 +141,13 @@ async function getNoteLinkInboundRelation(
});
}
function decodeHTMLEntities(text: string) {
return text
.replace(/&amp;/g, "&")
.replace(/&lt;/g, "<")
.replace(/&gt;/g, ">");
}
interface LinkModel {
fromLibID: number;
fromKey: string;