Navigation Menu

Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Don't watch editors more than once if they're re-added to the workspace #165

Merged
merged 1 commit into from Oct 21, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/whitespace.js
Expand Up @@ -4,6 +4,7 @@ const TRAILING_WHITESPACE_REGEX = /[ \t]+(?=\r?$)/g

module.exports = class Whitespace {
constructor () {
this.watchedEditors = new WeakSet()
this.subscriptions = new CompositeDisposable()

this.subscriptions.add(atom.workspace.observeTextEditors(editor => {
Expand Down Expand Up @@ -69,6 +70,8 @@ module.exports = class Whitespace {
}

handleEvents (editor) {
if (this.watchedEditors.has(editor)) return

let buffer = editor.getBuffer()

let bufferSavedSubscription = buffer.onWillSave(() => {
Expand Down Expand Up @@ -116,11 +119,13 @@ module.exports = class Whitespace {
this.subscriptions.remove(bufferSavedSubscription)
this.subscriptions.remove(editorTextInsertedSubscription)
this.subscriptions.remove(editorDestroyedSubscription)
this.watchedEditors.delete(editor)
})

this.subscriptions.add(bufferSavedSubscription)
this.subscriptions.add(editorTextInsertedSubscription)
this.subscriptions.add(editorDestroyedSubscription)
this.watchedEditors.add(editor)
}

removeTrailingWhitespace (editor, grammarScopeName) {
Expand Down