mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-15 08:30:42 +08:00
This commit is contained in:
parent
06cb209f0e
commit
377f9ef8b8
@ -35,6 +35,7 @@ import {lineNumberRender} from "../protyle/markdown/highlightRender";
|
|||||||
import * as dayjs from "dayjs";
|
import * as dayjs from "dayjs";
|
||||||
import {blockRender} from "../protyle/markdown/blockRender";
|
import {blockRender} from "../protyle/markdown/blockRender";
|
||||||
import {renameAsset} from "../editor/rename";
|
import {renameAsset} from "../editor/rename";
|
||||||
|
import {hasNextSibling} from "../protyle/wysiwyg/getBlock";
|
||||||
|
|
||||||
export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
|
export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
|
||||||
const nodeElement = hasClosestBlock(element);
|
const nodeElement = hasClosestBlock(element);
|
||||||
@ -535,6 +536,17 @@ export const imgMenu = (protyle: IProtyle, range: Range, assetElement: HTMLEleme
|
|||||||
click() {
|
click() {
|
||||||
nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
|
nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
|
||||||
assetElement.style.display = "block";
|
assetElement.style.display = "block";
|
||||||
|
let nextSibling = assetElement.nextSibling;
|
||||||
|
while (nextSibling) {
|
||||||
|
if (nextSibling.textContent === "") {
|
||||||
|
nextSibling = nextSibling.nextSibling;
|
||||||
|
} else if (nextSibling.textContent === Constants.ZWSP) {
|
||||||
|
nextSibling.textContent = "";
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
updateTransaction(protyle, id, nodeElement.outerHTML, html);
|
updateTransaction(protyle, id, nodeElement.outerHTML, html);
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
@ -545,6 +557,9 @@ export const imgMenu = (protyle: IProtyle, range: Range, assetElement: HTMLEleme
|
|||||||
click() {
|
click() {
|
||||||
nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
|
nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
|
||||||
assetElement.style.display = "";
|
assetElement.style.display = "";
|
||||||
|
if (!hasNextSibling(assetElement)) {
|
||||||
|
assetElement.insertAdjacentText("afterend", Constants.ZWSP);
|
||||||
|
}
|
||||||
updateTransaction(protyle, id, nodeElement.outerHTML, html);
|
updateTransaction(protyle, id, nodeElement.outerHTML, html);
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
|
@ -971,10 +971,13 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
|||||||
const oldHTML = nodeElement.outerHTML;
|
const oldHTML = nodeElement.outerHTML;
|
||||||
imgSelectElements.forEach((item: HTMLElement) => {
|
imgSelectElements.forEach((item: HTMLElement) => {
|
||||||
item.style.display = "";
|
item.style.display = "";
|
||||||
|
if (!hasNextSibling(item)) {
|
||||||
|
item.insertAdjacentText("afterend", Constants.ZWSP);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, oldHTML);
|
updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, oldHTML);
|
||||||
} else {
|
} else {
|
||||||
let selectElements:HTMLElement[] = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select"));
|
let selectElements: HTMLElement[] = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select"));
|
||||||
if (selectElements.length === 0) {
|
if (selectElements.length === 0) {
|
||||||
selectElements = [nodeElement];
|
selectElements = [nodeElement];
|
||||||
}
|
}
|
||||||
@ -992,10 +995,21 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
|||||||
const oldHTML = nodeElement.outerHTML;
|
const oldHTML = nodeElement.outerHTML;
|
||||||
imgSelectElements.forEach((item: HTMLElement) => {
|
imgSelectElements.forEach((item: HTMLElement) => {
|
||||||
item.style.display = "block";
|
item.style.display = "block";
|
||||||
|
let nextSibling = item.nextSibling;
|
||||||
|
while (nextSibling) {
|
||||||
|
if (nextSibling.textContent === "") {
|
||||||
|
nextSibling = nextSibling.nextSibling;
|
||||||
|
} else if (nextSibling.textContent === Constants.ZWSP) {
|
||||||
|
nextSibling.textContent = "";
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, oldHTML);
|
updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, oldHTML);
|
||||||
} else {
|
} else {
|
||||||
let selectElements:HTMLElement[] = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select"));
|
let selectElements: HTMLElement[] = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select"));
|
||||||
if (selectElements.length === 0) {
|
if (selectElements.length === 0) {
|
||||||
selectElements = [nodeElement];
|
selectElements = [nodeElement];
|
||||||
}
|
}
|
||||||
@ -1008,7 +1022,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (matchHotKey(window.siyuan.config.keymap.editor.general.alignRight.custom, event)) {
|
if (matchHotKey(window.siyuan.config.keymap.editor.general.alignRight.custom, event)) {
|
||||||
let selectElements:HTMLElement[] = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select"));
|
let selectElements: HTMLElement[] = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select"));
|
||||||
if (selectElements.length === 0) {
|
if (selectElements.length === 0) {
|
||||||
selectElements = [nodeElement];
|
selectElements = [nodeElement];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user