Move handling of undoGroupingInterval to TextEditorRegistry

This commit is contained in:
Max Brunsfeld
2016-07-11 17:47:40 -07:00
parent 9ab474a673
commit 5167dbca6f
4 changed files with 19 additions and 2 deletions

View File

@@ -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',

View File

@@ -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)
})
})
})

View File

@@ -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`.

View File

@@ -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
###