Skip to content

Commit

Permalink
🚨 #1089
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Oct 13, 2021
1 parent 0b6fc30 commit 9e6be85
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@

### v3.8.8 / 2021-10-xx

* [1089](https://github.com/Vanessa219/vditor/pull/1089) 解决内存泄漏问题 `开发重构`

### v3.8.7 / 2021-09-21

* [1049](https://github.com/Vanessa219/vditor/issues/1049) #后面没有空格也会渲染为标题 `修复缺陷`
Expand Down
14 changes: 8 additions & 6 deletions src/ts/ui/initUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const initUI = (vditor: IVditor) => {
'<iframe style="width: 100%;height: 0;border: 0"></iframe>');
}

setEditMode(vditor, vditor.options.mode, afterRender(vditor, contentElement));
setEditMode(vditor, vditor.options.mode, afterRender(vditor));

document.execCommand("DefaultParagraphSeparator", false, "p");

Expand Down Expand Up @@ -141,13 +141,15 @@ export const setTypewriterPosition = (vditor: IVditor) => {
((height - vditor.toolbar.element.offsetHeight) / 2) + "px");
};

let resizeCb = () => {}
export function UIUnbindListener () {
window.removeEventListener("resize", resizeCb)
let resizeCb: () => void;

export function UIUnbindListener() {
window.removeEventListener("resize", resizeCb);
}
const afterRender = (vditor: IVditor, contentElement: HTMLElement) => {

const afterRender = (vditor: IVditor) => {
setTypewriterPosition(vditor);
UIUnbindListener()
UIUnbindListener();
window.addEventListener("resize", resizeCb = () => {
setPadding(vditor);
setTypewriterPosition(vditor);
Expand Down
14 changes: 7 additions & 7 deletions src/ts/wysiwyg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class WYSIWYG {
public preventInput: boolean;
public composingLock = false;
public commentIds: string[] = [];
private scrollListener: () => void;

constructor(vditor: IVditor) {
const divElement = document.createElement("div");
Expand Down Expand Up @@ -195,6 +196,10 @@ class WYSIWYG {
this.selectPopover.setAttribute("style", "display:none");
}

public unbindListener() {
window.removeEventListener("scroll", this.scrollListener);
}

private copy(event: ClipboardEvent, vditor: IVditor) {
const range = getSelection().getRangeAt(0);
if (range.toString() === "") {
Expand Down Expand Up @@ -237,14 +242,9 @@ class WYSIWYG {
event.clipboardData.setData("text/html", "");
}

private scrollListener = () => {};
public unbindListener() {
window.removeEventListener("scroll", this.scrollListener)
}

private bindEvent(vditor: IVditor) {
this.unbindListener();
window.addEventListener("scroll", this.scrollListener = () => {
window.addEventListener("scroll", this.scrollListener = () => {
hidePanel(vditor, ["hint"]);
if (this.popover.style.display !== "block" || this.selectPopover.style.display !== "block") {
return;
Expand Down Expand Up @@ -337,7 +337,7 @@ class WYSIWYG {
this.preventInput = false;
return;
}
if (this.composingLock || event.data === "‘" || event.data === "“" || event.data === "《") {
if (this.composingLock || event.data === "‘" || event.data === "“" || event.data === "《") {
return;
}
const range = getSelection().getRangeAt(0);
Expand Down
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ interface IVditor {
triggerRemoveComment(vditor: IVditor): void,
showComment(): void,
hideComment(): void,
unbindListener(): void
unbindListener(): void,
};
ir?: {
range: Range,
Expand Down

0 comments on commit 9e6be85

Please sign in to comment.