Skip to content

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

:fire: Remove touch drag block selection https://github.com/siyuan-note/siyuan/issues/20682

Daniel85a85f79f815
diff --git a/app/src/protyle/wysiwyg/blockDragSelectionScroll.test.ts b/app/src/protyle/wysiwyg/blockDragSelectionGesture.browser.test.ts
similarity index 80%
rename from app/src/protyle/wysiwyg/blockDragSelectionScroll.test.ts
rename to app/src/protyle/wysiwyg/blockDragSelectionGesture.browser.test.ts
index 1d511ffa7d..ae8589bf72 100644
--- a/app/src/protyle/wysiwyg/blockDragSelectionScroll.test.ts
+++ b/app/src/protyle/wysiwyg/blockDragSelectionGesture.browser.test.ts
@@ -7,7 +7,7 @@ import {test} from "node:test";
import {promisify} from "node:util";
import {ModuleKind, ScriptTarget, transpileModule} from "typescript";
-test("native touch scrolling preserves selected blocks while sustained dragging extends the range", {
+test("native touch swipes preserve selected blocks and scroll even after a sustained press", {
skip: process.platform === "linux" && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY,
timeout: 30000,
}, async () => {
@@ -30,10 +30,10 @@ app.whenReady().then(async () => {
await win.webContents.debugger.sendCommand("Emulation.setTouchEmulationEnabled", {enabled: true});
const evaluate = code => win.webContents.executeJavaScript(code);
await evaluate(
- 'window.gestures = {}; new Function("exports", "require", ' + ${JSON.stringify(JSON.stringify(source))} +
- ')(window.gestures, () => ({Constants: {SIZE_DRAG_THRESHOLD: 5, TIMEOUT_MULTIPLE_SELECT: 1500}}));'
+ 'window.gestures = {}; new Function("exports", ' + ${JSON.stringify(JSON.stringify(source))} +
+ ')(window.gestures);'
);
- const setup = async multi => {
+ const setup = async () => {
await evaluate(
'window.dispose?.(); document.body.innerHTML = ' + JSON.stringify(
'<style>body{margin:0}.scroll{height:400px;overflow:auto}.protyle-wysiwyg{user-select:none}' +
@@ -48,11 +48,10 @@ app.whenReady().then(async () => {
'window.dispose = gestures.bindBlockDragSelectionGesture(root, () => scroller, {' +
'canStart: () => true, getStartBlock: target => target.closest(".block"),' +
'getBlockAtPoint: p => document.elementFromPoint(p.clientX, p.clientY)?.closest(".block"),' +
- 'isMultiSelectMode: () => ' + multi + ',' +
'select: (start, end) => { selections.push([start.dataset.id, end.dataset.id]);' +
'const a = blocks.indexOf(start), b = blocks.indexOf(end);' +
'blocks.forEach((block, i) => block.classList.toggle("selected", i >= Math.min(a,b) && i <= Math.max(a,b))); },' +
- 'scroll: () => {}, finish: (source, cancelled) => ends.push({source, cancelled}) }); void 0;'
+ 'scroll: () => {}, finish: cancelled => ends.push(cancelled) }); void 0;'
);
await delay(100);
};
@@ -61,9 +60,10 @@ app.whenReady().then(async () => {
});
const state = () => evaluate('({scroll: scroller.scrollTop, selections, ends,' +
' selected: blocks.filter(block => block.classList.contains("selected")).map(block => block.dataset.id)})');
- for (const multi of [false, true]) {
- await setup(multi);
+ for (const duration of [0, 1600]) {
+ await setup();
await touch("touchStart", 250);
+ if (duration) await delay(duration);
for (const y of [230, 190, 150, 100]) {
await delay(30);
await touch("touchMove", y);
@@ -71,22 +71,11 @@ app.whenReady().then(async () => {
await touch("touchEnd");
await delay(150);
const result = await state();
- assert.ok(result.scroll > 50, "a short swipe scrolls the editor in either selection mode");
+ assert.ok(result.scroll > 50, "swiping scrolls the editor regardless of the press duration");
assert.deepEqual(result.selections, []);
assert.deepEqual(result.ends, []);
assert.deepEqual(result.selected, ["0", "1"], "scrolling preserves the existing selection");
}
- await setup(true);
- await touch("touchStart", 50);
- await delay(1600);
- await touch("touchMove", 150);
- await touch("touchMove", 250);
- await touch("touchEnd");
- const selection = await state();
- assert.equal(selection.scroll, 0);
- assert.deepEqual(selection.selected, ["0", "1", "2"]);
- assert.ok(selection.selections.length > 0);
- assert.deepEqual(selection.ends, [{source: "touch", cancelled: false}]);
console.log("Native block selection scrolling passed");
win.destroy();
app.exit(0);
diff --git a/app/src/protyle/wysiwyg/blockDragSelectionGesture.test.ts b/app/src/protyle/wysiwyg/blockDragSelectionGesture.test.ts
index 3113641f27..04469e6ebf 100644
--- a/app/src/protyle/wysiwyg/blockDragSelectionGesture.test.ts
+++ b/app/src/protyle/wysiwyg/blockDragSelectionGesture.test.ts
@@ -53,13 +53,11 @@ const fixture = (mountScroll = true) => {
const element = Object.assign(new Surface(), {ownerDocument: document, contains: (): boolean => true});
const scrollElement = new Surface();
let enabled = true;
- let multiSelect = false;
const selections: string[][] = [];
- const finishes: Array<{source: string, cancelled: boolean}> = [];
+ const finishes: boolean[] = [];
const scrolls: unknown[] = [];
runInNewContext(compiled, {
exports,
- require: () => ({Constants: {SIZE_DRAG_THRESHOLD: 5, TIMEOUT_MULTIPLE_SELECT: 1500}}),
Date: {now: () => time},
});
let mountedScrollElement: Surface;
@@ -67,10 +65,9 @@ const fixture = (mountScroll = true) => {
canStart: () => enabled,
getStartBlock: (target: object) => blocks.includes(target as typeof blocks[0]) ? target : undefined,
getBlockAtPoint: (point: {clientY: number}) => blocks[Math.floor(point.clientY / 100)],
- isMultiSelectMode: () => multiSelect,
select: (start: typeof blocks[0], end: typeof blocks[0]) => selections.push([start.id, end.id]),
scroll: (point: unknown) => scrolls.push(point),
- finish: (source: string, cancelled: boolean) => finishes.push({source, cancelled}),
+ finish: (cancelled: boolean) => finishes.push(cancelled),
});
if (mountScroll) {
mountedScrollElement = scrollElement;
@@ -78,7 +75,7 @@ const fixture = (mountScroll = true) => {
const mouseDown = (properties = {}) => element.send("mousedown", {target: blocks[0], ...properties});
const touch = (type: string, y = 20, properties = {}) => {
const point = {identifier: 1, clientX: 20, clientY: y};
- return (type === "touchstart" ? element : document).send(type, {
+ return (type === "touchmove" ? document : element).send(type, {
target: blocks[0], touches: type === "touchend" ? [] : [point], changedTouches: [point], ...properties,
});
};
@@ -86,7 +83,6 @@ const fixture = (mountScroll = true) => {
element, document, window, scrollElement, selections, finishes, scrolls, blocks, dispose, mouseDown, touch,
advance: (milliseconds: number) => time += milliseconds,
disable: () => enabled = false,
- enterMultiSelect: () => multiSelect = true,
mount: () => mountedScrollElement = scrollElement,
};
};
@@ -97,9 +93,9 @@ test("scroll containers can be initialized after binding and disposal before a g
assert.equal(unused.element.count(), 0);
const mounted = fixture(false);
mounted.mount();
- mounted.touch("touchstart");
+ mounted.mouseDown();
assert.equal(mounted.scrollElement.count(), 1);
- mounted.touch("touchend");
+ mounted.document.send("mouseup");
assert.equal(mounted.scrollElement.count(), 0);
mounted.dispose();
});
@@ -114,7 +110,7 @@ test("mouse text selection stays native in one block and becomes a reversible wh
f.document.send("mousemove", {clientY: 20});
assert.deepEqual(f.selections, [["a", "c"], ["a", "b"], ["a", "a"]]);
assert.equal(f.document.send("mouseup").stopped, true);
- assert.deepEqual(f.finishes, [{source: "mouse", cancelled: false}]);
+ assert.deepEqual(f.finishes, [false]);
assert.equal(f.element.send("click").defaultPrevented, true);
assert.equal(f.document.count(), 0);
assert.equal(f.scrollElement.count(), 0);
@@ -133,13 +129,11 @@ test("new gestures preserve modifier clicks, right clicks, double clicks and han
}
});
-test("ordinary touch scrolling never changes into block selection after waiting", () => {
- for (const multiSelect of [false, true]) {
+test("touch swipes stay native even after a sustained press and never create a block selection", () => {
+ for (const duration of [0, 1600]) {
const f = fixture();
- if (multiSelect) {
- f.enterMultiSelect();
- }
assert.equal(f.touch("touchstart").defaultPrevented, false);
+ f.advance(duration);
assert.equal(f.touch("touchmove", 50).defaultPrevented, false);
f.advance(2000);
assert.equal(f.touch("touchmove", 220).defaultPrevented, false);
@@ -148,78 +142,47 @@ test("ordinary touch scrolling never changes into block selection after waiting"
assert.equal(f.document.count(), 0);
assert.equal(f.scrollElement.count(), 0);
assert.deepEqual(f.scrolls, []);
+ assert.deepEqual(f.finishes, []);
+ assert.equal(f.element.send("click").defaultPrevented, false);
}
});
-test("a sustained touch can cross block boundaries without changing a short native word selection", () => {
- const f = fixture();
- f.touch("touchstart");
- f.advance(1600);
- assert.equal(f.touch("touchmove", 22).defaultPrevented, false);
- assert.equal(f.touch("touchmove", 120).defaultPrevented, true);
- assert.equal(f.touch("touchmove", 220).defaultPrevented, true);
- assert.equal(f.touch("touchend", 220).defaultPrevented, true);
- assert.deepEqual(f.selections, [["a", "b"], ["a", "c"]]);
- assert.deepEqual(f.finishes, [{source: "touch", cancelled: false}]);
- f.mouseDown();
- assert.equal(f.document.count(), 0);
-});
-
-test("multi-select touch supports dragging after long-press activation and keeps later taps native", () => {
- const f = fixture();
- f.touch("touchstart");
- f.advance(1500);
- f.enterMultiSelect();
- assert.equal(f.touch("touchmove", 50).defaultPrevented, true);
- f.touch("touchmove", 220);
- f.touch("touchend", 220);
- assert.deepEqual(f.selections, [["a", "a"], ["a", "c"]]);
- assert.equal(f.touch("touchstart").defaultPrevented, false);
- assert.equal(f.touch("touchend").defaultPrevented, false);
-});
-
-test("a fresh touch in multi-select mode requires a sustained press before extending the selection", () => {
- const f = fixture();
- f.enterMultiSelect();
- assert.equal(f.touch("touchstart").defaultPrevented, false);
- f.advance(1500);
- assert.equal(f.touch("touchmove", 50).defaultPrevented, true);
- assert.equal(f.touch("touchmove", 220).defaultPrevented, true);
- assert.equal(f.touch("touchend", 220).defaultPrevented, true);
- assert.deepEqual(f.selections, [["a", "a"], ["a", "c"]]);
- assert.deepEqual(f.finishes, [{source: "touch", cancelled: false}]);
- assert.equal(f.document.count(), 0);
+test("compatibility mouse events after touch release or cancellation do not start block selection", () => {
+ for (const end of ["touchend", "touchcancel"]) {
+ const f = fixture();
+ f.touch("touchstart");
+ f.advance(2000);
+ f.touch(end);
+ f.mouseDown();
+ assert.equal(f.document.count(), 0);
+ f.advance(500);
+ f.mouseDown();
+ f.document.send("mousemove", {clientY: 220});
+ assert.deepEqual(f.selections, [["a", "c"]]);
+ }
});
-test("multi-touch, native cancellation, lost buttons, escape, blur and disposal release gesture listeners", () => {
- for (const end of ["multi-touch", "touchcancel", "buttons", "escape", "blur", "dispose", "disabled", "detached"]) {
+test("lost buttons, escape, blur and disposal release mouse gesture listeners", () => {
+ for (const end of ["buttons", "escape", "blur", "dispose", "disabled", "detached"]) {
const f = fixture();
- if (end === "multi-touch" || end === "touchcancel") {
- f.enterMultiSelect();
- f.touch("touchstart");
- f.advance(1500);
- f.touch("touchmove", 120);
- f.document.send(end === "multi-touch" ? "touchstart" : "touchcancel", {touches: [{}, {}]});
- } else {
- f.mouseDown();
- f.document.send("mousemove", {clientY: 120});
- if (end === "buttons") {
- f.document.send("mousemove", {buttons: 0});
- } else if (end === "escape") {
- f.document.send("keydown", {key: "Escape"});
- } else if (end === "blur") {
- f.window.send("blur");
- } else if (end === "disabled" || end === "detached") {
- if (end === "disabled") {
- f.disable();
- } else {
- f.element.contains = () => false;
- }
- f.document.send("mousemove", {clientY: 220});
+ f.mouseDown();
+ f.document.send("mousemove", {clientY: 120});
+ if (end === "buttons") {
+ f.document.send("mousemove", {buttons: 0});
+ } else if (end === "escape") {
+ f.document.send("keydown", {key: "Escape"});
+ } else if (end === "blur") {
+ f.window.send("blur");
+ } else if (end === "disabled" || end === "detached") {
+ if (end === "disabled") {
+ f.disable();
} else {
- f.dispose();
- assert.equal(f.element.count(), 0);
+ f.element.contains = () => false;
}
+ f.document.send("mousemove", {clientY: 220});
+ } else {
+ f.dispose();
+ assert.equal(f.element.count(), 0);
}
assert.equal(f.finishes.length, 1, end);
assert.equal(f.document.count(), 0, end);
@@ -235,7 +198,7 @@ test("scrolling refreshes the active range and a composition cancels it without
f.scrollElement.send("scroll");
assert.equal(f.selections.length, 2);
assert.equal(f.element.send("compositionstart").defaultPrevented, false);
- assert.deepEqual(f.finishes, [{source: "mouse", cancelled: true}]);
+ assert.deepEqual(f.finishes, [true]);
f.mouseDown();
assert.equal(f.document.count(), 0);
f.element.send("compositionend");
@@ -245,13 +208,10 @@ test("scrolling refreshes the active range and a composition cancels it without
assert.deepEqual(f.selections[f.selections.length - 1], ["a", "c"]);
});
-test("native drag and non-cancelable touch scrolling stay with the browser", () => {
+test("native drag stays with the browser", () => {
const f = fixture();
f.mouseDown();
assert.equal(f.document.send("dragstart").defaultPrevented, false);
assert.equal(f.document.count(), 0);
- f.touch("touchstart");
- f.advance(1600);
- assert.equal(f.touch("touchmove", 120, {cancelable: false}).defaultPrevented, false);
assert.deepEqual(f.selections, []);
});
diff --git a/app/src/protyle/wysiwyg/blockDragSelectionGesture.ts b/app/src/protyle/wysiwyg/blockDragSelectionGesture.ts
index d85bf80ec4..de54752b4f 100644
--- a/app/src/protyle/wysiwyg/blockDragSelectionGesture.ts
+++ b/app/src/protyle/wysiwyg/blockDragSelectionGesture.ts
@@ -1,25 +1,21 @@
-import {Constants} from "../../constants";
-
type TPoint = {clientX: number, clientY: number};
-type TSource = "mouse" | "touch";
interface IBlockDragSelectionOptions {
- canStart: (source: TSource) => boolean;
- getStartBlock: (target: HTMLElement, source: TSource) => HTMLElement | undefined;
+ canStart: () => boolean;
+ getStartBlock: (target: HTMLElement) => HTMLElement | undefined;
getBlockAtPoint: (point: TPoint) => HTMLElement | undefined;
- isMultiSelectMode: () => boolean;
- select: (start: HTMLElement, end: HTMLElement, source: TSource) => void;
+ select: (start: HTMLElement, end: HTMLElement) => void;
scroll: (point?: TPoint) => void;
- finish: (source: TSource, cancelled: boolean) => void;
+ finish: (cancelled: boolean) => void;
}
-// 文字选区保留在单个编辑宿主内,跨块拖动由应用维护整块选区。
+// 鼠标文字选区保留在单个编辑宿主内,跨块拖动由应用维护整块选区。
export const bindBlockDragSelectionGesture = (element: HTMLElement, getScrollElement: () => HTMLElement,
options: IBlockDragSelectionOptions) => {
const ownerDocument = element.ownerDocument;
const ownerWindow = ownerDocument.defaultView;
let gesture: {
- source: TSource, block: HTMLElement, point: TPoint, time: number, touchID?: number,
+ block: HTMLElement,
active: boolean, lastPoint: TPoint,
} | undefined;
let suppressClickUntil = 0;
@@ -32,10 +28,6 @@ export const bindBlockDragSelectionGesture = (element: HTMLElement, getScrollEle
gesture = undefined;
ownerDocument.removeEventListener("mousemove", mouseMove, true);
ownerDocument.removeEventListener("mouseup", mouseUp, true);
- ownerDocument.removeEventListener("touchmove", touchMove, true);
- ownerDocument.removeEventListener("touchend", touchEnd, true);
- ownerDocument.removeEventListener("touchcancel", cancel, true);
- ownerDocument.removeEventListener("touchstart", additionalTouch, true);
ownerDocument.removeEventListener("keydown", keyDown, true);
ownerDocument.removeEventListener("dragstart", dragStart, true);
scrollElement?.removeEventListener("scroll", scroll);
@@ -44,7 +36,7 @@ export const bindBlockDragSelectionGesture = (element: HTMLElement, getScrollEle
if (previous?.active) {
suppressClickUntil = Date.now() + 500;
options.scroll();
- options.finish(previous.source, cancelled);
+ options.finish(cancelled);
}
};
const cancel = () => finish(true);
@@ -60,19 +52,19 @@ export const bindBlockDragSelectionGesture = (element: HTMLElement, getScrollEle
cancel();
}
};
- const update = (point: TPoint, allowSingleBlock = false) => {
- if (!gesture || composing || !element.contains(gesture.block) || !options.canStart(gesture.source)) {
+ const update = (point: TPoint) => {
+ if (!gesture || composing || !element.contains(gesture.block) || !options.canStart()) {
cancel();
return false;
}
const end = options.getBlockAtPoint(point);
- if (!gesture.active && (!end || end === gesture.block && !allowSingleBlock)) {
+ if (!gesture.active && (!end || end === gesture.block)) {
return false;
}
gesture.active = true;
gesture.lastPoint = point;
if (end) {
- options.select(gesture.block, end, gesture.source);
+ options.select(gesture.block, end);
}
options.scroll(point);
return true;
@@ -98,88 +90,37 @@ export const bindBlockDragSelectionGesture = (element: HTMLElement, getScrollEle
event.stopImmediatePropagation();
}
};
- const additionalTouch = (event: TouchEvent) => {
- if (event.touches.length !== 1) {
- cancel();
- }
- };
- const touchMove = (event: TouchEvent) => {
- const touch = gesture && Array.from(event.touches).find(item => item.identifier === gesture.touchID);
- if (!touch || event.touches.length !== 1 || !event.cancelable) {
- cancel();
- return;
- }
- if (!gesture.active) {
- if (Math.abs(touch.clientX - gesture.point.clientX) < Constants.SIZE_DRAG_THRESHOLD &&
- Math.abs(touch.clientY - gesture.point.clientY) < Constants.SIZE_DRAG_THRESHOLD) {
- return;
- }
- // 普通滑动交给浏览器滚动,多选模式下也需持续长按后才尝试扩选。
- if (Date.now() - gesture.time < Constants.TIMEOUT_MULTIPLE_SELECT) {
- cancel();
- return;
- }
- }
- if (update(touch, options.isMultiSelectMode())) {
- // 保留冒泡,让移动端全局手势清理自己的长按和侧栏滑动状态。
- event.preventDefault();
- }
- };
- const touchEnd = (event: TouchEvent) => {
- lastTouchTime = Date.now();
- if (!gesture || !Array.from(event.changedTouches).some(item => item.identifier === gesture.touchID)) {
- return;
- }
- const active = gesture.active;
- finish(false);
- if (active) {
- event.preventDefault();
- }
- };
- const start = (target: HTMLElement, point: TPoint, source: TSource, touchID?: number) => {
+ const start = (target: HTMLElement, point: TPoint) => {
finish(true);
suppressClickUntil = 0;
- if (composing || !options.canStart(source)) {
+ if (composing || !options.canStart()) {
return;
}
- const block = options.getStartBlock(target, source);
+ const block = options.getStartBlock(target);
if (!block) {
return;
}
- gesture = {source, block, point, time: Date.now(), touchID, active: false, lastPoint: point};
+ gesture = {block, active: false, lastPoint: point};
// 正文宿主先于滚动容器初始化,开始手势时再绑定实际容器。
scrollElement = getScrollElement();
ownerDocument.addEventListener("keydown", keyDown, true);
ownerDocument.addEventListener("dragstart", dragStart, true);
ownerWindow.addEventListener("blur", cancel);
scrollElement.addEventListener("scroll", scroll);
- if (source === "mouse") {
- ownerDocument.addEventListener("mousemove", mouseMove, true);
- ownerDocument.addEventListener("mouseup", mouseUp, true);
- } else {
- ownerDocument.addEventListener("touchmove", touchMove, {capture: true, passive: false});
- ownerDocument.addEventListener("touchend", touchEnd, {capture: true, passive: false});
- ownerDocument.addEventListener("touchcancel", cancel, true);
- ownerDocument.addEventListener("touchstart", additionalTouch, true);
- }
- return true;
+ ownerDocument.addEventListener("mousemove", mouseMove, true);
+ ownerDocument.addEventListener("mouseup", mouseUp, true);
};
const mouseDown = (event: MouseEvent & {sourceCapabilities?: {firesTouchEvents: boolean}}) => {
if (event.defaultPrevented || event.button !== 0 || event.detail > 1 ||
- event.shiftKey || event.ctrlKey || event.metaKey || event.altKey || gesture?.source === "touch" ||
+ event.shiftKey || event.ctrlKey || event.metaKey || event.altKey ||
event.sourceCapabilities?.firesTouchEvents || Date.now() - lastTouchTime < 500) {
return;
}
- start(event.target as HTMLElement, event, "mouse");
+ start(event.target as HTMLElement, event);
};
- const touchStart = (event: TouchEvent) => {
+ const recordTouch = () => {
+ // 仅记录触摸时间,避免浏览器合成的兼容鼠标事件启动跨块拖选。
lastTouchTime = Date.now();
- if (event.defaultPrevented || event.touches.length !== 1) {
- cancel();
- return;
- }
- const touch = event.touches[0];
- start(event.target as HTMLElement, touch, "touch", touch.identifier);
};
const click = (event: MouseEvent) => {
if (Date.now() < suppressClickUntil) {
@@ -196,7 +137,9 @@ export const bindBlockDragSelectionGesture = (element: HTMLElement, getScrollEle
composing = false;
};
element.addEventListener("mousedown", mouseDown);
- element.addEventListener("touchstart", touchStart, {passive: false});
+ element.addEventListener("touchstart", recordTouch, {passive: true});
+ element.addEventListener("touchend", recordTouch, {passive: true});
+ element.addEventListener("touchcancel", recordTouch, {passive: true});
element.addEventListener("click", click, true);
element.addEventListener("compositionstart", compositionStart);
element.addEventListener("compositionend", compositionEnd);
@@ -204,7 +147,9 @@ export const bindBlockDragSelectionGesture = (element: HTMLElement, getScrollEle
return () => {
cancel();
element.removeEventListener("mousedown", mouseDown);
- element.removeEventListener("touchstart", touchStart);
+ element.removeEventListener("touchstart", recordTouch);
+ element.removeEventListener("touchend", recordTouch);
+ element.removeEventListener("touchcancel", recordTouch);
element.removeEventListener("click", click, true);
element.removeEventListener("compositionstart", compositionStart);
element.removeEventListener("compositionend", compositionEnd);
diff --git a/app/src/protyle/wysiwyg/boundedBlockDragSelect.test.ts b/app/src/protyle/wysiwyg/boundedBlockDragSelect.test.ts
index accf6baef6..064992cbe8 100644
--- a/app/src/protyle/wysiwyg/boundedBlockDragSelect.test.ts
+++ b/app/src/protyle/wysiwyg/boundedBlockDragSelect.test.ts
@@ -110,64 +110,63 @@ test("bounded selection resolves the scroll container after editor initializatio
test("bounded mouse selection is enabled only for protected editor roots with block operations", () => {
const f = fixture();
- assert.equal(f.options.canStart("mouse"), true);
+ assert.equal(f.options.canStart(), true);
f.setEditable("true");
- assert.equal(f.options.canStart("mouse"), false);
- assert.equal(f.options.canStart("touch"), true);
+ assert.equal(f.options.canStart(), false);
f.setEditable("false");
f.classes.add("fn__pointer-none");
- assert.equal(f.options.canStart("mouse"), false, "padding drag retains ownership of its gesture");
+ assert.equal(f.options.canStart(), false, "padding drag retains ownership of its gesture");
f.classes.clear();
f.protyle.disabled = true;
- assert.equal(f.options.canStart("touch"), false);
+ assert.equal(f.options.canStart(), false);
f.protyle.disabled = false;
f.setBacklink();
- assert.equal(f.options.canStart("mouse"), false);
+ assert.equal(f.options.canStart(), false);
});
test("bounded selection starts in editable block content and leaves controls and nested editors alone", () => {
const f = fixture();
- assert.equal(f.options.getStartBlock(f.target(), "mouse"), f.blocks[0]);
- assert.equal(f.options.getStartBlock(f.target(true), "mouse"), undefined);
- assert.equal(f.options.getStartBlock(f.target(false, false), "mouse"), undefined);
- assert.equal(f.options.getStartBlock(f.target(false, true, false), "mouse"), undefined);
+ assert.equal(f.options.getStartBlock(f.target()), f.blocks[0]);
+ assert.equal(f.options.getStartBlock(f.target(true)), undefined);
+ assert.equal(f.options.getStartBlock(f.target(false, false)), undefined);
+ assert.equal(f.options.getStartBlock(f.target(false, true, false)), undefined);
f.enterMultiSelect();
- assert.equal(f.options.getStartBlock(f.target(false, false), "touch"), f.blocks[0]);
+ assert.equal(f.options.getStartBlock(f.target(false, false)), undefined);
});
test("desktop completion uses existing block selection and a focusable block without reopening the editor root", () => {
const f = fixture();
- f.options.select(f.blocks[0], f.blocks[1], "mouse");
+ f.options.select(f.blocks[0], f.blocks[1]);
assert.ok(f.states.every(state => state.has("protyle-wysiwyg--select")));
assert.equal(f.state().selectionCleared, 1);
assert.ok(f.classes.has("protyle-wysiwyg--hiderange"));
- f.options.finish("mouse", false);
+ f.options.finish(false);
assert.equal(f.state().focused, f.blocks[1]);
assert.equal(f.state().modeElement, f.blocks[1]);
assert.equal(f.classes.has("protyle-wysiwyg--hiderange"), false);
- assert.equal(f.options.canStart("mouse"), true);
+ assert.equal(f.options.canStart(), true);
assert.equal(f.state().gutterRestored, 0);
f.flushFrames();
assert.equal(f.state().gutterRestored, 1);
assert.equal(f.state().gutterTarget, f.blocks[1]);
});
-test("mobile completion retains the multi-select toolbar and cancellation does not steal focus", () => {
+test("mobile mouse completion retains the multi-select toolbar and cancellation does not steal focus", () => {
const f = fixture(true);
- f.options.select(f.blocks[0], f.blocks[1], "touch");
- f.options.finish("touch", false);
+ f.options.select(f.blocks[0], f.blocks[1]);
+ f.options.finish(false);
assert.equal(f.state().multiSelect, true);
assert.equal(f.state().focused, undefined);
- f.options.select(f.blocks[0], f.blocks[1], "touch");
+ f.options.select(f.blocks[0], f.blocks[1]);
assert.equal(f.state().toolbarCount, 2);
- f.options.finish("touch", true);
+ f.options.finish(true);
f.flushFrames();
assert.equal(f.state().gutterRestored, 0, "mobile keeps its multi-select toolbar");
assert.equal(f.classes.has("protyle-wysiwyg--hiderange"), false);
const removed = fixture();
- removed.options.select(removed.blocks[0], removed.blocks[1], "mouse");
+ removed.options.select(removed.blocks[0], removed.blocks[1]);
removed.detach();
- removed.options.finish("mouse", false);
+ removed.options.finish(false);
removed.flushFrames();
assert.equal(removed.state().gutterRestored, 0);
assert.equal(removed.state().focused, undefined);
@@ -175,8 +174,8 @@ test("mobile completion retains the multi-select toolbar and cancellation does n
test("cancelled bounded selection does not restore a gutter after losing focus", () => {
const f = fixture();
- f.options.select(f.blocks[0], f.blocks[1], "touch");
- f.options.finish("touch", true);
+ f.options.select(f.blocks[0], f.blocks[1]);
+ f.options.finish(true);
f.flushFrames();
assert.equal(f.state().gutterRestored, 0);
});
diff --git a/app/src/protyle/wysiwyg/boundedBlockDragSelect.ts b/app/src/protyle/wysiwyg/boundedBlockDragSelect.ts
index 890b86edb3..b36e7809ca 100644
--- a/app/src/protyle/wysiwyg/boundedBlockDragSelect.ts
+++ b/app/src/protyle/wysiwyg/boundedBlockDragSelect.ts
@@ -24,24 +24,21 @@ export const bindBoundedBlockDragSelect = (protyle: IProtyle, element: HTMLEleme
return block ? (isInEmbedBlock(block) || block) as HTMLElement : undefined;
};
return bindBlockDragSelectionGesture(element, () => protyle.contentElement, {
- canStart: source => !!protyle.gutter && !protyle.disabled &&
+ canStart: () => !!protyle.gutter && !protyle.disabled &&
!window.siyuan.touchDragActive && !element.closest(".sy__backlink--bottom") &&
!element.classList.contains("fn__pointer-none") &&
// iPad 保留可跨块编辑的正文宿主,鼠标继续使用其原生文字选区。
- (source === "touch" || element.getAttribute("contenteditable") === "false"),
- isMultiSelectMode: () => protyle.toolbar.isMultiSelectMode(),
- getStartBlock: (target, source) => {
+ element.getAttribute("contenteditable") === "false",
+ getStartBlock: target => {
if (target.closest("input, textarea, select, button, a, audio, video, iframe, protyle-html, " +
".protyle-action, .protyle-attr, .protyle-action__drag, .sb__resize, .protyle-custom, " +
".av, .table, .protyle-wysiwyg__embed, [data-type='NodeBlockQueryEmbed'], [data-prevent-swipe]")) {
return undefined;
}
- if (source === "mouse" || !protyle.toolbar.isMultiSelectMode()) {
- const editable = target.closest('[contenteditable="true"]');
- if (!editable || !element.contains(editable) ||
- target.closest("[contenteditable]")?.getAttribute("contenteditable") !== "true") {
- return undefined;
- }
+ const editable = target.closest('[contenteditable="true"]');
+ if (!editable || !element.contains(editable) ||
+ target.closest("[contenteditable]")?.getAttribute("contenteditable") !== "true") {
+ return undefined;
}
return getBlock(target);
},
@@ -84,7 +81,7 @@ export const bindBoundedBlockDragSelect = (protyle: IProtyle, element: HTMLEleme
stopScrollAnimation();
}
},
- finish: (_source, cancelled) => {
+ finish: cancelled => {
selecting = false;
element.classList.remove("protyle-wysiwyg--hiderange");
if (!activeBlock || !element.contains(activeBlock)) {