Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@PaulBGD
Created December 2, 2015 02:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PaulBGD/fe5139dc16a791a34d14 to your computer and use it in GitHub Desktop.
Save PaulBGD/fe5139dc16a791a34d14 to your computer and use it in GitHub Desktop.
updateSelector() {
if (this.running) {
return this.selector.style.display = 'none';
}
let lines = this.lines;
let length = this.input.value.length;
if (!this.running) {
length += this.prefix.length;
}
length -= this.input.value.length - this.input.selectionStart;
let moved = (length * 9) - window.innerWidth;
if (moved > 0) { // we're wrapping the line
lines += Math.ceil(moved / window.innerWidth);
moved = moved % window.innerWidth;
moved = moved / 9; // how many spaces
length = Math.ceil(moved);
}
this.selector.style.left = (9 * length) + 'px';
this.selector.style.top = ((20 * lines) + 5 - window.scrollY) + 'px';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment