|
@@ -4,7 +4,7 @@ import {isMac, writeText} from "../util/compatibility";
|
|
|
import {
|
|
|
focusBlock,
|
|
|
getSelectionOffset,
|
|
|
- setFirstNodeRange,
|
|
|
+ setFirstNodeRange, setLastNodeRange,
|
|
|
} from "../util/selection";
|
|
|
import {getContenteditableElement, hasNextSibling, hasPreviousSibling} from "./getBlock";
|
|
|
import {hasClosestByMatchTag} from "../util/hasClosest";
|
|
@@ -95,21 +95,19 @@ export const upSelect = (options: {
|
|
|
options.event.stopPropagation();
|
|
|
options.event.preventDefault();
|
|
|
} else {
|
|
|
- if (isMac() // Windows 中 ⌥⇧↓ 默认无选中功能会导致 https://ld246.com/article/1716635371149
|
|
|
- && getSelectionOffset(options.nodeElement, options.editorElement, options.range).start !== 0) {
|
|
|
- const editElement = getContenteditableElement(options.nodeElement);
|
|
|
- if (editElement.tagName === "TABLE") {
|
|
|
- const cellElement = hasClosestByMatchTag(options.range.startContainer, "TH") || hasClosestByMatchTag(options.range.startContainer, "TD") || editElement.querySelector("th, td");
|
|
|
- if (getSelectionOffset(cellElement, cellElement, options.range).start !== 0) {
|
|
|
- setFirstNodeRange(cellElement, options.range);
|
|
|
- options.event.stopPropagation();
|
|
|
- options.event.preventDefault();
|
|
|
- return;
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 选中上一个节点的处理在 toolbar/index.ts 中 `shift+方向键或三击选中`
|
|
|
- return;
|
|
|
+ const tdElement = hasClosestByMatchTag(options.range.startContainer, "TD") || hasClosestByMatchTag(options.range.startContainer, "TH");
|
|
|
+ const nodeEditableElement = (tdElement || getContenteditableElement(options.nodeElement) || options.nodeElement) as HTMLElement;
|
|
|
+ const startIndex = getSelectionOffset(nodeEditableElement, options.editorElement, options.range).start
|
|
|
+ const innerText = nodeEditableElement.innerText;
|
|
|
+ const isExpandUp = matchHotKey(window.siyuan.config.keymap.editor.general.expandUp.custom, options.event)
|
|
|
+ if (!isMac() && isExpandUp) {
|
|
|
+ // Windows 中 ⌥⇧↑ 默认无选中功能会导致 https://ld246.com/article/1716635371149
|
|
|
+ } else if (startIndex > 0) {
|
|
|
+ // 选中上一个节点的处理在 toolbar/index.ts 中 `shift+方向键或三击选中`
|
|
|
+ if (innerText.substr(0, startIndex).indexOf("\n") === -1) {
|
|
|
+ setFirstNodeRange(nodeEditableElement, options.range);
|
|
|
}
|
|
|
+ return;
|
|
|
}
|
|
|
}
|
|
|
options.range.collapse(true);
|
|
@@ -141,9 +139,22 @@ export const downSelect = (options: {
|
|
|
options.event.stopPropagation();
|
|
|
options.event.preventDefault();
|
|
|
} else {
|
|
|
- if (isMac() // Windows 中 ⌥⇧↑ 默认无选中功能会导致 https://ld246.com/article/1716635371149
|
|
|
- && getSelectionOffset(options.nodeElement, options.editorElement, options.range).end < getContenteditableElement(options.nodeElement).textContent.length) {
|
|
|
+ const tdElement = hasClosestByMatchTag(options.range.startContainer, "TD") || hasClosestByMatchTag(options.range.startContainer, "TH");
|
|
|
+ const nodeEditableElement = (tdElement || getContenteditableElement(options.nodeElement) || options.nodeElement) as HTMLElement;
|
|
|
+ const endIndex = getSelectionOffset(nodeEditableElement, options.editorElement, options.range).end
|
|
|
+ const innerText = nodeEditableElement.innerText;
|
|
|
+ const isExpandDown = matchHotKey(window.siyuan.config.keymap.editor.general.expandDown.custom, options.event)
|
|
|
+ if (!isMac() && isExpandDown) {
|
|
|
+ // Windows 中 ⌥⇧↓ 默认无选中功能会导致 https://ld246.com/article/1716635371149
|
|
|
+ } else if (endIndex < innerText.length) {
|
|
|
// 选中下一个节点的处理在 toolbar/index.ts 中 `shift+方向键或三击选中`
|
|
|
+ if (!options.nodeElement.nextElementSibling && innerText.trimRight().substr(endIndex).indexOf("\n") === -1) {
|
|
|
+ // 当为最后一个块时应选中末尾
|
|
|
+ setLastNodeRange(nodeEditableElement, options.range, false);
|
|
|
+ if (options.nodeElement.classList.contains("code-block") && isExpandDown) {
|
|
|
+ options.event.preventDefault();
|
|
|
+ }
|
|
|
+ }
|
|
|
return;
|
|
|
}
|
|
|
}
|