SpecHelper has a method for getting pixel points from a row/column

This commit is contained in:
Corey Johnson
2012-02-02 11:14:50 -08:00
parent d2a6eca8f3
commit d8975e7a94
2 changed files with 13 additions and 12 deletions

View File

@@ -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()

View File

@@ -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)