diff --git a/package.json b/package.json index 6c667f3c9..58d5ae438 100644 --- a/package.json +++ b/package.json @@ -74,8 +74,8 @@ "one-dark-syntax": "0.7.1", "one-light-syntax": "0.7.0", "one-light-ui": "0.9.1", - "solarized-dark-syntax": "0.35.0", - "solarized-light-syntax": "0.21.0", + "solarized-dark-syntax": "0.38.1", + "solarized-light-syntax": "0.22.1", "archive-view": "0.58.0", "autocomplete-atom-api": "0.9.0", "autocomplete-css": "0.8.0", @@ -91,7 +91,7 @@ "deprecation-cop": "0.53.0", "dev-live-reload": "0.46.0", "encoding-selector": "0.20.0", - "exception-reporting": "0.25.0", + "exception-reporting": "0.32.0", "find-and-replace": "0.174.1", "fuzzy-finder": "0.87.0", "git-diff": "0.55.0", @@ -103,7 +103,7 @@ "link": "0.30.0", "markdown-preview": "0.150.0", "metrics": "0.51.0", - "notifications": "0.56.0", + "notifications": "0.57.0", "open-on-github": "0.37.0", "package-generator": "0.39.0", "release-notes": "0.53.0", diff --git a/spec/atom-spec.coffee b/spec/atom-spec.coffee index 99a7f432e..d2d1d68ae 100644 --- a/spec/atom-spec.coffee +++ b/spec/atom-spec.coffee @@ -127,6 +127,39 @@ describe "the `atom` global", -> column: 3 originalError: error + describe ".assert(condition, message, metadata)", -> + errors = null + + beforeEach -> + errors = [] + atom.onDidFailAssertion (error) -> errors.push(error) + + describe "if the condition is false", -> + it "notifies onDidFailAssertion handlers with an error object based on the call site of the assertion", -> + result = atom.assert(false, "a == b") + expect(result).toBe false + expect(errors.length).toBe 1 + expect(errors[0].message).toBe "Assertion failed: a == b" + expect(errors[0].stack).toContain('atom-spec') + + describe "if metadata is an object", -> + it "assigns the object on the error as `metadata`", -> + metadata = {foo: 'bar'} + atom.assert(false, "a == b", metadata) + expect(errors[0].metadata).toBe metadata + + describe "if metadata is a function", -> + it "assigns the function's return value on the error as `metadata`", -> + metadata = {foo: 'bar'} + atom.assert(false, "a == b", -> metadata) + expect(errors[0].metadata).toBe metadata + + describe "if the condition is true", -> + it "does nothing", -> + result = atom.assert(true, "a == b") + expect(result).toBe true + expect(errors).toEqual [] + describe "saving and loading", -> afterEach -> atom.mode = "spec" diff --git a/spec/pane-spec.coffee b/spec/pane-spec.coffee index ba2f02802..6ee7d1bab 100644 --- a/spec/pane-spec.coffee +++ b/spec/pane-spec.coffee @@ -209,6 +209,12 @@ describe "Pane", -> expect(item2.isDestroyed()).toBe true expect(events).toEqual [{item: item2, index: 1}] + it "invokes ::onWillRemoveItem() observers", -> + events = [] + pane.onWillRemoveItem (event) -> events.push(event) + pane.destroyItem(item2) + expect(events).toEqual [{item: item2, index: 1, destroyed: true}] + it "invokes ::onDidRemoveItem() observers", -> events = [] pane.onDidRemoveItem (event) -> events.push(event) @@ -496,6 +502,13 @@ describe "Pane", -> expect(pane1.getItems()).toEqual [item1, item3] expect(pane2.getItems()).toEqual [item4, item2, item5] + it "invokes ::onWillRemoveItem() observers", -> + events = [] + pane1.onWillRemoveItem (event) -> events.push(event) + pane1.moveItemToPane(item2, pane2, 1) + + expect(events).toEqual [{item: item2, index: 1, destroyed: false}] + it "invokes ::onDidRemoveItem() observers", -> events = [] pane1.onDidRemoveItem (event) -> events.push(event) diff --git a/spec/text-editor-spec.coffee b/spec/text-editor-spec.coffee index 641431d5a..c47939bf8 100644 --- a/spec/text-editor-spec.coffee +++ b/spec/text-editor-spec.coffee @@ -3707,11 +3707,12 @@ describe "TextEditor", -> expect(editor.indentLevelForLine("\t\thello")).toBe(2) it "returns the indent level based on the character starting the line when the leading whitespace contains both spaces and tabs", -> - expect(editor.indentLevelForLine("\t hello")).toBe(1) - expect(editor.indentLevelForLine(" \thello")).toBe(1) - expect(editor.indentLevelForLine(" \t hello")).toBe(1) - expect(editor.indentLevelForLine(" \t \thello")).toBe(2) - expect(editor.indentLevelForLine(" \t \thello")).toBe(2.5) + expect(editor.indentLevelForLine("\t hello")).toBe(2) + expect(editor.indentLevelForLine(" \thello")).toBe(2) + expect(editor.indentLevelForLine(" \t hello")).toBe(2.5) + expect(editor.indentLevelForLine(" \t \thello")).toBe(4) + expect(editor.indentLevelForLine(" \t \thello")).toBe(4) + expect(editor.indentLevelForLine(" \t \t hello")).toBe(4.5) describe "when the buffer is reloaded", -> it "preserves the current cursor position", -> diff --git a/src/atom.coffee b/src/atom.coffee index 316c51e29..03525df68 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -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' diff --git a/src/pane.coffee b/src/pane.coffee index 477239bdd..53980c8d1 100644 --- a/src/pane.coffee +++ b/src/pane.coffee @@ -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) diff --git a/src/selection.coffee b/src/selection.coffee index 0fcecbffe..a3cb4e0d3 100644 --- a/src/selection.coffee +++ b/src/selection.coffee @@ -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). diff --git a/src/text-editor.coffee b/src/text-editor.coffee index dfb791ee6..3b8653e3f 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -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 diff --git a/src/tokenized-buffer.coffee b/src/tokenized-buffer.coffee index c764c1a1f..e44183489 100644 --- a/src/tokenized-buffer.coffee +++ b/src/tokenized-buffer.coffee @@ -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 diff --git a/static/variables/ui-variables.less b/static/variables/ui-variables.less index d386730db..aa33d0e06 100644 --- a/static/variables/ui-variables.less +++ b/static/variables/ui-variables.less @@ -82,4 +82,4 @@ // Other -@font-family: 'Lucida Grande', 'Segoe UI', Ubuntu, Cantarell, sans-serif; +@font-family: 'SF UI Text', 'Lucida Grande', 'Segoe UI', Ubuntu, Cantarell, sans-serif;