fix: #448
This commit is contained in:
parent
55186d162a
commit
771ccc13fe
|
|
@ -19,6 +19,8 @@ menuAddNote.newTemplateItemNote=New Item Note from Template
|
|||
|
||||
menuAddReaderNote.newTemplateNote=New Item Note from Template
|
||||
|
||||
menuEditor.resizeImage=Resize Image
|
||||
|
||||
templateEditor.title=Template Editor
|
||||
templateEditor.templateName=Template Name
|
||||
templateEditor.previewContainer=Preview
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ menuAddNote.newTemplateItemNote=从模板新建条目子笔记
|
|||
|
||||
menuAddReaderNote.newTemplateNote=从模板新建条目子笔记
|
||||
|
||||
menuEditor.resizeImage=缩放图片
|
||||
|
||||
templateEditor.title=模板编辑器
|
||||
templateEditor.templateName=模板名称
|
||||
templateEditor.previewContainer=预览
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { initEditorImagePreviewer } from "./image";
|
||||
import { injectEditorCSS, injectEditorScripts } from "./inject";
|
||||
import { initEditorMenu } from "./menu";
|
||||
import { initEditorPopup } from "./popup";
|
||||
import { initEditorToolbar } from "./toolbar";
|
||||
|
||||
|
|
@ -31,4 +32,5 @@ async function onEditorInstanceCreated(editor: Zotero.EditorInstance) {
|
|||
initEditorImagePreviewer(editor);
|
||||
await initEditorToolbar(editor);
|
||||
initEditorPopup(editor);
|
||||
initEditorMenu(editor);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
import { config } from "../../../package.json";
|
||||
import {
|
||||
isImageAtCursor,
|
||||
updateImageDimensionsAtCursor,
|
||||
} from "../../utils/editor";
|
||||
import { getString } from "../../utils/locale";
|
||||
import { getEditorCore } from "../../utils/editor";
|
||||
|
||||
export function initEditorMenu(editor: Zotero.EditorInstance) {
|
||||
const makeId = (key: string) =>
|
||||
`${config.addonRef}-editor-menu-${editor.instanceID}-${key}`;
|
||||
// Prevent duplicate menu items
|
||||
if (editor._popup.getAttribute("bn-init") === "true") {
|
||||
return;
|
||||
}
|
||||
editor._popup.setAttribute("bn-init", "true");
|
||||
(editor._popup as XUL.Menu).addEventListener("popupshowing", (ev) => {
|
||||
if (isImageAtCursor(editor)) {
|
||||
ztoolkit.Menu.register(editor._popup, {
|
||||
tag: "menuitem",
|
||||
id: makeId("resizeImage"),
|
||||
classList: [config.addonRef],
|
||||
label: getString("menuEditor.resizeImage"),
|
||||
icon: `chrome://${config.addonRef}/content/icons/favicon.png`,
|
||||
commandListener: (ev) => {
|
||||
const newWidth = parseFloat(
|
||||
editor._iframeWindow.prompt(
|
||||
getString("editor.resizeImage.prompt"),
|
||||
// @ts-ignore
|
||||
getEditorCore(editor).view.state.selection.node?.attrs?.width
|
||||
) || ""
|
||||
);
|
||||
if (newWidth && newWidth > 10) {
|
||||
updateImageDimensionsAtCursor(editor, newWidth);
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -20,6 +20,7 @@ export {
|
|||
updateURLAtCursor,
|
||||
getTextBetween,
|
||||
getTextBetweenLines,
|
||||
isImageAtCursor,
|
||||
};
|
||||
|
||||
function insert(
|
||||
|
|
|
|||
Loading…
Reference in New Issue