From 64dd9a2448b999887e17171ceafaade0ddd4af85 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 20 Oct 2017 14:13:03 +0200 Subject: [PATCH] Don't watch editors more than once if they're re-added to the workspace --- lib/whitespace.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/whitespace.js b/lib/whitespace.js index 92defde..c3ec304 100644 --- a/lib/whitespace.js +++ b/lib/whitespace.js @@ -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 => { @@ -69,6 +70,8 @@ module.exports = class Whitespace { } handleEvents (editor) { + if (this.watchedEditors.has(editor)) return + let buffer = editor.getBuffer() let bufferSavedSubscription = buffer.onWillSave(() => { @@ -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) {