Skip to content

Commit c8c4565

Browse files
authored
[show-hint addon] Introduced option 'scrollMargin'
1 parent feed5d5 commit c8c4565

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

addon/hint/show-hint.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -379,12 +379,14 @@
379379
},
380380

381381
scrollToActive: function() {
382-
var node = this.hints.childNodes[this.selectedHint]
382+
var margin = this.completion.options.scrollMargin || 0;
383+
var node1 = this.hints.childNodes[Math.max(0, this.selectedHint - margin)];
384+
var node2 = this.hints.childNodes[Math.min(this.data.list.length - 1, this.selectedHint + margin)];
383385
var firstNode = this.hints.firstChild;
384-
if (node.offsetTop < this.hints.scrollTop)
385-
this.hints.scrollTop = node.offsetTop - firstNode.offsetTop;
386-
else if (node.offsetTop + node.offsetHeight > this.hints.scrollTop + this.hints.clientHeight)
387-
this.hints.scrollTop = node.offsetTop + node.offsetHeight - this.hints.clientHeight + firstNode.offsetTop;
386+
if (node1.offsetTop < this.hints.scrollTop)
387+
this.hints.scrollTop = node1.offsetTop - firstNode.offsetTop;
388+
else if (node2.offsetTop + node2.offsetHeight > this.hints.scrollTop + this.hints.clientHeight)
389+
this.hints.scrollTop = node2.offsetTop + node2.offsetHeight - this.hints.clientHeight + firstNode.offsetTop;
388390
},
389391

390392
screenAmount: function() {

doc/manual.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2790,6 +2790,9 @@ <h2 id="addons">Addons</h2>
27902790
<dd>Like <code>customKeys</code> above, but the bindings will
27912791
be added to the set of default bindings, instead of replacing
27922792
them.</dd>
2793+
<dt><code><strong>scrollMargin</strong>: integer</code></dt>
2794+
<dd>Show this many lines before and after the selected item.
2795+
Default is 0.</dd>
27932796
</dl>
27942797
The following events will be fired on the completions object
27952798
during completion:

0 commit comments

Comments
 (0)