♻️ set inline type

This commit is contained in:
Vanessa 2022-09-26 00:14:09 +08:00
parent eae9991e7b
commit f4c1687d4d
6 changed files with 19 additions and 8 deletions

View file

@ -49,7 +49,7 @@ export const initBlockPopover = () => {
}
let popoverTargetElement = hasClosestByAttribute(event.target, "data-type", "block-ref") as HTMLElement ||
hasClosestByAttribute(event.target, "data-type", "virtual-block-ref") as HTMLElement;
if (popoverTargetElement && popoverTargetElement.classList.contains("protyle-toolbar")) {
if (popoverTargetElement && popoverTargetElement.classList.contains("b3-tooltips")) {
popoverTargetElement = undefined;
}
if (!popoverTargetElement) {
@ -107,7 +107,7 @@ export const initBlockPopover = () => {
}
let popoverTargetElement = hasClosestByAttribute(event.target, "data-type", "block-ref") as HTMLElement ||
hasClosestByAttribute(event.target, "data-type", "virtual-block-ref") as HTMLElement;
if (popoverTargetElement && popoverTargetElement.classList.contains("protyle-toolbar")) {
if (popoverTargetElement && popoverTargetElement.classList.contains("b3-tooltips")) {
popoverTargetElement = undefined;
}
if (!popoverTargetElement) {

View file

@ -31,6 +31,7 @@ import {openFileById} from "../../editor/util";
import {openMobileFileById} from "../../mobile/editor";
import {getIconByType} from "../../editor/getIcon";
import {processRender} from "../util/processCode";
import {getEventName} from "../util/compatibility";
export class Hint {
public timeId: number;
@ -245,7 +246,7 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
}
if (hasSearch) {
const searchElement = this.element.querySelector("input.b3-text-field") as HTMLInputElement;
const oldValue = this.element.querySelector("mark").textContent;
const oldValue = this.element.querySelector("mark")?.textContent || "";
searchElement.value = oldValue;
searchElement.select();
searchElement.addEventListener("keydown", (event: KeyboardEvent) => {
@ -531,6 +532,10 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
range.deleteContents();
focusByRange(range);
protyle.toolbar.range = range;
if (["a", "block-ref", "inline-math", "inline-memo", "text"].includes(value)) {
protyle.toolbar.element.querySelector(`[data-type="${value}"]`).dispatchEvent(new CustomEvent("block-ref" === value? getEventName() : "click"));
return;
}
protyle.toolbar.setInlineMark(protyle, value, "range");
return;
} else if (value === "emoji") {

View file

@ -9,6 +9,9 @@ export class BlockRef extends ToolbarItem {
super(protyle, menuItem);
// 不能用 getEventName否则会导致光标位置变动到点击的文档中
this.element.addEventListener("click", (event: MouseEvent & { changedTouches: MouseEvent[] }) => {
if (protyle.toolbar.range.toString() === "") {
return;
}
fixTableRange(protyle.toolbar.range);
hintRef(protyle.toolbar.range.toString(), protyle, true);
protyle.toolbar.element.classList.add("fn__none");

View file

@ -11,6 +11,9 @@ export class Font extends ToolbarItem {
constructor(protyle: IProtyle, menuItem: IMenuItem) {
super(protyle, menuItem);
this.element.addEventListener(getEventName(), () => {
if (protyle.toolbar.range.toString() === "") {
return;
}
protyle.toolbar.element.classList.add("fn__none");
protyle.toolbar.subElement.innerHTML = "";
protyle.toolbar.subElement.style.width = "";

View file

@ -237,10 +237,6 @@ export class Toolbar {
}
public setInlineMark(protyle: IProtyle, type: string, action: "range" | "toolbar", textObj?: ITextOption) {
if (["a", "block-ref", "inline-math", "inline-memo"].includes(type) || (type === "text" && !textObj)) {
protyle.toolbar.element.querySelector(`[data-type="${type}"]`).dispatchEvent(new CustomEvent("block-ref" === type ? getEventName() : "click"));
return;
}
const nodeElement = hasClosestBlock(this.range.startContainer);
if (!nodeElement) {
return;

View file

@ -1,5 +1,5 @@
import {hideElements} from "../ui/hideElements";
import {isCtrl, isMac, writeText} from "../util/compatibility";
import {getEventName, isCtrl, isMac, writeText} from "../util/compatibility";
import {
focusBlock,
focusByRange,
@ -1197,6 +1197,10 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
}
if (matchHotKey(menuItem.hotkey, event)) {
protyle.toolbar.range = getEditorRange(protyle.wysiwyg.element);
if (["a", "block-ref", "inline-math", "inline-memo", "text"].includes(menuItem.name)) {
protyle.toolbar.element.querySelector(`[data-type="${menuItem.name}"]`).dispatchEvent(new CustomEvent("block-ref" === menuItem.name ? getEventName() : "click"));
return true;
}
protyle.toolbar.setInlineMark(protyle, menuItem.name, "range");
return true;
}