Merge remote-tracking branch 'origin/master' into dsandstrom-add-subword-cursors-4

This commit is contained in:
Nathan Sobo
2015-06-30 22:55:40 -05:00
10 changed files with 116 additions and 20 deletions

View File

@@ -333,6 +333,12 @@ class Atom extends Model
onDidThrowError: (callback) ->
@emitter.on 'did-throw-error', callback
# TODO: Make this part of the public API. We should make onDidThrowError
# match the interface by only yielding an exception object to the handler
# and deprecating the old behavior.
onDidFailAssertion: (callback) ->
@emitter.on 'did-fail-assertion', callback
###
Section: Atom Details
###
@@ -715,6 +721,22 @@ class Atom extends Model
Section: Private
###
assert: (condition, message, metadata) ->
return true if condition
error = new Error("Assertion failed: #{message}")
Error.captureStackTrace(error, @assert)
if metadata?
if typeof metadata is 'function'
error.metadata = metadata()
else
error.metadata = metadata
@emitter.emit 'did-fail-assertion', error
false
deserializeProject: ->
Project = require './project'

View File

@@ -163,6 +163,15 @@ class Pane extends Model
onDidRemoveItem: (callback) ->
@emitter.on 'did-remove-item', callback
# Public: Invoke the given callback before an item is removed from the pane.
#
# * `callback` {Function} to be called with when items are removed.
# * `event` {Object} with the following keys:
# * `item` The pane item to be removed.
# * `index` {Number} indicating where the item is located.
onWillRemoveItem: (callback) ->
@emitter.on 'will-remove-item', callback
# Public: Invoke the given callback when an item is moved within the pane.
#
# * `callback` {Function} to be called with when items are moved.
@@ -358,6 +367,8 @@ class Pane extends Model
index = @items.indexOf(item)
return if index is -1
@emitter.emit 'will-remove-item', {item, index, destroyed}
if Grim.includeDeprecatedAPIs and typeof item.on is 'function'
@unsubscribe item
@unsubscribeFromItem(item)

View File

@@ -642,7 +642,7 @@ class Selection extends Model
else
currentIndentLevel = @editor.indentLevelForLine(lines[i])
indentLevel = Math.max(0, currentIndentLevel + indentAdjustment)
lines[i] = line.replace(/^(\t+| +)/, @editor.buildIndentString(indentLevel))
lines[i] = line.replace(/^[\t ]+/, @editor.buildIndentString(indentLevel))
return
# Indent the current line(s).

View File

@@ -2481,13 +2481,14 @@ class TextEditor extends Model
options.autoIndent ?= @shouldAutoIndent()
@mutateSelectedText (selection) -> selection.indent(options)
# Constructs the string used for tabs.
buildIndentString: (number, column=0) ->
# Constructs the string used for indents.
buildIndentString: (level, column=0) ->
if @getSoftTabs()
tabStopViolation = column % @getTabLength()
_.multiplyString(" ", Math.floor(number * @getTabLength()) - tabStopViolation)
_.multiplyString(" ", Math.floor(level * @getTabLength()) - tabStopViolation)
else
_.multiplyString("\t", Math.floor(number))
excessWhitespace = _.multiplyString(' ', Math.round((level - Math.floor(level)) * @getTabLength()))
_.multiplyString("\t", Math.floor(level)) + excessWhitespace
###
Section: Grammars

View File

@@ -292,7 +292,17 @@ class TokenizedBuffer extends Model
# Returns a {Boolean} indicating whether the given buffer row starts
# a a foldable row range due to the code's indentation patterns.
isFoldableCodeAtRow: (row) ->
return false if @buffer.isRowBlank(row) or @tokenizedLineForRow(row).isComment()
# Investigating an exception that's occurring here due to the line being
# undefined. This should paper over the problem but we want to figure out
# what is happening:
tokenizedLine = @tokenizedLineForRow(row)
atom.assert tokenizedLine?, "TokenizedLine is defined", =>
metadata:
row: row
rowCount: @tokenizedLines.length
return false unless tokenizedLine?
return false if @buffer.isRowBlank(row) or tokenizedLine.isComment()
nextRow = @buffer.nextNonBlankRow(row)
return false unless nextRow?
@@ -411,10 +421,15 @@ class TokenizedBuffer extends Model
@indentLevelForLine(line)
indentLevelForLine: (line) ->
if match = line.match(/^\t+/)
match[0].length
else if match = line.match(/^ +/)
match[0].length / @getTabLength()
if match = line.match(/^[\t ]+/)
indentLength = 0
for character in match[0]
if character is '\t'
indentLength += @getTabLength() - (indentLength % @getTabLength())
else
indentLength++
indentLength / @getTabLength()
else
0