Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix memory leak in electron #451

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions src/editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
this.initialize()
},
beforeDestroy() {
this.quill.off('selection-change', this.handleSelectionChange)
this.quill.off('text-change', this.handleTextChange)
this.quill = null
delete this.quill
},
Expand Down Expand Up @@ -119,28 +121,32 @@
}

// Mark model as touched if editor lost focus
this.quill.on('selection-change', range => {
if (!range) {
this.$emit('blur', this.quill)
} else {
this.$emit('focus', this.quill)
}
})
this.quill.on('selection-change', this.handleSelectionChange)

// Update model if text changes
this.quill.on('text-change', (delta, oldDelta, source) => {
let html = this.$refs.editor.children[0].innerHTML
const quill = this.quill
const text = this.quill.getText()
if (html === '<p><br></p>') html = ''
this._content = html
this.$emit('input', this._content)
this.$emit('change', { html, text, quill })
})
this.quill.on('text-change', this.handleTextChange)

// Emit ready event
this.$emit('ready', this.quill)
}
},
// handle selection-change
handleSelectionChange(range) {
if (!range) {
this.$emit('blur', this.quill)
} else {
this.$emit('focus', this.quill)
}
},
// handle text-change
handleTextChange(delta, oldDelta, source) {
let html = this.$refs.editor.children[0].innerHTML
const quill = this.quill
const text = this.quill.getText()
if (html === '<p><br></p>') html = ''
this._content = html
this.$emit('input', this._content)
this.$emit('change', { html, text, quill })
}
},
watch: {
Expand Down