Skip to content

Commit 1f3a196

Browse files
committed
Allow a line handle to be passed to heightAtLine
1 parent fa9bc99 commit 1f3a196

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

doc/manual.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1811,7 +1811,7 @@ <h3 id="api_sizing">Sizing, scrolling and positioning methods</h3>
18111811
height. <code>mode</code> can be one of the same strings
18121812
that <a href="#coordsChar"><code>coordsChar</code></a>
18131813
accepts.</dd>
1814-
<dt id="heightAtLine"><code><strong>cm.heightAtLine</strong>(line: number, ?mode: string) → number</code></dt>
1814+
<dt id="heightAtLine"><code><strong>cm.heightAtLine</strong>(line: integer|LineHandle, ?mode: string) → number</code></dt>
18151815
<dd>Computes the height of the top of a line, in the coordinate
18161816
system specified by <code>mode</code>
18171817
(see <a href="#coordsChar"><code>coordsChar</code></a>), which

lib/codemirror.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4929,10 +4929,15 @@
49294929
return lineAtHeight(this.doc, height + this.display.viewOffset);
49304930
},
49314931
heightAtLine: function(line, mode) {
4932-
var end = false, last = this.doc.first + this.doc.size - 1;
4933-
if (line < this.doc.first) line = this.doc.first;
4934-
else if (line > last) { line = last; end = true; }
4935-
var lineObj = getLine(this.doc, line);
4932+
var end = false, lineObj;
4933+
if (typeof line == "number") {
4934+
var last = this.doc.first + this.doc.size - 1;
4935+
if (line < this.doc.first) line = this.doc.first;
4936+
else if (line > last) { line = last; end = true; }
4937+
lineObj = getLine(this.doc, line);
4938+
} else {
4939+
lineObj = line;
4940+
}
49364941
return intoCoordSystem(this, lineObj, {top: 0, left: 0}, mode || "page").top +
49374942
(end ? this.doc.height - heightAtLine(lineObj) : 0);
49384943
},

0 commit comments

Comments
 (0)