Vanessa 2022-07-09 16:47:02 +08:00
parent f788aa96e2
commit 3ae4585c0c

View file

@ -285,7 +285,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
if (selectElements.length > 0) { if (selectElements.length > 0) {
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
} } else {
const start = getSelectionOffset(nodeElement, editorElement, range).start; const start = getSelectionOffset(nodeElement, editorElement, range).start;
if (start !== 0) { if (start !== 0) {
const editElement = getContenteditableElement(nodeElement); const editElement = getContenteditableElement(nodeElement);
@ -299,6 +299,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
return; return;
} }
} }
}
range.collapse(true); range.collapse(true);
hideElements(["toolbar"], protyle); hideElements(["toolbar"], protyle);
if (selectElements.length === 0) { if (selectElements.length === 0) {
@ -332,7 +333,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
if (selectElements.length > 0) { if (selectElements.length > 0) {
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
} } else {
const editElement = getContenteditableElement(nodeElement); const editElement = getContenteditableElement(nodeElement);
const end = getSelectionOffset(nodeElement, editorElement, range).end; const end = getSelectionOffset(nodeElement, editorElement, range).end;
if (end < editElement.textContent.length) { if (end < editElement.textContent.length) {
@ -345,6 +346,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
return; return;
} }
} }
}
range.collapse(false); range.collapse(false);
hideElements(["toolbar"], protyle); hideElements(["toolbar"], protyle);
const selectLastElement = selectElements[selectElements.length - 1]; const selectLastElement = selectElements[selectElements.length - 1];
@ -985,6 +987,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select").forEach(item => { protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select").forEach(item => {
item.classList.remove("protyle-wysiwyg--select"); item.classList.remove("protyle-wysiwyg--select");
}); });
range.collapse(false);
nodeElement.classList.add("protyle-wysiwyg--select"); nodeElement.classList.add("protyle-wysiwyg--select");
countBlockWord([nodeElement.getAttribute("data-node-id")]); countBlockWord([nodeElement.getAttribute("data-node-id")]);
} }