From d8975e7a945c14ded7cd306d9dabaf932ee9fc6d Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Thu, 2 Feb 2012 11:14:50 -0800 Subject: [PATCH] SpecHelper has a method for getting pixel points from a row/column --- spec/atom/editor-spec.coffee | 16 ++++------------ spec/spec-helper.coffee | 9 +++++++++ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/spec/atom/editor-spec.coffee b/spec/atom/editor-spec.coffee index 8e30edbf9..6c7732c5b 100644 --- a/spec/atom/editor-spec.coffee +++ b/spec/atom/editor-spec.coffee @@ -247,14 +247,10 @@ describe "Editor", -> describe "when a mousedown event occurs in the editor", -> it "re-positions the cursor to the clicked row / column", -> editor.attachToDom() - editor.css(position: 'absolute', top: 10, left: 10) - pageX = editor.offset().left + 10 * editor.charWidth + 3 - pageY = editor.offset().top + 4 * editor.lineHeight - 2 - expect(editor.getCursorPosition()).toEqual(row: 0, column: 0) + [pageX, pageY] = window.pixelPositionForPoint(editor, [3, 10]) editor.lines.trigger mousedownEvent({pageX, pageY}) - expect(editor.getCursorPosition()).toEqual(row: 3, column: 10) describe "selection", -> @@ -321,16 +317,13 @@ describe "Editor", -> describe "when the mouse is dragged across the text", -> it "creates a selection from the initial click to mouse cursor's location ", -> editor.attachToDom() - editor.css(position: 'absolute', top: 10, left: 10) # start - pageX = editor.offset().left + 10 * editor.charWidth + 3 - pageY = editor.offset().top + 4 * editor.lineHeight + 3 + [pageX, pageY] = window.pixelPositionForPoint(editor, [4, 10]) editor.lines.trigger mousedownEvent({pageX, pageY}) # moving changes selection - pageX = editor.offset().left + 27 * editor.charWidth + 3 - pageY = editor.offset().top + 5 * editor.lineHeight + 3 + [pageX, pageY] = window.pixelPositionForPoint(editor, [5, 27]) editor.lines.trigger mousemoveEvent({pageX, pageY}) range = editor.selection.getRange() @@ -342,8 +335,7 @@ describe "Editor", -> $(document).trigger 'mouseup' # moving after mouse up should not change selection - pageX = editor.offset().left + 3 * editor.charWidth + 3 - pageY = editor.offset().top + 8 * editor.lineHeight + 3 + [pageX, pageY] = window.pixelPositionForPoint(editor, [8, 8]) editor.lines.trigger mousemoveEvent({pageX, pageY}) range = editor.selection.getRange() diff --git a/spec/spec-helper.coffee b/spec/spec-helper.coffee index ead6fcdef..ddc822570 100644 --- a/spec/spec-helper.coffee +++ b/spec/spec-helper.coffee @@ -3,6 +3,7 @@ $ = require 'jquery' _ = require 'underscore' Native = require 'native' BindingSet = require 'binding-set' +Point = require 'point' require 'window' window.showConsole() @@ -63,6 +64,14 @@ window.advanceClock = (delta) -> else true +window.pixelPositionForPoint = (editor, point) -> + editor.css(position: 'absolute', top: 10, left: 10) + + point = Point.fromObject point + pageY = editor.offset().top + point.row * editor.lineHeight + 1 # ensure the pixel is inside the char + pageX = editor.offset().left + point.column * editor.charWidth + 1 # ensure the pixel is inside the char + [pageX, pageY] + $.fn.resultOfTrigger = (type) -> event = $.Event(type) this.trigger(event)