From 4f50a4735dfd6cc7e102f0c886ea6340a44b24c0 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 12 Jun 2012 13:37:01 -0600 Subject: [PATCH] Add specs for EditSession.proto.selectToScreenPosition. Move coverage of selection merging --- spec/app/edit-session-spec.coffee | 33 +++++++++++++++++++++++++++++++ spec/app/editor-spec.coffee | 26 ------------------------ 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index 50b6aa22e..3560df36e 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -348,6 +348,39 @@ describe "EditSession", -> expect(selection1.getScreenRange()).toEqual([[0, 9], [1, 21]]) expect(selection1.isReversed()).toBeFalsy() + describe ".selectToScreenPosition(screenPosition)", -> + it "expands the last selection to the given position", -> + editSession.setSelectedBufferRange([[3, 0], [4, 5]]) + editSession.addCursorAtScreenPosition([5, 5]) + editSession.selectToScreenPosition([6, 1]) + + selections = editSession.getSelections() + expect(selections.length).toBe 2 + [selection1, selection2] = selections + expect(selection1.getScreenRange()).toEqual [[3, 0], [4, 5]] + expect(selection2.getScreenRange()).toEqual [[5, 5], [6, 1]] + + it "merges selections if they intersect, maintaining the directionality of the last selection", -> + editSession.setCursorScreenPosition([4, 10]) + editSession.selectToScreenPosition([5, 27]) + editSession.addCursorAtScreenPosition([3, 10]) + editSession.selectToScreenPosition([6, 27]) + + selections = editSession.getSelections() + expect(selections.length).toBe 1 + [selection1] = selections + expect(selection1.getScreenRange()).toEqual [[3, 10], [6, 27]] + expect(selection1.isReversed()).toBeFalsy() + + editSession.addCursorAtScreenPosition([7, 4]) + editSession.selectToScreenPosition([4, 11]) + + selections = editSession.getSelections() + expect(selections.length).toBe 1 + [selection1] = selections + expect(selection1.getScreenRange()).toEqual [[3, 10], [7, 4]] + expect(selection1.isReversed()).toBeTruthy() + describe ".selectToTop()", -> it "selects text from cusor position to the top of the buffer", -> editSession.setCursorScreenPosition [11,2] diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index d5a10b728..92ceed07b 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -1342,32 +1342,6 @@ describe "Editor", -> expect(selection1.getScreenRange()).toEqual [[4, 10], [5, 27]] expect(selection2.getScreenRange()).toEqual [[6, 10], [8, 27]] - it "merges selections when they intersect, maintaining the directionality of the newest selection", -> - editor.attachToDom() - editor.renderedLines.trigger mousedownEvent(editor: editor, point: [4, 10]) - editor.renderedLines.trigger mousemoveEvent(editor: editor, point: [5, 27]) - editor.renderedLines.trigger 'mouseup' - - editor.renderedLines.trigger mousedownEvent(editor: editor, point: [3, 10], metaKey: true) - editor.renderedLines.trigger mousemoveEvent(editor: editor, point: [6, 27], metaKey: true) - editor.renderedLines.trigger 'mouseup' - - selections = editor.getSelections() - expect(selections.length).toBe 1 - [selection1] = selections - expect(selection1.getScreenRange()).toEqual [[3, 10], [6, 27]] - expect(selection1.isReversed()).toBeFalsy() - - editor.renderedLines.trigger mousedownEvent(editor: editor, point: [7, 4], metaKey: true) - editor.renderedLines.trigger mousemoveEvent(editor: editor, point: [4, 11], metaKey: true) - editor.renderedLines.trigger 'mouseup' - - selections = editor.getSelections() - expect(selections.length).toBe 1 - [selection1] = selections - expect(selection1.getScreenRange()).toEqual [[3, 10], [7, 4]] - expect(selection1.isReversed()).toBeTruthy() - describe "buffer manipulation", -> beforeEach -> editor.attachToDom()