diff --git a/spec/display-buffer-spec.coffee b/spec/display-buffer-spec.coffee index 08814c5b0..f10e9844d 100644 --- a/spec/display-buffer-spec.coffee +++ b/spec/display-buffer-spec.coffee @@ -37,7 +37,7 @@ describe "DisplayBuffer", -> expect(displayBuffer2.isFoldedAtBufferRow(3)).toBeTruthy() # can diverge from origin - displayBuffer2.destroyFoldsContainingBufferRow(3) + displayBuffer2.unfoldBufferRow(3) expect(displayBuffer2.isFoldedAtBufferRow(3)).not.toBe displayBuffer.isFoldedAtBufferRow(3) describe "when the buffer changes", -> @@ -495,7 +495,7 @@ describe "DisplayBuffer", -> expect(displayBuffer.bufferPositionForScreenPosition([5, 0])).toEqual [5, 0] expect(displayBuffer.bufferPositionForScreenPosition([9, 2])).toEqual [9, 2] - describe ".destroyFoldsContainingBufferRow(row)", -> + describe ".unfoldBufferRow(row)", -> it "destroys all folds containing the given row", -> displayBuffer.createFold(2, 4) displayBuffer.createFold(2, 6) @@ -506,7 +506,7 @@ describe "DisplayBuffer", -> expect(displayBuffer.lineForRow(1).text).toBe '1' expect(displayBuffer.lineForRow(2).text).toBe '10' - displayBuffer.destroyFoldsContainingBufferRow(2) + displayBuffer.unfoldBufferRow(2) expect(displayBuffer.lineForRow(1).text).toBe '1' expect(displayBuffer.lineForRow(2).text).toBe '2' expect(displayBuffer.lineForRow(7).fold).toBeDefined() @@ -684,7 +684,7 @@ describe "DisplayBuffer", -> } markerChangedHandler.reset() - displayBuffer.destroyFoldsContainingBufferRow(4) + displayBuffer.unfoldBufferRow(4) expect(markerChangedHandler).toHaveBeenCalled() expect(markerChangedHandler.argsForCall[0][0]).toEqual { oldHeadScreenPosition: [8, 23] @@ -867,7 +867,7 @@ describe "DisplayBuffer", -> expect(marker.getHeadScreenPosition()).toEqual [8, 10] expect(marker.getTailScreenPosition()).toEqual [8, 4] - displayBuffer.destroyFoldsContainingBufferRow(4) + displayBuffer.unfoldBufferRow(4) expect(changeHandler).toHaveBeenCalled() expect(markerChangedHandler).toHaveBeenCalled() diff --git a/spec/language-mode-spec.coffee b/spec/language-mode-spec.coffee index a72470704..35f143636 100644 --- a/spec/language-mode-spec.coffee +++ b/spec/language-mode-spec.coffee @@ -285,21 +285,6 @@ describe "LanguageMode", -> expect(fold.getStartRow()).toBe 0 expect(fold.getEndRow()).toBe 13 - describe ".unfoldBufferRow(bufferRow)", -> - describe "when bufferRow can be unfolded", -> - it "destroys a fold based on the syntactic region starting at the given row", -> - languageMode.foldBufferRow(1) - expect(editor.lineForScreenRow(1).fold).toBeDefined() - - languageMode.unfoldBufferRow(1) - expect(editor.lineForScreenRow(1).fold).toBeUndefined() - - describe "when bufferRow can't be unfolded", -> - it "does not throw an error", -> - expect(editor.lineForScreenRow(1).fold).toBeUndefined() - languageMode.unfoldBufferRow(1) - expect(editor.lineForScreenRow(1).fold).toBeUndefined() - describe ".isFoldableAtBufferRow(bufferRow)", -> it "returns true if the line starts a foldable row range", -> expect(languageMode.isFoldableAtBufferRow(0)).toBe true diff --git a/src/display-buffer.coffee b/src/display-buffer.coffee index 085d9be4e..49227c5a0 100644 --- a/src/display-buffer.coffee +++ b/src/display-buffer.coffee @@ -169,7 +169,7 @@ class DisplayBuffer extends Model # Removes any folds found that contain the given buffer row. # # bufferRow - The buffer row {Number} to check against - destroyFoldsContainingBufferRow: (bufferRow) -> + unfoldBufferRow: (bufferRow) -> fold.destroy() for fold in @foldsContainingBufferRow(bufferRow) # Given a buffer row, this returns the largest fold that starts there. diff --git a/src/editor.coffee b/src/editor.coffee index 3f365bb4f..623d9776d 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -788,14 +788,11 @@ class Editor extends Model foldBufferRow: (bufferRow) -> @languageMode.foldBufferRow(bufferRow) - # Destroy the largest fold containing the given row in buffer - # coordinates. + # Public: Unfold all folds containing the given row in buffer coordinates. # # bufferRow - A {Number} - # - # TODO: Should this destroy all folds containing the given buffer row? unfoldBufferRow: (bufferRow) -> - @languageMode.unfoldBufferRow(bufferRow) + @displayBuffer.unfoldBufferRow(bufferRow) # Public: Determine whether the given row in buffer coordinates is foldable. # @@ -815,14 +812,10 @@ class Editor extends Model destroyFoldWithId: (id) -> @displayBuffer.destroyFoldWithId(id) - # {Delegates to: DisplayBuffer.destroyFoldsContainingBufferRow} - destroyFoldsContainingBufferRow: (bufferRow) -> - @displayBuffer.destroyFoldsContainingBufferRow(bufferRow) - # Remove any {Fold}s found that intersect the given buffer row. destroyFoldsIntersectingBufferRange: (bufferRange) -> for row in [bufferRange.start.row..bufferRange.end.row] - @destroyFoldsContainingBufferRow(row) + @unfoldBufferRow(row) # Public: Fold the given buffer row if it isn't currently folded, and unfold # it otherwise. @@ -904,7 +897,7 @@ class Editor extends Model # Make sure the inserted text doesn't go into an existing fold if fold = @displayBuffer.largestFoldStartingAtBufferRow(insertPosition.row) - @destroyFoldsContainingBufferRow(insertPosition.row) + @unfoldBufferRow(insertPosition.row) foldedRows.push(insertPosition.row + endRow - startRow + fold.getBufferRange().getRowCount()) @buffer.insert(insertPosition, lines) @@ -960,7 +953,7 @@ class Editor extends Model # Make sure the inserted text doesn't go into an existing fold if fold = @displayBuffer.largestFoldStartingAtBufferRow(insertPosition.row) - @destroyFoldsContainingBufferRow(insertPosition.row) + @unfoldBufferRow(insertPosition.row) foldedRows.push(insertPosition.row + fold.getBufferRange().getRowCount()) @buffer.insert(insertPosition, lines) diff --git a/src/language-mode.coffee b/src/language-mode.coffee index c5dae9e0c..0d7880cfe 100644 --- a/src/language-mode.coffee +++ b/src/language-mode.coffee @@ -121,12 +121,6 @@ class LanguageMode fold = @editor.displayBuffer.largestFoldStartingAtBufferRow(startRow) return @editor.createFold(startRow, endRow) unless fold - # Given a buffer row, this unfolds it. - # - # bufferRow - A {Number} indicating the buffer row - unfoldBufferRow: (bufferRow) -> - @editor.displayBuffer.largestFoldContainingBufferRow(bufferRow)?.destroy() - # Find the row range for a fold at a given bufferRow. Will handle comments # and code. # diff --git a/src/selection.coffee b/src/selection.coffee index a1e11990a..612531218 100644 --- a/src/selection.coffee +++ b/src/selection.coffee @@ -282,7 +282,7 @@ class Selection # :undo - if `skip`, skips the undo stack for this operation. insertText: (text, options={}) -> oldBufferRange = @getBufferRange() - @editor.destroyFoldsContainingBufferRow(oldBufferRange.end.row) + @editor.unfoldBufferRow(oldBufferRange.end.row) wasReversed = @isReversed() @clear() @cursor.needsAutoscroll = @cursor.isLastCursor() @@ -334,11 +334,15 @@ class Selection normalizedLines.join('\n') - # Public: Indents the selection. + # Indent the current line(s). + # + # If the selection is empty, indents the current line if the cursor precedes + # non-whitespace characters, and otherwise inserts a tab. If the selection is + # non empty, calls {::indentSelectedRows}. # # options - A {Object} with the keys: - # :autoIndent - If `true`, the indentation is performed appropriately. - # Otherwise, {Editor::getTabText} is used. + # :autoIndent - If `true`, the line is indented to an automatically-inferred + # level. Otherwise, {Editor::getTabText} is inserted. indent: ({ autoIndent }={})-> { row, column } = @cursor.getBufferPosition()