aboutsummaryrefslogtreecommitdiff
path: root/src/console/completion.js
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2017-09-05 19:37:52 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2017-09-05 19:37:52 +0900
commit2cbdc483b7ecdee0627daaf934e6010e77d68a77 (patch)
tree6f8b8667f835bfb7e778cc571d8869cb5903a08a /src/console/completion.js
parent8cabd68b927fe7022efa11dee082aafe8c2d4f30 (diff)
parentc507f7febf0d8827dafcc6fd543678af447c056c (diff)
Merge branch 'buffer-completion'
Diffstat (limited to 'src/console/completion.js')
-rw-r--r--src/console/completion.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/console/completion.js b/src/console/completion.js
new file mode 100644
index 0000000..0c21cb0
--- /dev/null
+++ b/src/console/completion.js
@@ -0,0 +1,26 @@
+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;
+ }
+}