fix: link popup buttons disapper
This commit is contained in:
parent
26693666c2
commit
d95ffdfe4f
|
|
@ -37,6 +37,8 @@
|
|||
<command id="cmd_addheading_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'addHeading'});" />
|
||||
<command id="cmd_indent_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'indentHeading'});" />
|
||||
<command id="cmd_unindent_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'unindentHeading'});" />
|
||||
<!-- <command id="cmd_importlink_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'importLink'});" />
|
||||
<command id="cmd_updatelink_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'updateLink'});" /> -->
|
||||
<command id="cmd_autoannotation_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'updateAutoAnnotation'});" />
|
||||
<command id="cmd_treeview_betternotes" oncommand="Zotero.Knowledge4Zotero.views.switchView(1);" />
|
||||
<command id="cmd_mindmap_betternotes" oncommand="Zotero.Knowledge4Zotero.views.switchView(2);" />
|
||||
|
|
@ -80,6 +82,8 @@
|
|||
<menuitem id="menu_addheading_betternotes" class="menu-type-betternotes" label="&zotero.__addonRef__.workspace.menu.addheading;" command="cmd_addheading_betternotes" />
|
||||
<menuitem id="menu_indent_betternotes" class="menu-type-betternotes" label="&zotero.__addonRef__.workspace.menu.indent;" command="cmd_indent_betternotes" key="key_indent_betternotes" />
|
||||
<menuitem id="menu_unindent_betternotes" class="menu-type-betternotes" label="&zotero.__addonRef__.workspace.menu.unindent;" command="cmd_unindent_betternotes" key="key_unindent_betternotes" />
|
||||
<!-- <menuitem id="menu_importlink_betternotes" class="menu-type-betternotes" label="&zotero.__addonRef__.workspace.menu.importLink;" command="cmd_importlink_betternotes" />
|
||||
<menuitem id="menu_updatelink_betternotes" class="menu-type-betternotes" label="&zotero.__addonRef__.workspace.menu.updateLink;" command="cmd_updatelink_betternotes" /> -->
|
||||
<menuseparator />
|
||||
<menuitem id="menu_autoannotation_betternotes" type="checkbox" label="&zotero.__addonRef__.workspace.menu.autoannotation;" command="cmd_autoannotation_betternotes" />
|
||||
</menupopup>
|
||||
|
|
|
|||
|
|
@ -47,6 +47,8 @@
|
|||
<command id="cmd_addheading" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'addHeading'});" />
|
||||
<command id="cmd_indent_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'indentHeading'});" />
|
||||
<command id="cmd_unindent_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'unindentHeading'});" />
|
||||
<!-- <command id="cmd_importlink_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'importLink'});" />
|
||||
<command id="cmd_updatelink_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'updateLink'});" /> -->
|
||||
<command id="cmd_autoannotation_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'updateAutoAnnotation', content: {event: event}});" />
|
||||
<command id="cmd_treeview" oncommand="Zotero.Knowledge4Zotero.views.switchView(1);" />
|
||||
<command id="cmd_mindmap" oncommand="Zotero.Knowledge4Zotero.views.switchView(2);" />
|
||||
|
|
@ -87,6 +89,8 @@
|
|||
<menuitem id="menu_addheading" label="&zotero.__addonRef__.workspace.menu.addheading;" command="cmd_addheading" />
|
||||
<menuitem id="menu_indent" label="&zotero.__addonRef__.workspace.menu.indent;" command="cmd_indent_betternotes" key="key_indent" />
|
||||
<menuitem id="menu_unindent" label="&zotero.__addonRef__.workspace.menu.unindent;" command="cmd_unindent_betternotes" key="key_unindent" />
|
||||
<!-- <menuitem id="menu_importlink_betternotes" class="menu-type-betternotes" label="&zotero.__addonRef__.workspace.menu.importLink;" command="cmd_importlink_betternotes" />
|
||||
<menuitem id="menu_updatelink_betternotes" class="menu-type-betternotes" label="&zotero.__addonRef__.workspace.menu.updateLink;" command="cmd_updatelink_betternotes" /> -->
|
||||
<menuseparator />
|
||||
<menuitem id="menu_autoannotation_betternotes" type="checkbox" label="&zotero.__addonRef__.workspace.menu.autoannotation;" command="cmd_autoannotation_betternotes" />
|
||||
</menupopup>
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
<!ENTITY zotero.__addonRef__.workspace.menu.addheading "Insert Heading...">
|
||||
<!ENTITY zotero.__addonRef__.workspace.menu.indent "Decrease Heading Level">
|
||||
<!ENTITY zotero.__addonRef__.workspace.menu.unindent "Increase Heading Level">
|
||||
<!ENTITY zotero.__addonRef__.workspace.menu.importLink "Import Selected Note Link Content">
|
||||
<!ENTITY zotero.__addonRef__.workspace.menu.updateLink "Update Selected Note Link Text">
|
||||
<!ENTITY zotero.__addonRef__.workspace.menu.autoannotation "Auto Insert New Annotations to Note">
|
||||
<!ENTITY zotero.__addonRef__.workspace.menu.treeview "Outline: Tree View">
|
||||
<!ENTITY zotero.__addonRef__.workspace.menu.mindmap "Outline: Mind Map">
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
<!ENTITY zotero.__addonRef__.workspace.menu.addheading "插入标题...">
|
||||
<!ENTITY zotero.__addonRef__.workspace.menu.indent "降低标题层级">
|
||||
<!ENTITY zotero.__addonRef__.workspace.menu.unindent "提升标题层级">
|
||||
<!ENTITY zotero.__addonRef__.workspace.menu.importLink "导入选中的笔记链接内容">
|
||||
<!ENTITY zotero.__addonRef__.workspace.menu.updateLink "更新选中的笔记链接文本">
|
||||
<!ENTITY zotero.__addonRef__.workspace.menu.autoannotation "自动插入新注释到笔记">
|
||||
<!ENTITY zotero.__addonRef__.workspace.menu.treeview "大纲: 树视图">
|
||||
<!ENTITY zotero.__addonRef__.workspace.menu.mindmap "大纲: 思维导图">
|
||||
|
|
|
|||
109
src/events.ts
109
src/events.ts
|
|
@ -708,38 +708,6 @@ class AddonEvents extends AddonBase {
|
|||
header.innerHTML = "Main Note";
|
||||
header.setAttribute("style", "font-size: medium");
|
||||
middle.append(header);
|
||||
|
||||
// Link popup listener
|
||||
const container =
|
||||
_window.document.getElementsByClassName("relative-container")[0];
|
||||
const containerObserver = new MutationObserver(async (mutations) => {
|
||||
for (const mut of mutations) {
|
||||
for (const node of mut.addedNodes) {
|
||||
// wait for ui ready
|
||||
await Zotero.Promise.delay(20);
|
||||
const linkElement = (node as Element).getElementsByTagName(
|
||||
"a"
|
||||
)[0];
|
||||
if (!linkElement) {
|
||||
return;
|
||||
}
|
||||
const linkObserver = new MutationObserver(async (linkMuts) => {
|
||||
this._Addon.views.updateEditorPopupButtons(
|
||||
_window,
|
||||
linkElement.getAttribute("href")
|
||||
);
|
||||
});
|
||||
linkObserver.observe(linkElement, { attributes: true });
|
||||
this._Addon.views.updateEditorPopupButtons(
|
||||
_window,
|
||||
linkElement.getAttribute("href")
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
containerObserver.observe(container, {
|
||||
childList: true,
|
||||
});
|
||||
} else {
|
||||
// This is a preview knowledge, hide openWorkspace button add show close botton
|
||||
this._Addon.views.changeEditorButtonView(
|
||||
|
|
@ -998,8 +966,9 @@ class AddonEvents extends AddonBase {
|
|||
Zotero.Prefs.get("Knowledge4Zotero.mainKnowledgeID")
|
||||
) {
|
||||
// Update current line index
|
||||
let selection =
|
||||
message.content.editorInstance._iframeWindow.document.getSelection();
|
||||
const _window = message.content.editorInstance._iframeWindow;
|
||||
const selection = _window.document.getSelection();
|
||||
const realElement = selection.focusNode.parentElement;
|
||||
let focusNode = selection.focusNode as XUL.Element;
|
||||
if (!focusNode) {
|
||||
return;
|
||||
|
|
@ -1044,9 +1013,7 @@ class AddonEvents extends AddonBase {
|
|||
if (diveTagNames.includes(focusNode.tagName)) {
|
||||
const eleList = this._Addon.parse.parseListElements(focusNode);
|
||||
for (const i in eleList) {
|
||||
if (
|
||||
selection.focusNode.parentElement.parentElement === eleList[i]
|
||||
) {
|
||||
if (realElement.parentElement === eleList[i]) {
|
||||
currentLineIndex += Number(i);
|
||||
break;
|
||||
}
|
||||
|
|
@ -1055,6 +1022,32 @@ class AddonEvents extends AddonBase {
|
|||
Zotero.debug(`Knowledge4Zotero: line ${currentLineIndex} selected.`);
|
||||
console.log(currentLineIndex);
|
||||
this._Addon.knowledge.currentLine = currentLineIndex;
|
||||
if (realElement.tagName === "A") {
|
||||
let link = (realElement as HTMLLinkElement).href;
|
||||
let linkedNote = (await this._Addon.knowledge.getNoteFromLink(link))
|
||||
.item;
|
||||
if (linkedNote) {
|
||||
let t = 0;
|
||||
let linkPopup = _window.document.querySelector(".link-popup");
|
||||
while (
|
||||
!(linkPopup && linkPopup.querySelector("a").href === link) &&
|
||||
t < 100
|
||||
) {
|
||||
t += 1;
|
||||
linkPopup = _window.document.querySelector(".link-popup");
|
||||
await Zotero.Promise.delay(30);
|
||||
}
|
||||
this._Addon.views.updateEditorPopupButtons(
|
||||
message.content.editorInstance._iframeWindow,
|
||||
link
|
||||
);
|
||||
} else {
|
||||
this._Addon.views.updateEditorPopupButtons(
|
||||
message.content.editorInstance._iframeWindow,
|
||||
undefined
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (message.type === "addHeading") {
|
||||
/*
|
||||
|
|
@ -1140,6 +1133,48 @@ class AddonEvents extends AddonBase {
|
|||
-1,
|
||||
node.model.lineIndex
|
||||
);
|
||||
} else if (message.type === "importLink") {
|
||||
/*
|
||||
message.content = {}
|
||||
*/
|
||||
// let newLines = [];
|
||||
// const convertResult = await this._Addon.knowledge.convertNoteLines(
|
||||
// note,
|
||||
// [],
|
||||
// true,
|
||||
// false
|
||||
// );
|
||||
// const subNoteLines = convertResult.lines;
|
||||
// const templateText = await this._Addon.template.renderTemplateAsync(
|
||||
// "[QuickImport]",
|
||||
// "subNoteLines, subNoteItem, noteItem",
|
||||
// [subNoteLines, note, this._Addon.knowledge.getWorkspaceNote()]
|
||||
// );
|
||||
// newLines.push(templateText);
|
||||
// const newLineString = newLines.join("\n");
|
||||
// await this._Addon.knowledge.modifyLineInNote(
|
||||
// undefined,
|
||||
// (oldLine: string) => {
|
||||
// Zotero.debug(oldLine);
|
||||
// const params = this._Addon.parse.parseParamsFromLink(link);
|
||||
// if (!params.ignore) {
|
||||
// const newLink =
|
||||
// link + (link.includes("?") ? "&ignore=1" : "?ignore=1");
|
||||
// const linkIndex = this._Addon.parse.parseLinkIndexInText(oldLine);
|
||||
// Zotero.debug(linkIndex);
|
||||
// return `${oldLine.slice(0, linkIndex[0])}${newLink}${oldLine.slice(
|
||||
// linkIndex[1]
|
||||
// )}\n${newLineString}`;
|
||||
// }
|
||||
// },
|
||||
// this._Addon.knowledge.currentLine
|
||||
// );
|
||||
// await Zotero.DB.executeTransaction(async () => {
|
||||
// await Zotero.Notes.copyEmbeddedImages(
|
||||
// note,
|
||||
// this._Addon.knowledge.getWorkspaceNote()
|
||||
// );
|
||||
// });
|
||||
} else if (message.type === "updateAutoAnnotation") {
|
||||
/*
|
||||
message.content = {
|
||||
|
|
|
|||
|
|
@ -293,29 +293,6 @@ class Knowledge extends AddonBase {
|
|||
}
|
||||
}
|
||||
|
||||
// Abandoned
|
||||
async addLinesToNote(
|
||||
note: ZoteroItem,
|
||||
newLines: string[],
|
||||
lineIndex: number
|
||||
) {
|
||||
note = note || this.getWorkspaceNote();
|
||||
if (!note) {
|
||||
return;
|
||||
}
|
||||
let noteLines = this.getLinesInNote(note);
|
||||
if (lineIndex < 0) {
|
||||
lineIndex =
|
||||
this.getWorkspaceNote().id === note.id && this.currentLine >= 0
|
||||
? this.currentLine
|
||||
: noteLines.length;
|
||||
} else if (lineIndex >= noteLines.length) {
|
||||
lineIndex = noteLines.length;
|
||||
}
|
||||
await this.addLineToNote(note, newLines.join("\n"), lineIndex);
|
||||
await this.scrollWithRefresh(lineIndex);
|
||||
}
|
||||
|
||||
_dataURLtoBlob(dataurl: string) {
|
||||
let parts = dataurl.split(",");
|
||||
let mime = parts[0].match(/:(.*?);/)[1];
|
||||
|
|
@ -545,7 +522,6 @@ class Knowledge extends AddonBase {
|
|||
.replace(headerStopReg, `</h${lineRank}>`),
|
||||
lineIndex
|
||||
);
|
||||
await this.scrollWithRefresh(lineIndex);
|
||||
}
|
||||
|
||||
moveHeaderLineInNote(
|
||||
|
|
|
|||
18
src/views.ts
18
src/views.ts
|
|
@ -381,8 +381,10 @@ class AddonViews extends AddonBase {
|
|||
}
|
||||
|
||||
async updateEditorPopupButtons(_window: Window, link: string) {
|
||||
const note: ZoteroItem = (await this._Addon.knowledge.getNoteFromLink(link))
|
||||
.item;
|
||||
const note: ZoteroItem = link
|
||||
? (await this._Addon.knowledge.getNoteFromLink(link)).item
|
||||
: undefined;
|
||||
// If the note is invalid, we remove the buttons
|
||||
if (note) {
|
||||
let insertButton = _window.document.getElementById("insert-note-link");
|
||||
if (insertButton) {
|
||||
|
|
@ -519,8 +521,18 @@ class AddonViews extends AddonBase {
|
|||
);
|
||||
});
|
||||
_window.document
|
||||
.getElementsByClassName("link-popup")[0]
|
||||
.querySelector(".link-popup")
|
||||
.append(insertButton, updateButton);
|
||||
} else {
|
||||
const insertLink = _window.document.querySelector("#insert-note-link");
|
||||
if (insertLink) {
|
||||
insertLink.remove();
|
||||
}
|
||||
|
||||
const updateLink = _window.document.querySelector("#update-note-link");
|
||||
if (updateLink) {
|
||||
updateLink.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue