This repository has been archived on 2020-04-04. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
Vim-Vixen/src/console/completion.js
2017-09-05 18:15:24 +09:00

26 lines
668 B
JavaScript

export default class Completion {
constructor(completions) {
if (typeof completions.length !== 'number') {
throw new TypeError('completions does not have a length in number');
}
this.completions = completions
this.index = 0;
}
prev() {
if (this.completions.length === 0) {
return null;
}
this.index = (this.index + this.completions.length - 1) % this.completions.length
return this.completions[this.index];
}
next() {
if (this.completions.length === 0) {
return null;
}
let item = this.completions[this.index];
this.index = (this.index + 1) % this.completions.length
return item;
}
}