Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Avoid rendering export previews during IME composition https://github.com/siyuan-note/siyuan/issues/18967

Daniel220e3ee3755e
diff --git a/app/src/protyle/export/index.ts b/app/src/protyle/export/index.ts
index b8836dbdda..44dcb17421 100644
--- a/app/src/protyle/export/index.ts
+++ b/app/src/protyle/export/index.ts
@@ -699,13 +699,27 @@ ${getIconScript(servePath)}
const customTitleElement = actionElement.querySelector('#customTitle');
const customTitlePanelElement = actionElement.querySelector('#customTitlePanel');
let titleRefreshTimer;
+ let titleComposing = false;
addTitleElement.addEventListener('change', () => {
customTitlePanelElement.classList.toggle('fn__none', !addTitleElement.checked);
refreshPreview();
});
- customTitleElement.addEventListener('input', () => {
+ const scheduleTitleRefresh = () => {
window.clearTimeout(titleRefreshTimer);
titleRefreshTimer = window.setTimeout(refreshPreview, 300);
+ };
+ customTitleElement.addEventListener('compositionstart', () => {
+ titleComposing = true;
+ window.clearTimeout(titleRefreshTimer);
+ });
+ customTitleElement.addEventListener('compositionend', () => {
+ titleComposing = false;
+ scheduleTitleRefresh();
+ });
+ customTitleElement.addEventListener('input', () => {
+ if (!titleComposing) {
+ scheduleTitleRefresh();
+ }
});
const mergeSubdocsElement = actionElement.querySelector('#mergeSubdocs');
const mergeHeadingOptionsElement = actionElement.querySelector('#mergeHeadingOptions');
diff --git a/app/src/protyle/export/util.ts b/app/src/protyle/export/util.ts
index 5ad170828d..a527c505cf 100644
--- a/app/src/protyle/export/util.ts
+++ b/app/src/protyle/export/util.ts
@@ -91,6 +91,7 @@ export const exportImage = (id: string, copyOnly = false) => {
let imageName = "image.png";
let outputting = false;
let titleRefreshTimer: number;
+ let titleComposing = false;
const setActionDisabled = (disabled: boolean) => {
cancelButton.disabled = disabled;
@@ -238,9 +239,22 @@ export const exportImage = (id: string, copyOnly = false) => {
customTitleElement.disabled = !addTitleElement.checked;
refreshExportPreview();
});
- customTitleElement.addEventListener("input", () => {
+ const scheduleTitleRefresh = () => {
window.clearTimeout(titleRefreshTimer);
titleRefreshTimer = window.setTimeout(refreshExportPreview, 300);
+ };
+ customTitleElement.addEventListener("compositionstart", () => {
+ titleComposing = true;
+ window.clearTimeout(titleRefreshTimer);
+ });
+ customTitleElement.addEventListener("compositionend", () => {
+ titleComposing = false;
+ scheduleTitleRefresh();
+ });
+ customTitleElement.addEventListener("input", () => {
+ if (!titleComposing) {
+ scheduleTitleRefresh();
+ }
});
foldElement.addEventListener("change", () => {
window.siyuan.storage[Constants.LOCAL_EXPORTIMG].keepFold = foldElement.checked;