mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Don't normalize indents on paste if there are preceding characters
This commit is contained in:
@@ -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", ->
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user