The column should be rounded to the next character edge if clicked in the editor
This commit is contained in:
parent
11906fa4b6
commit
36a7b98766
2 changed files with 29 additions and 1 deletions
|
|
@ -362,7 +362,7 @@ ace.VirtualRenderer = function(container) {
|
||||||
this.screenToTextCoordinates = function(pageX, pageY) {
|
this.screenToTextCoordinates = function(pageX, pageY) {
|
||||||
var canvasPos = this.scroller.getBoundingClientRect();
|
var canvasPos = this.scroller.getBoundingClientRect();
|
||||||
|
|
||||||
var col = Math.floor((pageX + this.scroller.scrollLeft - canvasPos.left)
|
var col = Math.round((pageX + this.scroller.scrollLeft - canvasPos.left)
|
||||||
/ this.characterWidth);
|
/ this.characterWidth);
|
||||||
var row = Math.floor((pageY + this.scrollTop - canvasPos.top)
|
var row = Math.floor((pageY + this.scrollTop - canvasPos.top)
|
||||||
/ this.lineHeight);
|
/ this.lineHeight);
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,34 @@ var VirtualRendererTest = new TestCase("VirtualRendererTest", {
|
||||||
assertEquals(6, renderer.$screenToDocumentColumn(0, 9));
|
assertEquals(6, renderer.$screenToDocumentColumn(0, 9));
|
||||||
assertEquals(12, renderer.$screenToDocumentColumn(0, 15));
|
assertEquals(12, renderer.$screenToDocumentColumn(0, 15));
|
||||||
assertEquals(13, renderer.$screenToDocumentColumn(0, 19));
|
assertEquals(13, renderer.$screenToDocumentColumn(0, 19));
|
||||||
|
},
|
||||||
|
|
||||||
|
"test: screen2text the column should be rounded to the next character edge" : function() {
|
||||||
|
var el = document.createElement("div");
|
||||||
|
el.style.left = "0px";
|
||||||
|
el.style.top = "0px";
|
||||||
|
el.style.width = "100px";
|
||||||
|
el.style.height = "100px";
|
||||||
|
document.body.style.margin = "0px";
|
||||||
|
document.body.style.padding = "0px";
|
||||||
|
document.body.appendChild(el);
|
||||||
|
|
||||||
|
var renderer = new ace.VirtualRenderer(el);
|
||||||
|
renderer.setDocument(new ace.Document("1234"));
|
||||||
|
|
||||||
|
renderer.characterWidth = 10;
|
||||||
|
renderer.lineHeight = 15;
|
||||||
|
|
||||||
|
assertPosition(0, 0, renderer.screenToTextCoordinates(0, 0));
|
||||||
|
assertPosition(0, 0, renderer.screenToTextCoordinates(4, 0));
|
||||||
|
assertPosition(0, 1, renderer.screenToTextCoordinates(5, 0));
|
||||||
|
assertPosition(0, 1, renderer.screenToTextCoordinates(9, 0));
|
||||||
|
assertPosition(0, 1, renderer.screenToTextCoordinates(10, 0));
|
||||||
|
assertPosition(0, 1, renderer.screenToTextCoordinates(14, 0));
|
||||||
|
assertPosition(0, 2, renderer.screenToTextCoordinates(15, 0));
|
||||||
|
document.body.removeChild(el);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// change tab size after setDocument (for text layer)
|
// change tab size after setDocument (for text layer)
|
||||||
});
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue