Skip to content

Commit

Permalink
fix #304
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Apr 11, 2020
1 parent ad9a066 commit c6123ec
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/ts/ir/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {expandMarker} from "./expandMarker";
import {highlightToolbar} from "./highlightToolbar";
import {input} from "./input";
import {processAfterRender, processHint} from "./process";
import {hidePanel} from "../toolbar/setToolbar";

class IR {
public element: HTMLPreElement;
Expand Down Expand Up @@ -39,7 +40,7 @@ class IR {

private bindEvent(vditor: IVditor) {
this.element.addEventListener("scroll", () => {
vditor.hint.element.style.display = "none";
hidePanel(vditor, ["hint", "headings", "emoji", "edit-mode"]);
});

this.element.addEventListener("copy", (event: ClipboardEvent & { target: HTMLElement }) => {
Expand Down
3 changes: 2 additions & 1 deletion src/ts/sv/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {getSelectText} from "./getSelectText";
import {html2md} from "./html2md";
import {inputEvent} from "./inputEvent";
import {insertText} from "./insertText";
import {hidePanel} from "../toolbar/setToolbar";

class Editor {
public element: HTMLPreElement;
Expand Down Expand Up @@ -61,7 +62,7 @@ class Editor {
});

this.element.addEventListener("scroll", () => {
vditor.hint.element.style.display = "none";
hidePanel(vditor, ["hint", "headings", "emoji", "edit-mode"]);
if (!vditor.preview || (vditor.preview && vditor.preview.element.style.display === "none")) {
return;
}
Expand Down
27 changes: 19 additions & 8 deletions src/ts/wysiwyg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,25 @@ class WYSIWYG {
});
}

this.element.addEventListener("scroll", () => {
hidePanel(vditor, ["hint", "headings", "emoji", "edit-mode"]);
if (this.popover.style.display !== "block") {
return;
}
const top = parseInt(this.popover.getAttribute("data-top"), 10) - vditor.wysiwyg.element.scrollTop;
this.popover.style.top = Math.max(-8, Math.min(top, this.element.clientHeight - 21)) + "px";
});
if (vditor.options.typewriterMode) {
window.addEventListener("scroll", () => {
hidePanel(vditor, ["hint", "headings", "emoji", "edit-mode"]);
if (this.popover.style.display !== "block") {
return;
}
const top = parseInt(this.popover.getAttribute("data-top"), 10);
this.popover.style.top = Math.max(top, (window.scrollY - vditor.element.offsetTop - 8)) + "px";
});
} else {
this.element.addEventListener("scroll", () => {
hidePanel(vditor, ["hint", "headings", "emoji", "edit-mode"]);
if (this.popover.style.display !== "block") {
return;
}
const top = parseInt(this.popover.getAttribute("data-top"), 10) - vditor.wysiwyg.element.scrollTop;
this.popover.style.top = Math.max(-8, Math.min(top, this.element.clientHeight - 21)) + "px";
});
}

this.element.addEventListener("copy", (event: ClipboardEvent & { target: HTMLElement }) => {
const range = getSelection().getRangeAt(0);
Expand Down

0 comments on commit c6123ec

Please sign in to comment.