Pass autoIndent as an option flag

Instead of querying EditSession for autoIndenting
This commit is contained in:
Corey Johnson
2013-01-09 15:24:04 -08:00
parent 261a8aae2d
commit f5ee676e5e
4 changed files with 41 additions and 49 deletions

View File

@@ -92,7 +92,6 @@ class EditSession
getScrollLeft: -> @scrollLeft
setSoftWrapColumn: (@softWrapColumn) -> @displayBuffer.setSoftWrapColumn(@softWrapColumn)
setAutoIndent: (@autoIndent) ->
setSoftTabs: (@softTabs) ->
getSoftWrap: -> @softWrap
@@ -158,18 +157,23 @@ class EditSession
getCursorScopes: -> @getCursor().getScopes()
logScreenLines: (start, end) -> @displayBuffer.logLines(start, end)
insertText: (text, options) ->
shouldAutoIndent: ->
false
insertText: (text, options={}) ->
options.autoIndent ?= @shouldAutoIndent()
@mutateSelectedText (selection) -> selection.insertText(text, options)
insertNewline: ->
@insertText('\n', autoIndent: true)
@insertText('\n')
insertNewlineBelow: ->
@moveCursorToEndOfLine()
@insertNewline()
indent: ->
@mutateSelectedText (selection) -> selection.indent()
indent: (options={})->
options.autoIndent ?= @shouldAutoIndent()
@mutateSelectedText (selection) -> selection.indent(options)
backspace: ->
@mutateSelectedText (selection) -> selection.backspace()
@@ -216,9 +220,13 @@ class EditSession
selection.copy(maintainPasteboard)
maintainPasteboard = true
pasteText: ->
pasteText: (options={})->
options.normalizeIndent ?= true
[text, metadata] = pasteboard.read()
@insertText(text, _.extend(metadata ? {}, normalizeIndent: true))
_.extend(options, metadata) if metadata
@insertText(text, options)
undo: ->
@buffer.undo(this)

View File

@@ -243,7 +243,7 @@ class Editor extends View
insertText: (text, options) -> @activeEditSession.insertText(text, options)
insertNewline: -> @activeEditSession.insertNewline()
insertNewlineBelow: -> @activeEditSession.insertNewlineBelow()
indent: -> @activeEditSession.indent()
indent: (options) -> @activeEditSession.indent(options)
indentSelectedRows: -> @activeEditSession.indentSelectedRows()
outdentSelectedRows: -> @activeEditSession.outdentSelectedRows()
cutSelection: -> @activeEditSession.cutSelectedText()
@@ -380,7 +380,7 @@ class Editor extends View
@selectOnMousemoveUntilMouseup()
@on "textInput", (e) =>
@insertText(e.originalEvent.data, autoIndent: true)
@insertText(e.originalEvent.data)
false
@scrollView.on 'mousewheel', (e) =>

View File

@@ -179,13 +179,13 @@ class Selection
else
@cursor.setBufferPosition(newBufferRange.end, skipAtomicTokens: true) if wasReversed
if @editSession.autoIndent and options.autoIndent
if options.autoIndent
if text == '\n'
@editSession.autoIndentBufferRow(newBufferRange.end.row)
else
@editSession.autoDecreaseIndentForRow(newBufferRange.start.row)
indent: ->
indent: ({ autoIndent }={})->
{ row, column } = @cursor.getBufferPosition()
if @isEmpty()
@@ -193,7 +193,7 @@ class Selection
desiredIndent = @editSession.suggestedIndentForBufferRow(row)
delta = desiredIndent - @cursor.getIndentLevel()
if @editSession.autoIndent and delta > 0
if autoIndent and delta > 0
@insertText(@editSession.buildIndentString(delta))
else
@insertText(@editSession.getTabText())
@@ -221,7 +221,7 @@ class Selection
if insideExistingLine
desiredBasis = @editSession.indentationForBufferRow(currentBufferRow)
else if @editSession.autoIndent
else if options.autoIndent
desiredBasis = @editSession.suggestedIndentForBufferRow(currentBufferRow)
else
desiredBasis = @cursor.getIndentLevel()