From b895122c24b82f22793c7fa98ed00dfd21645395 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 12 Jun 2012 14:44:45 -0600 Subject: [PATCH] Simplify Editor spec's mouse event integration specs Test handling of non-corresponding buffer & screen positions in spec on setCursorScreenPosition in edit-session-spec instead of in editor-spec --- spec/app/edit-session-spec.coffee | 9 ++ spec/app/editor-spec.coffee | 154 ++++++++++-------------------- src/app/edit-session.coffee | 1 + src/app/editor.coffee | 2 +- 4 files changed, 64 insertions(+), 102 deletions(-) diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index ca06e249d..4ecbb0d31 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -37,6 +37,15 @@ describe "EditSession", -> expect(editSession.getCursors()).toEqual [cursor1] expect(editSession.getCursorScreenPosition()).toEqual [4, 7] + describe "when soft-wrap is enabled and code is folded", -> + beforeEach -> + editSession.setSoftWrapColumn(50) + editSession.createFold(2, 3) + + it "positions the cursor at the buffer position that corresponds to the given screen position", -> + editSession.setCursorScreenPosition([9, 0]) + expect(editSession.getCursorBufferPosition()).toEqual [8, 11] + describe ".moveCursorUp()", -> it "moves the cursor up", -> editSession.setCursorScreenPosition([2, 2]) diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index f055e58c6..a5d0d4cfa 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -874,6 +874,59 @@ describe "Editor", -> editor.setFontSize(10) expect(editor.renderedLines.find(".line").length).toBeGreaterThan originalLineCount + describe "when a mousedown event occurs in the editor", -> + beforeEach -> + editor.attachToDom() + editor.css(position: 'absolute', top: 10, left: 10) + + describe "when it is a single click", -> + it "re-positions the cursor to the clicked row / column", -> + expect(editor.getCursorScreenPosition()).toEqual(row: 0, column: 0) + + editor.renderedLines.trigger mousedownEvent(editor: editor, point: [3, 10]) + expect(editor.getCursorScreenPosition()).toEqual(row: 3, column: 10) + + describe "when the lines are scrolled to the right", -> + it "re-positions the cursor on the clicked location", -> + setEditorWidthInChars(editor, 30) + expect(editor.getCursorScreenPosition()).toEqual(row: 0, column: 0) + editor.renderedLines.trigger mousedownEvent(editor: editor, point: [3, 30]) # scrolls lines to the right + editor.renderedLines.trigger mousedownEvent(editor: editor, point: [3, 50]) + expect(editor.getCursorBufferPosition()).toEqual(row: 3, column: 50) + + describe "when it is a double click", -> + it "selects the word under the cursor", -> + expect(editor.getCursorScreenPosition()).toEqual(row: 0, column: 0) + editor.renderedLines.trigger mousedownEvent(editor: editor, point: [0, 8], originalEvent: {detail: 1}) + editor.renderedLines.trigger 'mouseup' + editor.renderedLines.trigger mousedownEvent(editor: editor, point: [0, 8], originalEvent: {detail: 2}) + editor.renderedLines.trigger 'mouseup' + expect(editor.getSelectedText()).toBe "quicksort" + + describe "when it is clicked more then twice (triple, quadruple, etc...)", -> + it "selects the line under the cursor", -> + expect(editor.getCursorScreenPosition()).toEqual(row: 0, column: 0) + + # Triple click + editor.renderedLines.trigger mousedownEvent(editor: editor, point: [1, 8], originalEvent: {detail: 1}) + editor.renderedLines.trigger 'mouseup' + editor.renderedLines.trigger mousedownEvent(editor: editor, point: [1, 8], originalEvent: {detail: 2}) + editor.renderedLines.trigger 'mouseup' + editor.renderedLines.trigger mousedownEvent(editor: editor, point: [1, 8], originalEvent: {detail: 3}) + editor.renderedLines.trigger 'mouseup' + expect(editor.getSelectedText()).toBe " var sort = function(items) {" + + # Quad click + editor.renderedLines.trigger mousedownEvent(editor: editor, point: [2, 3], originalEvent: {detail: 1}) + editor.renderedLines.trigger 'mouseup' + editor.renderedLines.trigger mousedownEvent(editor: editor, point: [2, 3], originalEvent: {detail: 2}) + editor.renderedLines.trigger 'mouseup' + editor.renderedLines.trigger mousedownEvent(editor: editor, point: [2, 3], originalEvent: {detail: 3}) + editor.renderedLines.trigger 'mouseup' + editor.renderedLines.trigger mousedownEvent(editor: editor, point: [2, 3], originalEvent: {detail: 4}) + editor.renderedLines.trigger 'mouseup' + expect(editor.getSelectedText()).toBe " if (items.length <= 1) return items;" + describe "cursor movement", -> describe ".setCursorScreenPosition({row, column})", -> beforeEach -> @@ -883,107 +936,6 @@ describe "Editor", -> it "moves the cursor to the character at the given row and column", -> expect(editor.getCursorView().position()).toEqual(top: 2 * editor.lineHeight, left: 2 * editor.charWidth) - describe "when a mousedown event occurs in the editor", -> - beforeEach -> - editor.attachToDom() - editor.css(position: 'absolute', top: 10, left: 10) - - describe "when soft-wrap and is enabled and code is folded", -> - beforeEach -> - setEditorWidthInChars(editor, 50) - editor.setSoftWrap(true) - editor.createFold(2, 3) - - describe "when it is a single click", -> - it "re-positions the cursor from the clicked screen position to the corresponding buffer position", -> - expect(editor.getCursorScreenPosition()).toEqual(row: 0, column: 0) - editor.renderedLines.trigger mousedownEvent(editor: editor, point: [9, 0]) - expect(editor.getCursorBufferPosition()).toEqual(row: 8, column: 11) - - describe "when it is a double click", -> - it "selects the word under the cursor", -> - expect(editor.getCursorScreenPosition()).toEqual(row: 0, column: 0) - editor.renderedLines.trigger mousedownEvent(editor: editor, point: [9, 0], originalEvent: {detail: 1}) - editor.renderedLines.trigger 'mouseup' - editor.renderedLines.trigger mousedownEvent(editor: editor, point: [9, 0], originalEvent: {detail: 2}) - expect(editor.getSelectedText()).toBe "sort" - - describe "when it is clicked more then twice (triple, quadruple, etc...)", -> - it "selects the line under the cursor", -> - expect(editor.getCursorScreenPosition()).toEqual(row: 0, column: 0) - - # Triple click - point = [9, 3] - editor.renderedLines.trigger mousedownEvent(editor: editor, point: point, originalEvent: {detail: 1}) - editor.renderedLines.trigger 'mouseup' - editor.renderedLines.trigger mousedownEvent(editor: editor, point: point, originalEvent: {detail: 2}) - editor.renderedLines.trigger 'mouseup' - editor.renderedLines.trigger mousedownEvent(editor: editor, point: point, originalEvent: {detail: 3}) - editor.renderedLines.trigger 'mouseup' - expect(editor.getSelectedText()).toBe " return sort(left).concat(pivot).concat(sort(right));" - - # Quad click - point = [12, 3] - editor.renderedLines.trigger mousedownEvent(editor: editor, point: point, originalEvent: {detail: 1}) - editor.renderedLines.trigger 'mouseup' - editor.renderedLines.trigger mousedownEvent(editor: editor, point: point, originalEvent: {detail: 2}) - editor.renderedLines.trigger 'mouseup' - editor.renderedLines.trigger mousedownEvent(editor: editor, point: point, originalEvent: {detail: 3}) - editor.renderedLines.trigger 'mouseup' - editor.renderedLines.trigger mousedownEvent(editor: editor, point: point, originalEvent: {detail: 4}) - editor.renderedLines.trigger 'mouseup' - - expect(editor.getSelectedText()).toBe " return sort(Array.apply(this, arguments));" - - describe "when soft-wrap is disabled", -> - describe "when it is a single click", -> - it "re-positions the cursor to the clicked row / column", -> - expect(editor.getCursorScreenPosition()).toEqual(row: 0, column: 0) - - editor.renderedLines.trigger mousedownEvent(editor: editor, point: [3, 10]) - expect(editor.getCursorScreenPosition()).toEqual(row: 3, column: 10) - - describe "when the lines are scrolled to the right", -> - it "re-positions the cursor on the clicked location", -> - setEditorWidthInChars(editor, 30) - expect(editor.getCursorScreenPosition()).toEqual(row: 0, column: 0) - editor.renderedLines.trigger mousedownEvent(editor: editor, point: [3, 30]) # scrolls lines to the right - editor.renderedLines.trigger mousedownEvent(editor: editor, point: [3, 50]) - expect(editor.getCursorBufferPosition()).toEqual(row: 3, column: 50) - - describe "when it is a double click", -> - it "selects the word under the cursor", -> - expect(editor.getCursorScreenPosition()).toEqual(row: 0, column: 0) - editor.renderedLines.trigger mousedownEvent(editor: editor, point: [0, 8], originalEvent: {detail: 1}) - editor.renderedLines.trigger 'mouseup' - editor.renderedLines.trigger mousedownEvent(editor: editor, point: [0, 8], originalEvent: {detail: 2}) - editor.renderedLines.trigger 'mouseup' - expect(editor.getSelectedText()).toBe "quicksort" - - describe "when it is clicked more then twice (triple, quadruple, etc...)", -> - it "selects the line under the cursor", -> - expect(editor.getCursorScreenPosition()).toEqual(row: 0, column: 0) - - # Triple click - editor.renderedLines.trigger mousedownEvent(editor: editor, point: [1, 8], originalEvent: {detail: 1}) - editor.renderedLines.trigger 'mouseup' - editor.renderedLines.trigger mousedownEvent(editor: editor, point: [1, 8], originalEvent: {detail: 2}) - editor.renderedLines.trigger 'mouseup' - editor.renderedLines.trigger mousedownEvent(editor: editor, point: [1, 8], originalEvent: {detail: 3}) - editor.renderedLines.trigger 'mouseup' - expect(editor.getSelectedText()).toBe " var sort = function(items) {" - - # Quad click - editor.renderedLines.trigger mousedownEvent(editor: editor, point: [2, 3], originalEvent: {detail: 1}) - editor.renderedLines.trigger 'mouseup' - editor.renderedLines.trigger mousedownEvent(editor: editor, point: [2, 3], originalEvent: {detail: 2}) - editor.renderedLines.trigger 'mouseup' - editor.renderedLines.trigger mousedownEvent(editor: editor, point: [2, 3], originalEvent: {detail: 3}) - editor.renderedLines.trigger 'mouseup' - editor.renderedLines.trigger mousedownEvent(editor: editor, point: [2, 3], originalEvent: {detail: 4}) - editor.renderedLines.trigger 'mouseup' - expect(editor.getSelectedText()).toBe " if (items.length <= 1) return items;" - describe "scrolling", -> describe "vertical scrolling", -> beforeEach -> diff --git a/src/app/edit-session.coffee b/src/app/edit-session.coffee index d9dc348ba..546877986 100644 --- a/src/app/edit-session.coffee +++ b/src/app/edit-session.coffee @@ -73,6 +73,7 @@ class EditSession setScrollLeft: (@scrollLeft) -> getScrollLeft: -> @scrollLeft + setSoftWrapColumn: (softWrapColumn) -> @renderer.setSoftWrapColumn(softWrapColumn) setAutoIndent: (@autoIndent) -> setSoftTabs: (@softTabs) -> diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 086fb9c24..ce349f79c 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -587,7 +587,7 @@ class Editor extends View setSoftWrapColumn: (softWrapColumn) -> softWrapColumn ?= @calcSoftWrapColumn() - @renderer.setSoftWrapColumn(softWrapColumn) if softWrapColumn + @activeEditSession.setSoftWrapColumn(softWrapColumn) if softWrapColumn createFold: (startRow, endRow) -> @renderer.createFold(startRow, endRow)