Make undo grouping interval configurable

This commit is contained in:
Max Brunsfeld
2014-11-06 09:25:10 -08:00
parent d85c07e7e2
commit d97c81bf6a
4 changed files with 22 additions and 6 deletions

View File

@@ -1925,14 +1925,26 @@ describe "TextEditorComponent", ->
expect(editor.lineTextForBufferRow(0)).toBe 'var quicksort = function () {'
it "groups events that occur close together in time into single undo entries", ->
currentTime = 0
spyOn(Date, 'now').andCallFake -> currentTime
atom.config.set('editor.undoGroupingInterval', 100)
editor.setText("")
componentNode.dispatchEvent(buildTextInputEvent(data: 'x', target: inputNode))
componentNode.dispatchEvent(buildTextInputEvent(data: 'y', target: inputNode))
componentNode.dispatchEvent(buildTextInputEvent(data: 'z', target: inputNode))
currentTime += 99
componentNode.dispatchEvent(buildTextInputEvent(data: 'y', target: inputNode))
currentTime += 99
componentNode.dispatchEvent(new CustomEvent('editor:duplicate-lines', bubbles: true, cancelable: true))
expect(editor.getText()).toBe "xyz\nxyz"
currentTime += 100
componentNode.dispatchEvent(new CustomEvent('editor:duplicate-lines', bubbles: true, cancelable: true))
expect(editor.getText()).toBe "xy\nxy\nxy"
componentNode.dispatchEvent(new CustomEvent('core:undo', bubbles: true, cancelable: true))
expect(editor.getText()).toBe "xy\nxy"
componentNode.dispatchEvent(new CustomEvent('core:undo', bubbles: true, cancelable: true))
expect(editor.getText()).toBe ""

View File

@@ -105,6 +105,11 @@ module.exports =
scrollPastEnd:
type: 'boolean'
default: false
undoGroupingInterval:
type: 'integer'
default: 500
minimum: 0
description: 'Time interval in milliseconds within which operations will be grouped in the undo history'
useHardwareAcceleration:
type: 'boolean'
default: true

View File

@@ -21,7 +21,6 @@ TextEditorComponent = React.createClass
statics:
performSyncUpdates: false
groupingInterval: 500
visible: false
autoHeight: false
@@ -458,7 +457,7 @@ TextEditorComponent = React.createClass
selectedLength = inputNode.selectionEnd - inputNode.selectionStart
editor.selectLeft() if selectedLength is 1
insertedRange = editor.transact @constructor.groupingInterval, ->
insertedRange = editor.transact atom.config.get('editor.undoGroupingInterval'), ->
editor.insertText(event.data)
inputNode.value = event.data if insertedRange

View File

@@ -150,7 +150,7 @@ stopEventPropagationAndGroupUndo = (commandListeners) ->
newCommandListeners[commandName] = (event) ->
event.stopPropagation()
model = @getModel()
model.transact TextEditorComponent.groupingInterval, ->
model.transact atom.config.get('editor.undoGroupingInterval'), ->
commandListener.call(model, event)
newCommandListeners