Remove TextEditor::withGroupingInterval

Just use ::transact
This commit is contained in:
Max Brunsfeld
2014-11-05 14:35:09 -08:00
parent 5437236304
commit e7eef89fa5
4 changed files with 13 additions and 48 deletions

View File

@@ -2816,36 +2816,6 @@ describe "TextEditor", ->
editor.redo()
expect(editor.getSelectedBufferRanges()).toEqual [[[1, 6], [1, 6]], [[1, 18], [1, 18]]]
describe ".withGroupingInterval(interval)", ->
currentTime = null
beforeEach ->
currentTime = 0
spyOn(Date, 'now').andCallFake -> currentTime
it "allows undo entries to be grouped", ->
buffer.setText("")
editor.withGroupingInterval 200, ->
editor.insertText("1")
currentTime += 199
editor.insertText("2")
currentTime += 199
editor.insertText("3")
currentTime += 200
editor.insertText("4")
expect(buffer.getText()).toBe "1234"
editor.undo()
expect(buffer.getText()).toBe "123"
editor.undo()
expect(buffer.getText()).toBe ""
xit "restores folds after undo and redo", ->
editor.foldBufferRow(1)
editor.setSelectedBufferRange([[1, 0], [10, Infinity]], preserveFolds: true)

View File

@@ -458,8 +458,9 @@ TextEditorComponent = React.createClass
selectedLength = inputNode.selectionEnd - inputNode.selectionStart
editor.selectLeft() if selectedLength is 1
insertedRange = editor.withGroupingInterval @constructor.groupingInterval, ->
insertedRange = editor.transact(->
editor.insertText(event.data)
, @constructor.groupingInterval)
inputNode.value = event.data if insertedRange
onVerticalScroll: (scrollTop) ->

View File

@@ -141,8 +141,9 @@ editorEventListeners = (commandListeners) ->
newCommandListeners[commandName] = (event) ->
event.stopPropagation()
model = @getModel()
model.withGroupingInterval TextEditorComponent.groupingInterval, ->
model.transact(->
commandListener.call(model, event)
, TextEditorComponent.groupingInterval)
newCommandListeners
atom.commands.add 'atom-text-editor', editorEventListeners(

View File

@@ -68,7 +68,6 @@ class TextEditor extends Model
suppressSelectionMerging: false
updateBatchDepth: 0
selectionFlashDuration: 500
groupingInterval: 0
@delegatesMethods 'suggestedIndentForBufferRow', 'autoIndentBufferRow', 'autoIndentBufferRows',
'autoDecreaseIndentForBufferRow', 'toggleLineCommentForBufferRow', 'toggleLineCommentsForBufferRows',
@@ -1098,7 +1097,9 @@ class TextEditor extends Model
# execution and revert any changes performed up to the abortion.
#
# * `fn` A {Function} to call inside the transaction.
transact: (fn) -> @buffer.transact(fn, @groupingInterval)
# * `groupingInterval` This is the sames as the `groupingInterval` parameter
# in {::beginTransaction}
transact: (fn, groupingInterval) -> @buffer.transact(fn, groupingInterval)
# Extended: Start an open-ended transaction.
#
@@ -1106,7 +1107,12 @@ class TextEditor extends Model
# transaction. If you nest calls to transactions, only the outermost
# transaction is considered. You must match every begin with a matching
# commit, but a single call to abort will cancel all nested transactions.
beginTransaction: -> @buffer.beginTransaction(@groupingInterval)
#
# * `groupingInterval` (optional) The {Number} of milliseconds for which this
# transaction should be considered 'groupable' after it begins. If a transaction
# with a positive `groupingInterval` is committed while the previous transaction is
# still 'groupable', the two transactions are merged with respect to undo and redo.
beginTransaction: (groupingInterval) -> @buffer.beginTransaction(groupingInterval)
# Extended: Commit an open-ended transaction started with {::beginTransaction}
# and push it to the undo stack.
@@ -1118,19 +1124,6 @@ class TextEditor extends Model
# within the transaction.
abortTransaction: -> @buffer.abortTransaction()
# Extended: Set the time interval over which undo/redo operations are grouped.
#
# * `interval` A {Number} of milliseconds within which operations should be
# grouped with respec to undo/redo
# * `fn` A {Function} to call with the given interval setting
withGroupingInterval: (interval, fn) ->
previousInterval = @groupingInterval
@groupingInterval = interval
try
fn()
finally
@groupingInterval = previousInterval
###
Section: TextEditor Coordinates
###