Don't normalize indents on paste if there are preceding characters

This commit is contained in:
Matt Colyer
2013-11-13 17:18:43 -08:00
parent 0673ce8e71
commit 52680bd63f
3 changed files with 19 additions and 1 deletions

View File

@@ -2525,6 +2525,13 @@ describe "EditSession", ->
editSession.insertText("foo", indentBasis: 5)
expect(editSession.lineForBufferRow(5)).toBe " foo current = items.shift();"
it "does not adjust the whitespace if there are preceding characters", ->
copyText(" foo")
editSession.setCursorBufferPosition([5, 30])
editSession.pasteText()
expect(editSession.lineForBufferRow(5)).toBe " current = items.shift(); foo"
describe "when the inserted text contains newlines", ->
describe "when the cursor is preceded only by whitespace characters", ->
it "normalizes indented lines to the cursor's current indentation level", ->

View File

@@ -466,3 +466,11 @@ class Cursor
# Returns an {Array} of {String}s.
getScopes: ->
@editSession.scopesForBufferPosition(@getBufferPosition())
# Public: Returns true if this cursor has no non-whitespace characters before
# it's current position.
hasNoPrecedingCharacters: ->
bufferPosition = @getBufferPosition()
line = @editSession.lineForBufferRow(bufferPosition.row)
firstCharacterColumn = line.search(/\S/)
noPrecedingCharacters = bufferPosition.column < firstCharacterColumn or firstCharacterColumn is -1

View File

@@ -567,8 +567,11 @@ class EditSession
pasteText: (options={}) ->
[text, metadata] = atom.pasteboard.read()
containsNewlines = text.indexOf('\n') isnt -1
if atom.config.get('editor.normalizeIndentOnPaste') and metadata
options.indentBasis ?= metadata.indentBasis
if @getCursor().hasNoPrecedingCharacters() or containsNewlines
options.indentBasis ?= metadata.indentBasis
@insertText(text, options)