This commit is contained in:
Vanessa 2022-09-19 23:56:47 +08:00
parent 1ad3a1c505
commit 6851656c09
4 changed files with 13 additions and 13 deletions

View File

@ -11,7 +11,7 @@ import {
setFirstNodeRange, setFirstNodeRange,
setLastNodeRange setLastNodeRange
} from "../util/selection"; } from "../util/selection";
import {hasClosestBlock, hasClosestByAttribute, hasClosestByClassName, hasClosestByMatchTag} from "../util/hasClosest"; import {hasClosestBlock, hasClosestByClassName} from "../util/hasClosest";
import {Link} from "./Link"; import {Link} from "./Link";
import {setPosition} from "../../util/setPosition"; import {setPosition} from "../../util/setPosition";
import {updateTransaction} from "../wysiwyg/transaction"; import {updateTransaction} from "../wysiwyg/transaction";
@ -859,33 +859,33 @@ export class Toolbar {
} }
} }
if (isInlineMemo) { if (isInlineMemo) {
let inlineMemoElements let inlineMemoElements;
if (updateElements) { if (updateElements) {
inlineMemoElements = updateElements inlineMemoElements = updateElements;
} else { } else {
inlineMemoElements = [renderElement] inlineMemoElements = [renderElement];
} }
inlineMemoElements.forEach((item, index) => { inlineMemoElements.forEach((item, index) => {
if (!target.value) { if (!target.value) {
// https://github.com/siyuan-note/insider/issues/1046 // https://github.com/siyuan-note/insider/issues/1046
const currentTypes = item.getAttribute("data-type").split(" ") const currentTypes = item.getAttribute("data-type").split(" ");
if (currentTypes.length === 1 && currentTypes[0] === "inline-memo") { if (currentTypes.length === 1 && currentTypes[0] === "inline-memo") {
item.outerHTML = item.innerHTML + (index === inlineMemoElements.length - 1 ? "<wbr>" : ""); item.outerHTML = item.innerHTML + (index === inlineMemoElements.length - 1 ? "<wbr>" : "");
focusByWbr(nodeElement, this.range); focusByWbr(nodeElement, this.range);
} else { } else {
currentTypes.find((typeItem, index) => { currentTypes.find((typeItem, index) => {
if (typeItem === "inline-memo") { if (typeItem === "inline-memo") {
currentTypes.splice(index, 1) currentTypes.splice(index, 1);
return true return true;
} }
}) });
item.setAttribute("data-type", currentTypes.join(" ")); item.setAttribute("data-type", currentTypes.join(" "));
item.removeAttribute("data-inline-memo-content"); item.removeAttribute("data-inline-memo-content");
} }
} else { } else {
item.setAttribute("data-inline-memo-content", Lute.EscapeHTMLStr(target.value)); item.setAttribute("data-inline-memo-content", Lute.EscapeHTMLStr(target.value));
} }
}) });
} else if (type === "NodeBlockQueryEmbed") { } else if (type === "NodeBlockQueryEmbed") {
blockRender(protyle, renderElement); blockRender(protyle, renderElement);
} }

View File

@ -1,4 +1,4 @@
import {hasClosestBlock, hasClosestByAttribute, hasClosestByClassName, hasClosestByMatchTag} from "./hasClosest"; import {hasClosestBlock, hasClosestByAttribute, hasClosestByClassName} from "./hasClosest";
import * as dayjs from "dayjs"; import * as dayjs from "dayjs";
import {removeEmbed} from "../wysiwyg/removeEmbed"; import {removeEmbed} from "../wysiwyg/removeEmbed";
import {transaction, updateTransaction} from "../wysiwyg/transaction"; import {transaction, updateTransaction} from "../wysiwyg/transaction";

View File

@ -45,7 +45,7 @@ export const fixTableRange = (range:Range) => {
} }
} }
} }
} };
export const selectAll = (protyle: IProtyle, nodeElement: Element, range: Range) => { export const selectAll = (protyle: IProtyle, nodeElement: Element, range: Range) => {
const editElement = getContenteditableElement(nodeElement); const editElement = getContenteditableElement(nodeElement);

View File

@ -846,12 +846,12 @@ export class WYSIWYG {
let cursorElement = hasClosestBlock(range.startContainer) as Element; let cursorElement = hasClosestBlock(range.startContainer) as Element;
if (cursorElement) { if (cursorElement) {
if (cursorElement.nextElementSibling?.classList.contains("table")) { if (cursorElement.nextElementSibling?.classList.contains("table")) {
setLastNodeRange(getContenteditableElement(cursorElement), range, false) setLastNodeRange(getContenteditableElement(cursorElement), range, false);
} else if (cursorElement.classList.contains("table")) { } else if (cursorElement.classList.contains("table")) {
const cellElements = cursorElement.querySelectorAll("th, td"); const cellElements = cursorElement.querySelectorAll("th, td");
cursorElement = cellElements[cellElements.length - 1]; cursorElement = cellElements[cellElements.length - 1];
if (cursorElement.contains(range.startContainer)) { if (cursorElement.contains(range.startContainer)) {
setLastNodeRange(cursorElement, range, false) setLastNodeRange(cursorElement, range, false);
} }
} }
} }