Skip to content

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

Revert ":art: Improve Trackpad Adjustment Editor Font Size https://ld246.com/…" (#18233)

Vdfa1f68fccb3
diff --git a/app/src/boot/globalEvent/event.ts b/app/src/boot/globalEvent/event.ts
index b54f4c5008..8653d087f4 100644
--- a/app/src/boot/globalEvent/event.ts
+++ b/app/src/boot/globalEvent/event.ts
@@ -200,7 +200,6 @@ export const initWindowEvent = (app: App) => {
window.siyuan.ctrlIsPressed = false;
window.siyuan.shiftIsPressed = false;
window.siyuan.altIsPressed = false;
- window.siyuan.metaIsPressed = false;
document.body.classList.remove("body--shift-pressed");
/// #if BROWSER
setWebViewFocusable();
diff --git a/app/src/boot/globalEvent/keydown.ts b/app/src/boot/globalEvent/keydown.ts
index 7577a6b903..ee0a559772 100644
--- a/app/src/boot/globalEvent/keydown.ts
+++ b/app/src/boot/globalEvent/keydown.ts
@@ -3,7 +3,6 @@ import {
isMac,
isNotCtrl,
isOnlyMeta,
- isPhysicalMetaKeyEvent,
updateHotkeyTip,
writeText
} from "../../protyle/util/compatibility";
@@ -1176,9 +1175,6 @@ const panelTreeKeydown = (app: App, event: KeyboardEvent) => {
let switchDialog: Dialog;
export const windowKeyDown = (app: App, event: KeyboardEvent) => {
- if (isPhysicalMetaKeyEvent(event)) {
- window.siyuan.metaIsPressed = true;
- }
if (filterHotkey(event, app)) {
return;
}
diff --git a/app/src/boot/globalEvent/keyup.ts b/app/src/boot/globalEvent/keyup.ts
index fee4281817..9c5991dc76 100644
--- a/app/src/boot/globalEvent/keyup.ts
+++ b/app/src/boot/globalEvent/keyup.ts
@@ -7,12 +7,8 @@ import {App} from "../../index";
import {Constants} from "../../constants";
import {matchHotKey} from "../../protyle/util/hotKey";
import {isWindow} from "../../util/functions";
-import {isPhysicalMetaKeyEvent} from "../../protyle/util/compatibility";
export const windowKeyUp = (app: App, event: KeyboardEvent) => {
- if (isPhysicalMetaKeyEvent(event)) {
- window.siyuan.metaIsPressed = false;
- }
window.siyuan.ctrlIsPressed = false;
window.siyuan.shiftIsPressed = false;
window.siyuan.altIsPressed = false;
diff --git a/app/src/boot/onGetConfig.ts b/app/src/boot/onGetConfig.ts
index 3db34ccaa6..c53baa6f39 100644
--- a/app/src/boot/onGetConfig.ts
+++ b/app/src/boot/onGetConfig.ts
@@ -145,7 +145,6 @@ export const initWindow = async (app: App) => {
window.siyuan.altIsPressed = false;
window.siyuan.ctrlIsPressed = false;
window.siyuan.shiftIsPressed = false;
- window.siyuan.metaIsPressed = false;
document.body.classList.remove("body--blur");
} else if (cmd === "blur") {
document.body.classList.add("body--blur");
diff --git a/app/src/index.ts b/app/src/index.ts
index 1609f2af7c..8865cba825 100644
--- a/app/src/index.ts
+++ b/app/src/index.ts
@@ -237,7 +237,6 @@ export class App {
closedTabs: [],
ctrlIsPressed: false,
altIsPressed: false,
- metaIsPressed: false,
ws: mainWs,
};
diff --git a/app/src/mobile/index.ts b/app/src/mobile/index.ts
index 383f4956d4..a1f026aaaf 100644
--- a/app/src/mobile/index.ts
+++ b/app/src/mobile/index.ts
@@ -194,7 +194,6 @@ class App {
window.siyuan.ctrlIsPressed = false;
window.siyuan.shiftIsPressed = false;
window.siyuan.altIsPressed = false;
- window.siyuan.metaIsPressed = false;
});
window.addEventListener("blur", () => {
setWebViewFocusable();
diff --git a/app/src/protyle/ui/initUI.ts b/app/src/protyle/ui/initUI.ts
index 57fa801c35..745d5de0f5 100644
--- a/app/src/protyle/ui/initUI.ts
+++ b/app/src/protyle/ui/initUI.ts
@@ -86,55 +86,24 @@ export const initUI = (protyle: IProtyle) => {
let wheelTimeout: number;
const wheelId = genUUID();
const isMacOS = isMac();
- const ZOOM_THRESHOLD = 20; // 累加 deltaY 达到阈值时改动一级字号,避免单次缩放触发多次事件导致跳级
- const WHEEL_IDLE_MS = 200; // 单轮滚动的间隔时间,超过该时间后重置累加值
- let accumDeltaY = 0;
- let resetTimer: number;
- let wheelActive = false; // 记录是否处于同一轮滚动中
- let modifierOnset = false; // 记录同一轮滚动的首次滚动是否按下 Ctrl/Cmd
- protyle.contentElement.addEventListener("wheel", (event: WheelEvent) => {
- if (!window.siyuan.config.editor.fontSizeScrollZoom || event.shiftKey || event.deltaY === 0) {
- // 用 event.shiftKey || event.deltaY === 0 检测横向滚动,因为触控板快速划动时 deltaX 可能很大,即使容器并不能发生横向滚动
- return;
- }
- // 用「首轮是否带修饰键 + 空闲窗口」避免惯性或残留累加误触
- // 浏览器无法区分触控板与鼠标滚轮 https://github.com/w3c/pointerevents/issues/596 ,浏览器将触控板双指捏合与张开映射为带 ctrlKey 的 wheel
- // Mac 在鼠标不移动的情况下 metaKey 状态更新滞后,参考 https://github.com/tldraw/tldraw/issues/7981 用 keydown/keyup 维护 metaIsPressed 状态
- const modifierPressed = isMacOS ? window.siyuan.metaIsPressed || event.ctrlKey : event.ctrlKey;
- if (!modifierPressed) {
- accumDeltaY = 0;
- }
- clearTimeout(resetTimer);
- resetTimer = window.setTimeout(() => {
- wheelActive = false;
- accumDeltaY = 0;
- }, WHEEL_IDLE_MS);
- if (!wheelActive) {
- wheelActive = true;
- modifierOnset = modifierPressed;
- }
- if (!modifierPressed || !modifierOnset) {
- // 触控板惯性会在松手后仍产生滚轮事件,避免划动后再按下 Ctrl/Cmd 会调整字号 https://ld246.com/article/1764296257377
- // 要在单轮滚动的最后一个滚动事件触发之后等待 WHEEL_IDLE_MS 时间间隔之后再按下 Ctrl/Cmd 滚动才能调整字号
+ protyle.contentElement.addEventListener("mousewheel", (event: WheelEvent) => {
+ if (!window.siyuan.config.editor.fontSizeScrollZoom || (isMacOS && !event.metaKey) || (!isMacOS && !event.ctrlKey) || event.deltaX !== 0) {
return;
}
event.stopPropagation();
- if (accumDeltaY !== 0 && Math.sign(event.deltaY) !== Math.sign(accumDeltaY)) {
- accumDeltaY = 0;
- }
- accumDeltaY += event.deltaY;
- let stepped = false;
- if (accumDeltaY <= -ZOOM_THRESHOLD && window.siyuan.config.editor.fontSize < 72) {
- window.siyuan.config.editor.fontSize++;
- stepped = true;
- } else if (accumDeltaY >= ZOOM_THRESHOLD && window.siyuan.config.editor.fontSize > 9) {
- window.siyuan.config.editor.fontSize--;
- stepped = true;
- }
- if (!stepped) {
- return;
+ if (event.deltaY < 0) {
+ if (window.siyuan.config.editor.fontSize < 72) {
+ window.siyuan.config.editor.fontSize++;
+ } else {
+ return;
+ }
+ } else if (event.deltaY > 0) {
+ if (window.siyuan.config.editor.fontSize > 9) {
+ window.siyuan.config.editor.fontSize--;
+ } else {
+ return;
+ }
}
- accumDeltaY = 0;
setInlineStyle();
clearTimeout(wheelTimeout);
showMessage(`${window.siyuan.languages.fontSize} ${window.siyuan.config.editor.fontSize}px<span class="fn__space"></span>
@@ -158,7 +127,7 @@ export const initUI = (protyle: IProtyle) => {
});
});
}, Constants.TIMEOUT_LOAD);
- }, {passive: true}); // 调整字号有时候会滚动编辑器,目前使用 passive: true 没有解决方法
+ }, {passive: true});
protyle.contentElement.addEventListener("click", (event: MouseEvent & { target: HTMLElement }) => {
hideElements(["hint", "util"], protyle);
// wysiwyg 元素下方点击无效果 https://github.com/siyuan-note/siyuan/issues/12009
diff --git a/app/src/protyle/util/compatibility.ts b/app/src/protyle/util/compatibility.ts
index fa84265690..7e0f1982ad 100644
--- a/app/src/protyle/util/compatibility.ts
+++ b/app/src/protyle/util/compatibility.ts
@@ -334,13 +334,6 @@ export const isNotCtrl = (event: KeyboardEvent | MouseEvent) => {
return false;
};
-export const isPhysicalMetaKeyEvent = (event: KeyboardEvent) =>
- event.key === "Meta" ||
- event.code === "MetaLeft" ||
- event.code === "MetaRight" ||
- event.code === "OSLeft" ||
- event.code === "OSRight";
-
export const isHuawei = () => {
return window.siyuan.config.system.osPlatform.toLowerCase().indexOf("huawei") > -1;
};
diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts
index 235a242248..dc372dab0f 100644
--- a/app/src/types/index.d.ts
+++ b/app/src/types/index.d.ts
@@ -614,7 +614,6 @@ interface ISiyuan {
ctrlIsPressed?: boolean,
altIsPressed?: boolean,
shiftIsPressed?: boolean,
- metaIsPressed?: boolean,
coordinates?: {
pageX: number,
pageY: number,
diff --git a/app/src/window/index.ts b/app/src/window/index.ts
index 683af2b643..2df8dfd7ba 100644
--- a/app/src/window/index.ts
+++ b/app/src/window/index.ts
@@ -181,7 +181,6 @@ class App {
closedTabs: [],
ctrlIsPressed: false,
altIsPressed: false,
- metaIsPressed: false,
ws: mainWs,
};
fetchPost("/api/system/getConf", {}, async (response) => {