Skip to content

Commit 5d740b9

Browse files
committed
[show-hint addon] Scroll initially selected hint into view
See https://discuss.codemirror.net/t/show-selectedhint-in-very-long-list-of-hints/2255
1 parent 00363e3 commit 5d740b9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

addon/hint/show-hint.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@
322322
CodeMirror.on(hints, "mousedown", function() {
323323
setTimeout(function(){cm.focus();}, 20);
324324
});
325+
this.scrollToActive()
325326

326327
CodeMirror.signal(data, "select", completions[this.selectedHint], hints.childNodes[this.selectedHint]);
327328
return true;
@@ -363,11 +364,16 @@
363364
if (node) node.className = node.className.replace(" " + ACTIVE_HINT_ELEMENT_CLASS, "");
364365
node = this.hints.childNodes[this.selectedHint = i];
365366
node.className += " " + ACTIVE_HINT_ELEMENT_CLASS;
367+
this.scrollToActive()
368+
CodeMirror.signal(this.data, "select", this.data.list[this.selectedHint], node);
369+
},
370+
371+
scrollToActive: function() {
372+
var node = this.hints.childNodes[this.selectedHint]
366373
if (node.offsetTop < this.hints.scrollTop)
367374
this.hints.scrollTop = node.offsetTop - 3;
368375
else if (node.offsetTop + node.offsetHeight > this.hints.scrollTop + this.hints.clientHeight)
369376
this.hints.scrollTop = node.offsetTop + node.offsetHeight - this.hints.clientHeight + 3;
370-
CodeMirror.signal(this.data, "select", this.data.list[this.selectedHint], node);
371377
},
372378

373379
screenAmount: function() {

0 commit comments

Comments
 (0)