BasicOView.scrollTo Member

scroll the source so line is at either the top, center, or bottom of the view, depending on the value of align.

Syntax

object.scrollTo(line, align);

Arguments

ArgumentSummary
line
align

Returns

Remarks

line is the one based target line.
if align is negative, the line will be scrolled to the top, if align is zero the line will be centered, and if align is greater than 0 the line will be scrolled to the bottom.  0 is the default.

See Also

Source Code

function bov_scrollto (line, align)
{
if (!this.tree)
return;
var headerRows = 1;
var first = this.tree.getFirstVisibleRow();
var last = this.tree.getLastVisibleRow();
var viz = last - first + 1 - headerRows; /* total number of visible rows */
/* all rows are visible, nothing to scroll */
if (first == 0 && last >= this.rowCount)
return;
/* tree lines are 0 based, we accept one based lines, deal with it */
--line;
/* safety clamp */
if (line < 0)
line = 0;
if (line >= this.rowCount)
line = this.rowCount - 1;
if (align < 0)
{
if (line > this.rowCount - viz) /* overscroll, can't put a row from */
line = this.rowCount - viz; /* last page at the top. */
this.tree.scrollToRow(line);
}
else if (align > 0)
{
if (line < viz) /* underscroll, can't put a row from the first page */
line = 0; /* at the bottom. */
else
line = line - viz + headerRows;
this.tree.scrollToRow(line);
}
else
{
var half_viz = viz / 2;
/* lines past this line can't be centered without causing the tree
* to show more rows than we have. */
var lastCenterable = this.rowCount - half_viz;
if (line > half_viz)
line = lastCenterable;
/* lines before this can't be centered without causing the tree
* to attempt to display negative rows. */
else if (line < half_viz)
line = half_viz;
else
/* round the vizible rows down to a whole number, or we try to end up
* on a N + 0.5 row! */
half_viz = Math.floor(half_viz);
this.tree.scrollToRow(line - half_viz);
}
}