Skip to content

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

:art: https://github.com/siyuan-note/siyuan/issues/13207

Vanessace696ca1d1fd
diff --git a/app/src/constants.ts b/app/src/constants.ts
index bd9b7a2200..e409ac8ddd 100644
--- a/app/src/constants.ts
+++ b/app/src/constants.ts
@@ -301,6 +301,7 @@ export abstract class Constants {
public static readonly TIMEOUT_RESIZE = 200;
public static readonly TIMEOUT_INPUT = 256;
public static readonly TIMEOUT_LOAD = 300;
+ public static readonly TIMEOUT_LONGPRESS = 400;
public static readonly TIMEOUT_TRANSITION = 300;
public static readonly TIMEOUT_COUNT = 1000;
diff --git a/app/src/mobile/dock/MobileFiles.ts b/app/src/mobile/dock/MobileFiles.ts
index 03e67fd945..75feaad28a 100644
--- a/app/src/mobile/dock/MobileFiles.ts
+++ b/app/src/mobile/dock/MobileFiles.ts
@@ -311,7 +311,7 @@ export class MobileFiles extends Model {
if (!state) return;
const touch = event.touches[0];
if (!state.isDragging) {
- if (Date.now() - state.startTime < 400 &&
+ if (Date.now() - state.startTime < Constants.TIMEOUT_LONGPRESS &&
(Math.abs(touch.clientX - state.startX) > 5 || Math.abs(touch.clientY - state.startY) > 5)) {
this.touchDragState = null;
return;
diff --git a/app/src/mobile/menu/index.ts b/app/src/mobile/menu/index.ts
index a235eeba2f..498bb32319 100644
--- a/app/src/mobile/menu/index.ts
+++ b/app/src/mobile/menu/index.ts
@@ -25,8 +25,12 @@ import {commandPanel} from "../../boot/globalEvent/command/panel";
import {openTopBarMenu} from "../../plugin/openTopBarMenu";
import {initFileTree} from "../settings/fileTree";
import {initExport} from "../settings/export";
+import {getCurrentEditor} from "../editor";
export const popMenu = () => {
+ if (getCurrentEditor()?.protyle.toolbar.isMultiSelectMode()) {
+ return;
+ }
activeBlur();
document.getElementById("menu").style.transform = "translateX(0px)";
};
diff --git a/app/src/mobile/util/initFramework.ts b/app/src/mobile/util/initFramework.ts
index 3335e9a020..f48a62525b 100644
--- a/app/src/mobile/util/initFramework.ts
+++ b/app/src/mobile/util/initFramework.ts
@@ -1,6 +1,6 @@
import {Constants} from "../../constants";
import {closeModel, closePanel} from "./closePanel";
-import {openMobileFileById} from "../editor";
+import {getCurrentEditor, openMobileFileById} from "../editor";
import {validateName} from "../../editor/rename";
import {getEventName} from "../../protyle/util/compatibility";
import {fetchPost} from "../../util/fetch";
@@ -147,6 +147,9 @@ export const initFramework = (app: App, isStart: boolean) => {
});
window.siyuan.mobile.docks.file = new MobileFiles(app);
document.getElementById("toolbarFile").addEventListener("click", () => {
+ if (getCurrentEditor()?.protyle.toolbar.isMultiSelectMode()) {
+ return;
+ }
activeBlur();
sidebarElement.style.transform = "translateX(0px)";
const type = sidebarElement.querySelector(".toolbar--border .toolbar__icon--active").getAttribute("data-type");
diff --git a/app/src/mobile/util/touch.ts b/app/src/mobile/util/touch.ts
index b814361a54..038324de93 100644
--- a/app/src/mobile/util/touch.ts
+++ b/app/src/mobile/util/touch.ts
@@ -10,6 +10,7 @@ import {activeBlur} from "./keyboardToolbar";
import {isChromeBrowser, isIPhone} from "../../protyle/util/compatibility";
import {getRangeByPoint} from "../../protyle/util/selection";
import {getCurrentEditor} from "../editor";
+import {Constants} from "../../constants";
let clientX: number;
let clientY: number;
@@ -34,14 +35,23 @@ const popSide = (render = true) => {
export const handleTouchEnd = (event: TouchEvent) => {
const target = event.target as HTMLElement;
const currentTime = Date.now();
- if (!window.siyuan.touchDragActive && isIPhone() && !isChromeBrowser() && typeof yDiff === "undefined" &&
- currentTime - time > 900 && currentTime - time < 2000) {
- target.dispatchEvent(new MouseEvent("contextmenu", {
- bubbles: true,
- cancelable: true,
- clientX: event.changedTouches[0].clientX,
- clientY: event.changedTouches[0].clientY,
- }));
+ if (Math.abs(clientX - event.changedTouches[0].clientX) < 5 && Math.abs(clientY - event.changedTouches[0].clientY) < 5 &&
+ currentTime - time > Constants.TIMEOUT_LONGPRESS) {
+ if (isIPhone() && !isChromeBrowser() && !window.siyuan.touchDragActive) {
+ target.dispatchEvent(new MouseEvent("contextmenu", {
+ bubbles: true,
+ cancelable: true,
+ clientX: event.changedTouches[0].clientX,
+ clientY: event.changedTouches[0].clientY,
+ }));
+ }
+ if (currentTime - time > 2000) {
+ const blockElement = hasClosestBlock(target);
+ if (blockElement) {
+ const protyle = getCurrentEditor().protyle;
+ protyle.toolbar.showMultiSelectMode(protyle, blockElement);
+ }
+ }
event.stopImmediatePropagation();
event.preventDefault();
return;
@@ -166,6 +176,23 @@ export const handleTouchEnd = (event: TouchEvent) => {
export const handleTouchStart = (event: TouchEvent) => {
time = Date.now();
const target = event.touches[0].target as HTMLElement;
+ const editor = getCurrentEditor();
+ if (editor && editor.protyle.toolbar.isMultiSelectMode()) {
+ const blockElement = hasClosestBlock(target);
+ if (blockElement) {
+ blockElement.querySelectorAll(".protyle-wysiwyg--select").forEach(item => {
+ item.classList.remove("protyle-wysiwyg--select");
+ });
+ const blockParentElement = hasClosestByClassName(blockElement.parentElement, "protyle-wysiwyg--select");
+ if (blockParentElement) {
+ blockParentElement.classList.remove("protyle-wysiwyg--select");
+ }
+ blockElement.classList.toggle("protyle-wysiwyg--select");
+ editor.protyle.toolbar.subElement.querySelector(".multiSelectCount").textContent =
+ editor.protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select").length.toString();
+ }
+ return;
+ }
if (0 < event.touches.length && (target.tagName === "VIDEO" || target.tagName === "AUDIO")) {
// https://github.com/siyuan-note/siyuan/issues/14569
activeBlur();
@@ -181,12 +208,10 @@ export const handleTouchStart = (event: TouchEvent) => {
clientY = null;
return;
}
- if (getSelection().rangeCount > 0 && hasClosestBlock(event.target as Element)) {
- const editor = getCurrentEditor();
- if (editor && !editor.protyle.disabled && event.touches[0].clientY > window.innerHeight / 2 &&
- document.querySelector("#keyboardToolbar").classList.contains("fn__none")) {
- window.siyuan.mobile.touchRange = getRangeByPoint(event.touches[0].clientX, event.touches[0].clientY);
- }
+ if (getSelection().rangeCount > 0 && hasClosestBlock(event.target as Element) &&
+ editor && !editor.protyle.disabled && event.touches[0].clientY > window.innerHeight / 2 &&
+ document.querySelector("#keyboardToolbar").classList.contains("fn__none")) {
+ window.siyuan.mobile.touchRange = getRangeByPoint(event.touches[0].clientX, event.touches[0].clientY);
}
firstDirection = null;
diff --git a/app/src/protyle/breadcrumb/index.ts b/app/src/protyle/breadcrumb/index.ts
index dba28b57c3..3e8a6347e4 100644
--- a/app/src/protyle/breadcrumb/index.ts
+++ b/app/src/protyle/breadcrumb/index.ts
@@ -200,6 +200,9 @@ ${padHTML}
}
private genMobileMenu(protyle: IProtyle) {
+ if (protyle.toolbar.isMultiSelectMode()) {
+ return;
+ }
const menu = new Menu(Constants.MENU_BREADCRUMB_MOBILE_PATH);
let blockElement: Element;
if (getSelection().rangeCount > 0) {
diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.ts
index da08c15c65..10d535a2b9 100644
--- a/app/src/protyle/toolbar/index.ts
+++ b/app/src/protyle/toolbar/index.ts
@@ -1377,6 +1377,58 @@ export class Toolbar {
inputElement.select();
}
+ public showMultiSelectMode(protyle: IProtyle, blockElement: HTMLElement) {
+ blockElement.classList.add("protyle-wysiwyg--select");
+ window.siyuan.menus.menu.remove();
+
+ this.subElement.style.width = window.innerWidth - 16 + "px";
+ this.subElement.style.padding = "0";
+ this.subElement.innerHTML = `<div class="block__icons">
+ <div class="block__logo">
+ <svg class="block__logoicon"><use xlink:href="#iconCheck"></use></svg>
+ <span class="multiSelectCount">${protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select").length}</span>
+ </div>
+ <span class="fn__flex-1"></span>
+ <button class="block__icon block__icon--show" data-type="menu" data-menu="true"><svg><use xlink:href="#iconMore"></use></svg></button>
+ <span class="fn__space"></span>
+ <button class="block__icon block__icon--show" data-type="exitMultiSelectMode"><svg><use xlink:href="#iconClose"></use></svg></button>
+</div>`;
+ this.subElement.style.zIndex = (++window.siyuan.zIndex).toString();
+ this.subElement.classList.remove("fn__none");
+ this.subElementCloseCB = undefined;
+ this.subElement.firstElementChild.addEventListener("click", (event) => {
+ let target = event.target as HTMLElement;
+ while (target && target !== this.subElement) {
+ if (target.dataset.type === "exitMultiSelectMode") {
+ this.subElement.classList.add("fn__none");
+ this.subElement.innerHTML = "";
+ hideElements(["select"], protyle);
+ event.preventDefault();
+ event.stopPropagation();
+ break;
+ } else if (target.dataset.type === "menu") {
+ protyle.gutter.renderMenu(protyle, protyle.wysiwyg.element.querySelector(".protyle-wysiwyg--select"));
+ window.siyuan.menus.menu.fullscreen();
+ event.preventDefault();
+ event.stopPropagation();
+ break;
+ }
+ target = target.parentElement;
+ }
+ });
+ setPosition(this.subElement, 8, 8);
+ this.element.classList.add("fn__none");
+ }
+
+ public isMultiSelectMode() {
+ let result = false;
+ /// #if MOBILE
+ result = !this.subElement.classList.contains("fn__none") &&
+ !!this.subElement.querySelector('[data-type="exitMultiSelectMode"]');
+ /// #endif
+ return result;
+ }
+
public showTpl(protyle: IProtyle, nodeElement: HTMLElement, range: Range) {
this.range = range;
hideElements(["hint"], protyle);
@@ -1593,7 +1645,11 @@ export class Toolbar {
k: inputElement.value,
}, (response) => {
let searchHTML = "";
- response.data.widgets.forEach((item: { path: string, content: string, name: string }, index: number) => {
+ response.data.widgets.forEach((item: {
+ path: string,
+ content: string,
+ name: string
+ }, index: number) => {
searchHTML += `<div data-value="${item.path}" data-content="${item.content}" class="b3-list-item${index === 0 ? " b3-list-item--focus" : ""}">
${item.name}
<span class="b3-list-item__meta">${item.content}</span>
diff --git a/app/src/protyle/ui/hideElements.ts b/app/src/protyle/ui/hideElements.ts
index e22c0476d6..1d5af6dae4 100644
--- a/app/src/protyle/ui/hideElements.ts
+++ b/app/src/protyle/ui/hideElements.ts
@@ -37,7 +37,8 @@ export const hideElements = (panels: string[], protyle?: IProtyle, focusHide = f
}
if (protyle.toolbar && panels.includes("util")) {
const pinElement = protyle.toolbar.subElement.querySelector('[data-type="pin"]');
- if (focusHide || !pinElement || (pinElement && pinElement.getAttribute("aria-label") === window.siyuan.languages.pin)) {
+ if (!protyle.toolbar.isMultiSelectMode() &&
+ (focusHide || !pinElement || (pinElement && pinElement.getAttribute("aria-label") === window.siyuan.languages.pin))) {
protyle.toolbar.subElement.classList.add("fn__none");
if (protyle.toolbar.subElementCloseCB) {
protyle.toolbar.subElementCloseCB();
@@ -66,7 +67,8 @@ export const hideAllElements = (types: string[]) => {
getAllEditor().forEach(item => {
if (item.protyle.toolbar) {
const pinElement = item.protyle.toolbar.subElement.querySelector('[data-type="pin"]');
- if (!pinElement || (pinElement && pinElement.getAttribute("aria-label") === window.siyuan.languages.pin)) {
+ if (!item.protyle.toolbar.isMultiSelectMode() &&
+ (!pinElement || (pinElement && pinElement.getAttribute("aria-label") === window.siyuan.languages.pin))) {
item.protyle.toolbar.subElement.classList.add("fn__none");
if (item.protyle.toolbar.subElementCloseCB) {
item.protyle.toolbar.subElementCloseCB();
diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts
index 9f855851a5..85e78bd6d0 100644
--- a/app/src/protyle/wysiwyg/index.ts
+++ b/app/src/protyle/wysiwyg/index.ts
@@ -509,6 +509,10 @@ export class WYSIWYG {
});
this.element.addEventListener("mousedown", (event: MouseEvent) => {
+ if (protyle.toolbar.isMultiSelectMode()) {
+ event.preventDefault();
+ return;
+ }
protyle.wysiwyg.element.classList.remove("protyle-wysiwyg--hiderange");
if (event.button === 2) {
// 右键
@@ -2611,6 +2615,10 @@ export class WYSIWYG {
});
let mobileBlur = false;
this.element.addEventListener("click", (event: MouseEvent & { target: HTMLElement }) => {
+ if (protyle.toolbar.isMultiSelectMode()) {
+ event.preventDefault();
+ return;
+ }
if (this.preventClick) {
this.preventClick = false;
return;