From f2a497d591654bcce4d9727efa6796be012935e8 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 28 Apr 2016 13:43:00 +0200 Subject: [PATCH] Don't create folds for empty ranges --- spec/selection-spec.coffee | 19 +++++++++++++++++++ src/selection.coffee | 5 +++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/spec/selection-spec.coffee b/spec/selection-spec.coffee index 18095d6f8..7511c4b39 100644 --- a/spec/selection-spec.coffee +++ b/spec/selection-spec.coffee @@ -101,3 +101,22 @@ describe "Selection", -> selection.setBufferRange [[2, 0], [3, 0]] selection.insertText("\r\n", autoIndent: true) expect(buffer.lineForRow(2)).toBe " " + + describe ".fold()", -> + it "folds the buffer range spanned by the selection", -> + selection.setBufferRange([[0, 3], [1, 6]]) + selection.fold() + + expect(selection.getScreenRange()).toEqual([[0, 4], [0, 4]]) + expect(selection.getBufferRange()).toEqual([[1, 6], [1, 6]]) + expect(editor.lineTextForScreenRow(0)).toBe "var#{editor.displayLayer.foldCharacter}sort = function(items) {" + expect(editor.isFoldedAtBufferRow(0)).toBe(true) + + it "doesn't create a fold when the selection is empty", -> + selection.setBufferRange([[0, 3], [0, 3]]) + selection.fold() + + expect(selection.getScreenRange()).toEqual([[0, 3], [0, 3]]) + expect(selection.getBufferRange()).toEqual([[0, 3], [0, 3]]) + expect(editor.lineTextForScreenRow(0)).toBe "var quicksort = function () {" + expect(editor.isFoldedAtBufferRow(0)).toBe(false) diff --git a/src/selection.coffee b/src/selection.coffee index ea8ca187a..7ecbb3fbc 100644 --- a/src/selection.coffee +++ b/src/selection.coffee @@ -628,8 +628,9 @@ class Selection extends Model # Public: Creates a fold containing the current selection. fold: -> range = @getBufferRange() - @editor.foldBufferRange(range) - @cursor.setBufferPosition(range.end) + unless range.isEmpty() + @editor.foldBufferRange(range) + @cursor.setBufferPosition(range.end) # Private: Increase the indentation level of the given text by given number # of levels. Leaves the first line unchanged.