Skip to content

Commit

Permalink
🎨 Vanessa219#27 emoji
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 authored and stevapple committed Apr 8, 2020
1 parent 0d5f7e2 commit 1f5122c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/ts/toolbar/EditMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ export const setEditMode = (vditor: IVditor, type: string, event?: Event) => {
}
const allToolbar = ["emoji", "headings", "bold", "italic", "strike", "link", "list", "ordered-list", "check",
"line", "quote", "code", "inline-code", "upload", "record", "table"];
enableToolbar(vditor.toolbar.elements, allToolbar);
removeCurrentToolbar(vditor.toolbar.elements, allToolbar);

if (type === "ir") {
hideToolbar(vditor.toolbar.elements, ["format", "both", "preview"]);
disableToolbar(vditor.toolbar.elements, allToolbar);
disableToolbar(vditor.toolbar.elements, ["headings", "bold", "italic", "strike", "link", "list", "ordered-list", "check",
"line", "quote", "code", "inline-code", "upload", "record", "table"]);
vditor.irUndo.resetIcon(vditor);
vditor.sv.element.style.display = "none";
vditor.preview.element.style.display = "none";
Expand All @@ -54,7 +57,6 @@ export const setEditMode = (vditor: IVditor, type: string, event?: Event) => {
});
} else if (type === "wysiwyg") {
hideToolbar(vditor.toolbar.elements, ["format", "both", "preview"]);
enableToolbar(vditor.toolbar.elements, allToolbar);
vditor.wysiwygUndo.resetIcon(vditor);
vditor.sv.element.style.display = "none";
vditor.preview.element.style.display = "none";
Expand All @@ -72,8 +74,6 @@ export const setEditMode = (vditor: IVditor, type: string, event?: Event) => {
setPadding(vditor);
} else if (type === "sv") {
showToolbar(vditor.toolbar.elements, ["format", "both", "preview"]);
enableToolbar(vditor.toolbar.elements, allToolbar);
removeCurrentToolbar(vditor.toolbar.elements, allToolbar);
vditor.undo.resetIcon(vditor);
vditor.wysiwyg.element.parentElement.style.display = "none";
vditor.ir.element.parentElement.style.display = "none";
Expand Down
23 changes: 17 additions & 6 deletions src/ts/toolbar/Emoji.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,30 @@ data-value=":${key}: " data-key=":${key}:" class="vditor-emojis__icon" src="${em
element.addEventListener(getEventName(), (event: Event) => {
event.preventDefault();
const value = element.getAttribute("data-value");
if (vditor.currentMode === "wysiwyg") {
const range = getEditorRange(vditor.wysiwyg.element);
if (vditor.currentMode === "sv") {
insertText(vditor, value, "", true);
} else {
let range;
let html = "";
if (vditor.currentMode === "wysiwyg") {
range = getEditorRange(vditor.wysiwyg.element);
html = vditor.lute.SpinVditorDOM(value);
} else if (vditor.currentMode === "ir") {
range = getEditorRange(vditor.ir.element);
html = vditor.lute.SpinVditorIRDOM(value);
}
if (value.indexOf(":") > -1) {
insertHTML(vditor.lute.SpinVditorDOM(value), vditor);
range.insertNode(document.createTextNode(" "));
const tempElement = document.createElement("div");
tempElement.innerHTML = html;
html = tempElement.firstElementChild.firstElementChild.outerHTML + " ";
insertHTML(html, vditor);
} else {
range.insertNode(document.createTextNode(value));
}
range.collapse(false);
setSelectionFocus(range);
} else {
insertText(vditor, value, "", true);
}

this.panelElement.style.display = "none";
});
element.addEventListener("mouseover", (event: Event) => {
Expand Down
7 changes: 6 additions & 1 deletion src/ts/util/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,12 @@ export const insertHTML = (html: string, vditor: IVditor) => {
const pasteElement = document.createElement("template");
pasteElement.innerHTML = html;

const range = getSelection().getRangeAt(0);
let range;
if (vditor.currentMode === "wysiwyg") {
range = getEditorRange(vditor.wysiwyg.element);
} else if (vditor.currentMode === "ir") {
range = getEditorRange(vditor.ir.element);
}
if (range.toString() !== "") {
if (vditor.currentMode === "wysiwyg") {
vditor.wysiwyg.preventInput = true;
Expand Down

0 comments on commit 1f5122c

Please sign in to comment.