This commit is contained in:
Vanessa 2022-12-26 20:13:36 +08:00
parent e22573b4eb
commit f53c2fdebd
3 changed files with 19 additions and 5 deletions

View file

@ -89,7 +89,7 @@ export const hintSlash = (key: string, protyle: IProtyle) => {
html: `<div class="b3-list-item__first"><svg class="b3-list-item__graphic"><use xlink:href="#iconCode"></use></svg><span class="b3-list-item__text">${window.siyuan.languages.code}</span><span class="b3-menu__accelerator">\`\`\`Enter</span></div>`,
}, {
filter: ["表格", "biaoge", "bg", "table"],
value: `| col1${Lute.Caret} | col2 | col3 |\n| --- | --- | --- |\n| | | |\n| | | |`,
value: `| ${Lute.Caret} | | |\n| --- | --- | --- |\n| | | |\n| | | |`,
html: `<div class="b3-list-item__first"><svg class="b3-list-item__graphic"><use xlink:href="#iconTable"></use></svg><span class="b3-list-item__text">${window.siyuan.languages.table}</span><span class="b3-menu__accelerator">${updateHotkeyTip((window.siyuan.config.keymap.editor.insert.table.custom))}</span></div>`,
}, {
filter: ["分割线", "fengexian", "fgx", "divider"],

View file

@ -590,6 +590,13 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
}
nodeElement.outerHTML = newHTML;
nodeElement = protyle.wysiwyg.element.querySelector(`[data-node-id="${id}"]`);
// https://github.com/siyuan-note/siyuan/issues/6864
if (nodeElement.getAttribute("data-type") === "NodeTable") {
nodeElement.querySelectorAll("colgroup col").forEach((item: HTMLElement) => {
item.style.width = "80px";
});
newHTML = nodeElement.outerHTML;
}
updateTransaction(protyle, id, newHTML, html);
} else {
let newHTML = protyle.lute.SpinBlockDOM(textContent);
@ -597,13 +604,21 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
newHTML = `<div data-node-id="${Lute.NewNodeID()}" data-type="NodeHTMLBlock" class="render-node" data-subtype="block"><div class="protyle-icons"><span class="protyle-icon protyle-icon--first protyle-action__edit"><svg><use xlink:href="#iconEdit"></use></svg></span><span class="protyle-icon protyle-action__menu protyle-icon--last"><svg><use xlink:href="#iconMore"></use></svg></span></div><div><protyle-html data-content=""></protyle-html><span style="position: absolute">${Constants.ZWSP}</span></div><div class="protyle-attr" contenteditable="false"></div></div>`;
}
nodeElement.insertAdjacentHTML("afterend", newHTML);
const oldHTML = nodeElement.outerHTML;
const newId = newHTML.substr(newHTML.indexOf('data-node-id="') + 14, 22);
nodeElement = protyle.wysiwyg.element.querySelector(`[data-node-id="${newId}"]`);
// https://github.com/siyuan-note/siyuan/issues/6864
if (nodeElement.getAttribute("data-type") === "NodeTable") {
nodeElement.querySelectorAll("colgroup col").forEach((item: HTMLElement) => {
item.style.width = "80px";
});
}
transaction(protyle, [{
data: nodeElement.outerHTML,
data: oldHTML,
id,
action: "update"
}, {
data: newHTML,
data: nodeElement.outerHTML,
id: newId,
previousID: id,
action: "insert"
@ -615,7 +630,6 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
id,
action: "update"
}]);
nodeElement = protyle.wysiwyg.element.querySelector(`[data-node-id="${newId}"]`);
}
if (value === "<div>" || value === "$$" || (value.indexOf("```") > -1 && value.length > 3)) {
protyle.toolbar.showRender(protyle, nodeElement);

View file

@ -1330,7 +1330,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
if (matchHotKey(window.siyuan.config.keymap.editor.insert.table.custom, event)) {
protyle.hint.splitChar = "/";
protyle.hint.lastIndex = -1;
protyle.hint.fill(`| col1${Lute.Caret} | col2 | col3 |\n| --- | --- | --- |\n| | | |\n| | | |`, protyle);
protyle.hint.fill(`| ${Lute.Caret} | | |\n| --- | --- | --- |\n| | | |\n| | | |`, protyle);
event.preventDefault();
event.stopPropagation();
return;