This commit is contained in:
Vanessa 2023-12-15 12:30:57 +08:00
parent 7414dc960f
commit a104c94c5f
4 changed files with 32 additions and 18 deletions

View file

@ -25,6 +25,7 @@ import * as dayjs from "dayjs";
import {openCalcMenu} from "./calc";
import {avRender} from "./render";
import {addView, openViewMenu} from "./view";
import {writeText} from "../../util/compatibility";
export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLElement }) => {
const blockElement = hasClosestBlock(event.target);
@ -41,7 +42,7 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
const copyElement = hasClosestByAttribute(event.target, "data-type", "copy");
if (copyElement) {
getCellText(hasClosestByClassName(copyElement, "av__cell"));
writeText(getCellText(hasClosestByClassName(copyElement, "av__cell")));
showMessage(window.siyuan.languages.copied);
event.preventDefault();
event.stopPropagation();

View file

@ -2,7 +2,7 @@ import {transaction} from "../../wysiwyg/transaction";
import {hasClosestBlock, hasClosestByClassName} from "../../util/hasClosest";
import {openMenuPanel} from "./openMenuPanel";
import {updateAttrViewCellAnimation} from "./action";
import {isNotCtrl, writeText} from "../../util/compatibility";
import {isNotCtrl} from "../../util/compatibility";
import {objEquals} from "../../../util/functions";
import {fetchPost} from "../../../util/fetch";
import {focusBlock} from "../../util/selection";
@ -10,19 +10,21 @@ import * as dayjs from "dayjs";
export const getCellText = (cellElement: HTMLElement | false) => {
if (!cellElement) {
return
return "";
}
let cellText = ""
const textElement = cellElement.querySelector(".av__celltext");
if (textElement) {
if (textElement.querySelector(".av__cellicon")) {
writeText(`${textElement.firstChild.textContent}${textElement.lastChild.textContent}`);
cellText = `${textElement.firstChild.textContent}${textElement.lastChild.textContent}`;
} else {
writeText(textElement.textContent);
cellText = textElement.textContent;
}
} else {
writeText(cellElement.textContent);
cellText = cellElement.textContent;
}
}
return cellText;
};
const genCellValueByElement = (colType: TAVCol, cellElement: HTMLElement) => {
let cellValue: IAVCellValue;
@ -55,7 +57,6 @@ const genCellValueByElement = (colType: TAVCol, cellElement: HTMLElement) => {
mSelect
};
} else if (["date", "created", "updated"].includes(colType)) {
debugger;
cellValue = {
type: colType,
[colType]: JSON.parse(cellElement.querySelector(".av__celltext").getAttribute("data-value"))
@ -97,7 +98,7 @@ export const genCellValue = (colType: TAVCol, value: string | any) => {
type: colType,
mSelect: [{
content: value,
color: ""
color: value ? "1" : ""
}]
};
} else if (["date", "created", "updated"].includes(colType) && value === "") {
@ -435,7 +436,7 @@ const updateCellValueByInput = (protyle: IProtyle, type: TAVCol, cellElements: H
});
};
export const updateCellsValue = (protyle: IProtyle, nodeElement: HTMLElement) => {
export const updateCellsValue = (protyle: IProtyle, nodeElement: HTMLElement, value = "") => {
const doOperations: IOperation[] = []
const undoOperations: IOperation[] = []
@ -471,7 +472,7 @@ export const updateCellsValue = (protyle: IProtyle, nodeElement: HTMLElement) =>
avID,
keyID: colId,
rowID,
data: genCellValue(type, "")
data: genCellValue(type, value)
});
undoOperations.push({
action: "updateAttrViewCell",

View file

@ -1,6 +1,6 @@
import {matchHotKey} from "../../util/hotKey";
import {selectRow} from "./row";
import {cellScrollIntoView, popTextCell} from "./cell";
import {cellScrollIntoView, popTextCell, updateCellsValue} from "./cell";
import {avContextmenu} from "./action";
import {hasClosestByClassName} from "../../util/hasClosest";
import {Constants} from "../../../constants";
@ -34,6 +34,11 @@ export const avKeydown = (event: KeyboardEvent, nodeElement: HTMLElement, protyl
event.preventDefault();
return true;
}
if (event.key === "Backspace") {
updateCellsValue(protyle, nodeElement);
event.preventDefault();
return true;
}
let newCellElement;
if (event.key === "ArrowLeft" || matchHotKey("⇧⇥", event)) {
const previousRowElement = rowElement.previousElementSibling;

View file

@ -9,6 +9,17 @@ import {highlightRender} from "../render/highlightRender";
import {scrollCenter} from "../../util/highlightById";
import {updateAVName} from "../render/av/action";
import {readText} from "./compatibility";
import {updateCellsValue} from "../render/av/cell";
const processAV = (range: Range, text: string, protyle: IProtyle, blockElement: Element) => {
if (blockElement.querySelector(".av__cell--select, .av__row--select")) {
updateCellsValue(protyle, blockElement as HTMLElement, text);
} else {
range.insertNode(document.createTextNode(text));
range.collapse(false);
updateAVName(protyle, blockElement);
}
};
export const insertHTML = (html: string, protyle: IProtyle, isBlock = false,
// 移动端插入嵌入块时,获取到的 range 为旧值
@ -43,14 +54,10 @@ export const insertHTML = (html: string, protyle: IProtyle, isBlock = false,
range.deleteContents();
const text = readText();
if (typeof text === "string") {
range.insertNode(document.createTextNode(text));
range.collapse(false);
updateAVName(protyle, blockElement);
processAV(range, text, protyle, blockElement)
} else {
text.then((t) => {
range.insertNode(document.createTextNode(t));
range.collapse(false);
updateAVName(protyle, blockElement);
processAV(range, t, protyle, blockElement)
});
}
return;