diff --git a/doc/manual.html b/doc/manual.html
index 2cfda6689c..452ad91a40 100644
--- a/doc/manual.html
+++ b/doc/manual.html
@@ -475,13 +475,16 @@
Programming API
Retrieves the current value of the given option for this
editor instance.
- cursorCoords(start) → object
+ cursorCoords(start, mode) → object
Returns an {x, y, yBot}
object containing the
- coordinates of the cursor relative to the top-left corner of the
+ coordinates of the cursor. If mode
+ is "local"
, they will be relative to the top-left
+ corner of the editable document. If it is "page"
or
+ not given, they are relative to the top-left corner of the
page. yBot
is the coordinate of the bottom of the
cursor. start
is a boolean indicating whether you
want the start or the end of the selection.
- charCoords(pos) → object
+ charCoords(pos, mode) → object
Like cursorCoords
, but returns the position of
an arbitrary characters. pos
should be
a {line, ch}
object.
diff --git a/lib/codemirror.js b/lib/codemirror.js
index 4536e136ec..d34c3a6e25 100644
--- a/lib/codemirror.js
+++ b/lib/codemirror.js
@@ -176,11 +176,16 @@ var CodeMirror = (function() {
line = clipLine(line == null ? doc.size - 1: line);
return getStateBefore(line + 1);
},
- cursorCoords: function(start){
+ cursorCoords: function(start, mode) {
if (start == null) start = sel.inverted;
- return pageCoords(start ? sel.from : sel.to);
+ return this.charCoords(start ? sel.from : sel.to, mode);
+ },
+ charCoords: function(pos, mode) {
+ pos = clipPos(pos);
+ if (mode == "local") return localCoords(pos, false);
+ if (mode == "div") return localCoords(pos, true);
+ return pageCoords(pos);
},
- charCoords: function(pos){return pageCoords(clipPos(pos));},
coordsChar: function(coords) {
var off = eltOffset(lineSpace);
return coordsChar(coords.x - off.left, coords.y - off.top);