mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Only auto-indent when typing, not when pasting or programmatically inserting
This paves the way for using a different strategy to normalize indentation when pasting, without it getting tangled in auto-indent.
This commit is contained in:
@@ -142,7 +142,7 @@ class EditSession
|
||||
@mutateSelectedText (selection) -> selection.insertText(text, options)
|
||||
|
||||
insertNewline: ->
|
||||
@insertText('\n')
|
||||
@insertText('\n', autoIndent: true)
|
||||
|
||||
insertNewlineBelow: ->
|
||||
@moveCursorToEndOfLine()
|
||||
|
||||
@@ -214,7 +214,7 @@ class Editor extends View
|
||||
deleteToEndOfWord: -> @activeEditSession.deleteToEndOfWord()
|
||||
deleteLine: -> @activeEditSession.deleteLine()
|
||||
cutToEndOfLine: -> @activeEditSession.cutToEndOfLine()
|
||||
insertText: (text) -> @activeEditSession.insertText(text)
|
||||
insertText: (text, options) -> @activeEditSession.insertText(text, options)
|
||||
insertNewline: -> @activeEditSession.insertNewline()
|
||||
insertNewlineBelow: -> @activeEditSession.insertNewlineBelow()
|
||||
indent: -> @activeEditSession.indent()
|
||||
@@ -327,7 +327,7 @@ class Editor extends View
|
||||
@selectOnMousemoveUntilMouseup()
|
||||
|
||||
@on "textInput", (e) =>
|
||||
@insertText(e.originalEvent.data)
|
||||
@insertText(e.originalEvent.data, autoIndent: true)
|
||||
false
|
||||
|
||||
@scrollView.on 'mousewheel', (e) =>
|
||||
|
||||
@@ -141,16 +141,9 @@ class Selection
|
||||
newBufferRange = @editSession.buffer.change(oldBufferRange, text)
|
||||
@cursor.setBufferPosition(newBufferRange.end, skipAtomicTokens: true) if wasReversed
|
||||
|
||||
autoIndent = options.autoIndent ? true
|
||||
|
||||
if @editSession.autoIndent and autoIndent
|
||||
if /\n/.test(text)
|
||||
firstLinePrefix = @editSession.getTextInBufferRange([[newBufferRange.start.row, 0], newBufferRange.start])
|
||||
if /^\s*$/.test(firstLinePrefix)
|
||||
@editSession.autoIncreaseIndentForBufferRow(newBufferRange.start.row)
|
||||
|
||||
if newBufferRange.getRowCount() > 1
|
||||
@editSession.autoIndentBufferRows(newBufferRange.start.row + 1, newBufferRange.end.row)
|
||||
if @editSession.autoIndent and options.autoIndent
|
||||
if text == '\n'
|
||||
@editSession.autoIndentBufferRow(newBufferRange.end.row)
|
||||
else
|
||||
@editSession.autoDecreaseIndentForRow(newBufferRange.start.row)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user