From 766af2388efcf6e52484f1819229728a43bfcc29 Mon Sep 17 00:00:00 2001 From: nightwing Date: Tue, 8 May 2012 19:25:15 +0400 Subject: [PATCH] fix virtual renderer test --- lib/ace/virtual_renderer_test.js | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/lib/ace/virtual_renderer_test.js b/lib/ace/virtual_renderer_test.js index 59d5b089..191666c3 100644 --- a/lib/ace/virtual_renderer_test.js +++ b/lib/ace/virtual_renderer_test.js @@ -50,34 +50,36 @@ var assert = require("./test/assertions"); module.exports = { "test: screen2text the column should be rounded to the next character edge" : function() { var el = document.createElement("div"); - + if (!el.getBoundingClientRect) { console.log("Skipping test: This test only runs in the browser"); return; } - - el.style.left = "0px"; - el.style.top = "0px"; - el.style.width = "100px"; + + el.style.left = "20px"; + el.style.top = "30px"; + el.style.width = "300px"; el.style.height = "100px"; - document.body.style.margin = "0px"; - document.body.style.padding = "0px"; document.body.appendChild(el); var renderer = new VirtualRenderer(el); renderer.setPadding(0); renderer.setSession(new EditSession("1234")); + var r = renderer.scroller.getBoundingClientRect(); + function testPixelToText(x, y, row, column) { + assert.position(renderer.screenToTextCoordinates(x+r.left, y+r.top), row, column); + } + renderer.characterWidth = 10; renderer.lineHeight = 15; - assert.position(renderer.screenToTextCoordinates(0, 0), 0, 0); - assert.position(renderer.screenToTextCoordinates(4, 0), 0, 0); - assert.position(renderer.screenToTextCoordinates(5, 0), 0, 1); - assert.position(renderer.screenToTextCoordinates(9, 0), 0, 1); - assert.position(renderer.screenToTextCoordinates(10, 0), 0, 1); - assert.position(renderer.screenToTextCoordinates(14, 0), 0, 1); - assert.position(renderer.screenToTextCoordinates(15, 0), 0, 2); + testPixelToText(4, 0, 0, 0); + testPixelToText(5, 0, 0, 1); + testPixelToText(9, 0, 0, 1); + testPixelToText(10, 0, 0, 1); + testPixelToText(14, 0, 0, 1); + testPixelToText(15, 0, 0, 2); document.body.removeChild(el); }