mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Merge pull request #6960 from atom/mb-remove-double-transaction
Avoid double transaction when typing
This commit is contained in:
@@ -309,8 +309,7 @@ class TextEditorComponent
|
||||
selectedLength = inputNode.selectionEnd - inputNode.selectionStart
|
||||
@editor.selectLeft() if selectedLength is 1
|
||||
|
||||
insertedRange = @editor.transact atom.config.get('editor.undoGroupingInterval'), =>
|
||||
@editor.insertText(event.data)
|
||||
insertedRange = @editor.insertText(event.data, groupUndo: true)
|
||||
inputNode.value = event.data if insertedRange
|
||||
|
||||
onVerticalScroll: (scrollTop) =>
|
||||
|
||||
@@ -761,15 +761,23 @@ class TextEditor extends Model
|
||||
@emit('will-insert-text', willInsertEvent) if includeDeprecatedAPIs
|
||||
@emitter.emit 'will-insert-text', willInsertEvent
|
||||
|
||||
groupingInterval = if options.groupUndo
|
||||
atom.config.get('editor.undoGroupingInterval')
|
||||
else
|
||||
0
|
||||
|
||||
if willInsert
|
||||
options.autoIndentNewline ?= @shouldAutoIndent()
|
||||
options.autoDecreaseIndent ?= @shouldAutoIndent()
|
||||
@mutateSelectedText (selection) =>
|
||||
range = selection.insertText(text, options)
|
||||
didInsertEvent = {text, range}
|
||||
@emit('did-insert-text', didInsertEvent) if includeDeprecatedAPIs
|
||||
@emitter.emit 'did-insert-text', didInsertEvent
|
||||
range
|
||||
@mutateSelectedText(
|
||||
(selection) =>
|
||||
range = selection.insertText(text, options)
|
||||
didInsertEvent = {text, range}
|
||||
@emit('did-insert-text', didInsertEvent) if includeDeprecatedAPIs
|
||||
@emitter.emit 'did-insert-text', didInsertEvent
|
||||
range
|
||||
, groupingInterval
|
||||
)
|
||||
else
|
||||
false
|
||||
|
||||
@@ -795,9 +803,9 @@ class TextEditor extends Model
|
||||
# * `fn` A {Function} that will be called once for each {Selection}. The first
|
||||
# argument will be a {Selection} and the second argument will be the
|
||||
# {Number} index of that selection.
|
||||
mutateSelectedText: (fn) ->
|
||||
mutateSelectedText: (fn, groupingInterval=0) ->
|
||||
@mergeIntersectingSelections =>
|
||||
@transact =>
|
||||
@transact groupingInterval, =>
|
||||
fn(selection, index) for selection, index in @getSelectionsOrderedByBufferPosition()
|
||||
|
||||
# Move lines intersection the most recent selection up by one row in screen
|
||||
|
||||
Reference in New Issue
Block a user