From 33abaff747aa07c6369605e10f3e466457f34dde Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 28 Sep 2012 19:13:22 -0700 Subject: [PATCH] Don't highlight line if selection is multiline --- spec/app/editor-spec.coffee | 19 +++++++++++++++---- src/app/editor.coffee | 3 ++- src/app/selection.coffee | 4 ++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index 3e67040be..d32b05f90 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -1619,10 +1619,10 @@ describe "Editor", -> expect(editor.find('.line-number.cursor-line-number').text()).toBe "2" describe "line highlighting", -> - describe "when there is no wrapping", -> - beforeEach -> - editor.attachToDom(30) + beforeEach -> + editor.attachToDom(30) + describe "when there is no wrapping", -> it "highlights the line where the initial cursor position is", -> expect(editor.getCursorBufferPosition().row).toBe 0 expect(editor.find('.line.cursor-line').length).toBe 1 @@ -1636,7 +1636,6 @@ describe "Editor", -> describe "when there is wrapping", -> beforeEach -> - editor.attachToDom(30) editor.setSoftWrap(true) setEditorWidthInChars(editor, 20) @@ -1651,6 +1650,18 @@ describe "Editor", -> expect(editor.find('.line.cursor-line').length).toBe 1 expect(editor.find('.line.cursor-line').text()).toBe ' var sort = ' + describe "when there is a selection", -> + it "highlights if the selection is contained to one line", -> + editor.getSelection().setBufferRange(new Range([0,0],[0,1])) + expect(editor.getSelection().isMultiLine()).toBe false + expect(editor.find('.line.cursor-line').length).toBe 1 + expect(editor.find('.line.cursor-line').text()).toBe buffer.lineForRow(0) + + it "doesn't highlight if the selection spans multiple lines", -> + editor.getSelection().setBufferRange(new Range([0,0],[2,0])) + expect(editor.getSelection().isMultiLine()).toBe true + expect(editor.find('.line.cursor-line').length).toBe 0 + describe "folding", -> beforeEach -> editSession = rootView.project.buildEditSessionForPath('two-hundred.txt') diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 225ae4c94..d2e00e549 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -943,4 +943,5 @@ class Editor extends View @cursorScreenRow = @getCursorScreenPosition().row screenRow = @cursorScreenRow - @firstRenderedScreenRow @find('.line.cursor-line').removeClass('cursor-line') - @find(".line:eq(#{screenRow})").addClass('cursor-line') + if !@getSelection().isMultiLine() + @find(".line:eq(#{screenRow})").addClass('cursor-line') diff --git a/src/app/selection.coffee b/src/app/selection.coffee index eca63c7ff..8daad3198 100644 --- a/src/app/selection.coffee +++ b/src/app/selection.coffee @@ -31,6 +31,10 @@ class Selection isReversed: -> not @isEmpty() and @cursor.getBufferPosition().isLessThan(@anchor.getBufferPosition()) + isMultiLine: -> + range = @getScreenRange() + range.start.row != range.end.row + getScreenRange: -> if @anchor new Range(@anchor.getScreenPosition(), @cursor.getScreenPosition())