From 7425f58f266f127e55d6d7e046dc96fcb9dccace Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 23 Jan 2013 16:46:43 -0800 Subject: [PATCH] Only change end position if selection is mult-line --- spec/app/language-mode-spec.coffee | 13 ++++++++++++- src/app/language-mode.coffee | 8 ++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/spec/app/language-mode-spec.coffee b/spec/app/language-mode-spec.coffee index 68184adf4..9e1cd8b71 100644 --- a/spec/app/language-mode-spec.coffee +++ b/spec/app/language-mode-spec.coffee @@ -145,7 +145,7 @@ describe "LanguageMode", -> expect(buffer.lineForRow(0)).toBe '"ok"' expect(editSession.getCursorBufferPosition()).toEqual [0, 4] - describe "when there is text selected", -> + describe "when there is text selected on a single line", -> it "wraps the selection with brackets", -> editSession.insertText 'text' editSession.moveCursorToBottom() @@ -156,6 +156,17 @@ describe "LanguageMode", -> expect(editSession.getSelectedBufferRange()).toEqual [[0, 1], [0, 5]] expect(editSession.getSelection().isReversed()).toBeTruthy() + describe "when there is text selected on multiple lines", -> + it "wraps the selection with brackets", -> + editSession.insertText 'text\nabcd' + editSession.moveCursorToBottom() + editSession.selectToTop() + editSession.selectAll() + editSession.insertText '(' + expect('(text\nabcd)').toBe buffer.getText() + expect(editSession.getSelectedBufferRange()).toEqual [[0, 1], [1, 4]] + expect(editSession.getSelection().isReversed()).toBeTruthy() + describe "when inserting a quote", -> describe "when a word character is before the cursor", -> it "does not automatically insert closing quote", -> diff --git a/src/app/language-mode.coffee b/src/app/language-mode.coffee index 1649fe373..afdbf4704 100644 --- a/src/app/language-mode.coffee +++ b/src/app/language-mode.coffee @@ -74,8 +74,12 @@ class LanguageMode options = reverse: selection.isReversed() wrappedText = "#{bracket}#{selection.getText()}#{pair}" selection.insertText(wrappedText) - newRange = [range.start.add([0, 1]), range.end.add([0, 1])] - selection.setBufferRange(newRange, options) + selectionStart = range.start.add([0, 1]) + if range.start.row is range.end.row + selectionEnd = range.end.add([0, 1]) + else + selectionEnd = range.end + selection.setBufferRange([selectionStart, selectionEnd], options) reloadGrammar: -> path = @buffer.getPath()