From 5167dbca6fd5432f6804cc9eab02c26c08b4c7cc Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 11 Jul 2016 17:47:40 -0700 Subject: [PATCH] Move handling of undoGroupingInterval to TextEditorRegistry --- spec/text-editor-component-spec.js | 2 +- spec/text-editor-registry-spec.js | 11 +++++++++++ src/text-editor-registry.js | 1 + src/text-editor.coffee | 7 ++++++- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/spec/text-editor-component-spec.js b/spec/text-editor-component-spec.js index 83f5d1b80..4685f6226 100644 --- a/spec/text-editor-component-spec.js +++ b/spec/text-editor-component-spec.js @@ -3909,7 +3909,7 @@ describe('TextEditorComponent', function () { spyOn(Date, 'now').andCallFake(function () { return currentTime }) - atom.config.set('editor.undoGroupingInterval', 100) + editor.setUndoGroupingInterval(100) editor.setText('') componentNode.dispatchEvent(buildTextInputEvent({ data: 'x', diff --git a/spec/text-editor-registry-spec.js b/spec/text-editor-registry-spec.js index a53820277..985f9b0a9 100644 --- a/spec/text-editor-registry-spec.js +++ b/spec/text-editor-registry-spec.js @@ -383,5 +383,16 @@ describe('TextEditorRegistry', function () { atom.config.set('editor.scrollPastEnd', true) expect(editor.getScrollPastEnd()).toBe(true) }) + + it('sets the undo grouping interval based on the config', function () { + expect(editor.getUndoGroupingInterval()).toBe(300) + + atom.config.set('editor.undoGroupingInterval', 600) + registry.maintainConfig(editor) + expect(editor.getUndoGroupingInterval()).toBe(600) + + atom.config.set('editor.undoGroupingInterval', 300) + expect(editor.getUndoGroupingInterval()).toBe(300) + }) }) }) diff --git a/src/text-editor-registry.js b/src/text-editor-registry.js index e59aa2c4a..082aa5f28 100644 --- a/src/text-editor-registry.js +++ b/src/text-editor-registry.js @@ -17,6 +17,7 @@ const EDITOR_SETTER_NAMES_BY_SETTING_KEY = [ ['editor.autoIndent', 'setAutoIndent'], ['editor.autoIndentOnPaste', 'setAutoIndentOnPaste'], ['editor.scrollPastEnd', 'setScrollPastEnd'], + ['editor.undoGroupingInterval', 'setUndoGroupingInterval'], ] // Experimental: This global registry tracks registered `TextEditors`. diff --git a/src/text-editor.coffee b/src/text-editor.coffee index bc69db8ce..71631bffc 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -153,6 +153,7 @@ class TextEditor extends Model @backUpBeforeSaving ?= false @autoIndent ?= true @autoIndentOnPaste ?= true + @undoGroupingInterval ?= 300 @buffer ?= new TextBuffer @tokenizedBuffer ?= new TokenizedBuffer({ @@ -898,7 +899,7 @@ class TextEditor extends Model return false unless @emitWillInsertTextEvent(text) groupingInterval = if options.groupUndo - @config.get('editor.undoGroupingInterval') + @undoGroupingInterval else 0 @@ -3339,6 +3340,10 @@ class TextEditor extends Model getScrollPastEnd: -> @scrollPastEnd + setUndoGroupingInterval: (@undoGroupingInterval) -> + + getUndoGroupingInterval: -> @undoGroupingInterval + ### Section: Event Handlers ###