Created
October 12, 2012 12:02
-
-
Save pvdz/3878890 to your computer and use it in GitHub Desktop.
ace get linear caret position wot?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getCharPos1: function() { | |
// Get cursor position | |
var charPos = 0; | |
var cursorPos = this.editor.getCursorPosition(); | |
for (var i=0; i<cursorPos.row; i++){ | |
charPos += this.editor.session.$rowLengthCache[i]; // +1 for newline | |
} | |
charPos += cursorPos.column + cursorPos.row; // Add row count to compensate for newlines | |
return charPos; | |
}, | |
caretPos2: function(){ | |
var cursorPos = this.editor.getCursorPosition(); | |
var col = cursorPos.column; | |
var row = cursorPos.row; | |
var doc = this.editor.session.doc; | |
var lines = doc.$lines; | |
var newlineLength = doc.$autoNewLine.length; | |
var pos = 0; | |
for (var y=0; y<row; ++y) { | |
var line = lines[y].length; | |
pos += line; | |
} | |
pos += newlineLength * y; | |
pos += col; | |
return pos; | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment