From 4341f5ab620bc9e7b1e8b02f74167fa8c77c8f90 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Mon, 4 Sep 2017 07:54:27 +0900 Subject: [PATCH 01/10] select tab as rotations --- src/background/index.js | 6 +++--- src/background/tabs.js | 10 ++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/background/index.js b/src/background/index.js index 15c8ab0..93d0e74 100644 --- a/src/background/index.js +++ b/src/background/index.js @@ -55,9 +55,9 @@ const normalizeUrl = (string) => { } } -const cmdBuffer = (arg) => { +const cmdBuffer = (sender, arg) => { if (isNaN(arg)) { - return tabs.selectByKeyword(arg); + return tabs.selectByKeyword(sender.tab, arg); } else { let index = parseInt(arg, 10) - 1; return tabs.selectAt(index); @@ -73,7 +73,7 @@ const cmdEnterHandle = (request, sender) => { return browser.tabs.create({ url: normalizeUrl(words[1]) }); case 'b': case 'buffer': - return cmdBuffer(words[1]); + return cmdBuffer(sender, words[1]); } throw new Error(words[0] + ' command is not defined'); }; diff --git a/src/background/tabs.js b/src/background/tabs.js index efecdc4..be8ef02 100644 --- a/src/background/tabs.js +++ b/src/background/tabs.js @@ -31,7 +31,7 @@ const selectAt = (index) => { }); }; -const selectByKeyword = (keyword) => { +const selectByKeyword = (current, keyword) => { return browser.tabs.query({ currentWindow: true }).then((tabs) => { let matched = tabs.filter((t) => { return t.url.includes(keyword) || t.title.includes(keyword) @@ -39,10 +39,12 @@ const selectByKeyword = (keyword) => { if (matched.length == 0) { throw new RangeError('No matching buffer for ' + keyword); - } else if (matched.length >= 2) { - throw new RangeError('More than one match for ' + keyword); } - + for (let tab of matched) { + if (tab.index > current.index) { + return browser.tabs.update(tab.id, { active: true }); + } + } return browser.tabs.update(matched[0].id, { active: true }); }); } From 40dce0ca6e7eaffcc214327f72ba17d307daad44 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Mon, 4 Sep 2017 18:29:25 +0900 Subject: [PATCH 02/10] add setCompletions --- src/console/console-frame.js | 4 ++++ src/console/console.html | 2 +- src/console/console.js | 39 ++++++++++++++++++++++++++++++++++++ src/console/console.scss | 38 ++++++++++++++++++++++++++--------- 4 files changed, 73 insertions(+), 10 deletions(-) diff --git a/src/console/console-frame.js b/src/console/console-frame.js index ea9f523..11c36f4 100644 --- a/src/console/console-frame.js +++ b/src/console/console-frame.js @@ -51,4 +51,8 @@ export default class ConsoleFrame { isErrorShown() { return this.element.style.display === 'block' && this.errorShown; } + + setCompletions(completions) { + messages.send(this.element.contentWindow, completions); + } } diff --git a/src/console/console.html b/src/console/console.html index 2eb445d..4222f12 100644 --- a/src/console/console.html +++ b/src/console/console.html @@ -9,7 +9,7 @@

-

+
    { let command = window.document.querySelector('#vimvixen-console-command'); command.style.display = 'none'; + + let completion = window.document.querySelector('#vimvixen-console-completion'); + command.style.display = 'none'; +} + +const setCompletions = (completions) => { + let completion = window.document.querySelector('#vimvixen-console-completion'); + completion.style.display = 'block'; + completion.innerHTML = ''; + + for (let group of completions) { + let title = window.document.createElement('li'); + title.className = 'vimvixen-console-completion-title'; + title.textContent = group.name; + + completion.append(title); + + for (let item of group.items) { + let caption = window.document.createElement('span'); + caption.textContent = item.caption; + caption.className = 'vimvixen-console-completion-item-caption'; + + let url = window.document.createElement('span'); + url.textContent = item.url; + url.className = 'vimvixen-console-completion-item-url'; + + let li = window.document.createElement('li'); + li.style.backgroundImage = 'url(' + item.icon + ')'; + li.className = 'vimvixen-console-completion-item'; + li.append(caption); + li.append(url); + li.setAttribute('data-content', item.content); + + completion.append(li); + } + } } messages.receive(window, (message) => { @@ -85,5 +121,8 @@ messages.receive(window, (message) => { case 'vimvixen.console.show.error': showError(message.text); break; + case 'vimvixen.console.set.completions': + setCompletions(message.completions); + break; } }); diff --git a/src/console/console.scss b/src/console/console.scss index 0de873d..b91e0b8 100644 --- a/src/console/console.scss +++ b/src/console/console.scss @@ -23,20 +23,40 @@ body { line-height: 16px; } - &-error { - background-color: red; - font-weight: bold; - color: white; + &-completion { + background-color: white; @include consoole-font; - } + &-title { + background-color: lightgray; + font-weight: bold; + margin: 0; + padding: 0; + } + + &-item { + padding-left: 1.5rem; + background-position: 0 center; + background-repeat: no-repeat; - &-title { - background-color: lightgray; + &-caption { + display: inline-block; + width: 40%; + } + + &-url { + display: inline-block; + color: green; + } + } + + } + + &-error { + background-color: red; font-weight: bold; - margin: 0; - padding: 0; + color: white; @include consoole-font; } From 5e124e7561b355758a68f79d3ecf10148f8ecdd5 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Tue, 5 Sep 2017 12:07:02 +0900 Subject: [PATCH 03/10] add Completion class --- src/console/completion.js | 26 ++++++++++++++++++ test/console/completion.test.js | 48 +++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 src/console/completion.js create mode 100644 test/console/completion.test.js 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; + } +} diff --git a/test/console/completion.test.js b/test/console/completion.test.js new file mode 100644 index 0000000..a789c15 --- /dev/null +++ b/test/console/completion.test.js @@ -0,0 +1,48 @@ +import { expect } from "chai"; +import Completion from '../../src/console/completion'; + +describe('Completion class', () => { + describe('#constructor', () => { + it('creates new object by iterable items', () => { + new Completion([1,2,3,4,5]); + new Completion([]); + new Completion('hello'); + new Completion(''); + }); + + it('creates new object by iterable items', () => { + expect(() => new Completion({ key: 'value' })).to.throw(TypeError); + expect(() => new Completion(12345)).to.throw(TypeError); + }); + }); + + describe('#next', () => { + it('complete next items', () => { + let completion = new Completion([3, 4, 5]); + expect(completion.next()).to.equal(3); + expect(completion.next()).to.equal(4); + expect(completion.next()).to.equal(5); + expect(completion.next()).to.equal(3); + }); + + it('returns null when empty completions', () => { + let completion = new Completion([]); + expect(completion.next()).to.be.null; + }); + }); + + describe('#prev', () => { + it('complete prev items', () => { + let completion = new Completion([3, 4, 5]); + expect(completion.prev()).to.equal(5); + expect(completion.prev()).to.equal(4); + expect(completion.prev()).to.equal(3); + expect(completion.prev()).to.equal(5); + }); + + it('returns null when empty completions', () => { + let completion = new Completion([]); + expect(completion.prev()).to.be.null; + }); + }); +}); From 1383b8c12d438eaf271bdf528ff033270a45d394 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Tue, 5 Sep 2017 12:24:24 +0900 Subject: [PATCH 04/10] tab completion --- src/console/console.js | 49 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/src/console/console.js b/src/console/console.js index e54611d..3c7d61f 100644 --- a/src/console/console.js +++ b/src/console/console.js @@ -1,10 +1,13 @@ import './console.scss'; +import Completion from './completion'; import * as messages from '../shared/messages'; const parent = window.parent; // TODO consider object-oriented var prevValue = ""; +window.completion = null; +var completionOrigin = ""; const blurMessage = () => { return { @@ -30,6 +33,32 @@ const handleBlur = () => { messages.send(parent, blurMessage()); }; +const completeNext = () => { + if (!window.completion) { + return; + } + let item = window.completion.next(); + if (!item) { + return; + } + + let input = window.document.querySelector('#vimvixen-console-command-input'); + input.value = completionOrigin + item.content; +} + +const completePrev = () => { + if (!window.completion) { + return; + } + let item = window.completion.prev(); + if (!item) { + return; + } + + let input = window.document.querySelector('#vimvixen-console-command-input'); + input.value = completionOrigin + item.content; +} + const handleKeydown = (e) => { switch(e.keyCode) { case KeyboardEvent.DOM_VK_ESCAPE: @@ -38,6 +67,15 @@ const handleKeydown = (e) => { case KeyboardEvent.DOM_VK_RETURN: messages.send(parent, keydownMessage(e.target)); break; + case KeyboardEvent.DOM_VK_TAB: + if (e.shiftKey) { + completePrev(); + } else { + completeNext(); + } + e.stopPropagation(); + e.preventDefault(); + break; } }; @@ -77,7 +115,7 @@ const showError = (text) => { command.style.display = 'none'; let completion = window.document.querySelector('#vimvixen-console-completion'); - command.style.display = 'none'; + completion.style.display = 'none'; } const setCompletions = (completions) => { @@ -111,6 +149,15 @@ const setCompletions = (completions) => { completion.append(li); } } + + let flatten = []; + for (let group of completions) { + flatten = flatten.concat(group.items); + } + window.completion = new Completion(flatten); + + let input = window.document.querySelector('#vimvixen-console-command-input'); + completionOrigin = input.value; } messages.receive(window, (message) => { From 73a4fe0bb1f8a7296f0a174e84111ce021f1c14e Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Tue, 5 Sep 2017 13:44:21 +0900 Subject: [PATCH 05/10] do simple completion --- src/background/index.js | 16 ++++++++++++++-- src/background/tabs.js | 11 ++++++++++- src/console/console-frame.js | 5 ++++- src/content/index.js | 26 +++++++++++++++++++------- 4 files changed, 47 insertions(+), 11 deletions(-) diff --git a/src/background/index.js b/src/background/index.js index 93d0e74..4a5e6d6 100644 --- a/src/background/index.js +++ b/src/background/index.js @@ -84,8 +84,20 @@ browser.runtime.onMessage.addListener((request, sender) => { return keyPressHandle(request, sender); case 'event.cmd.enter': return cmdEnterHandle(request, sender); - case 'event.cmd.suggest': - // TODO make suggestion and return + case 'event.cmd.tabs.completion': + return tabs.getCompletions(request.text).then((tabs) => { + let items = tabs.map((tab) => { + return { + caption: tab.title, + content: tab.title, + url: tab.url + } + }); + return { + name: "Buffers", + items: items + }; + }); break; } return Promise.resolve(); diff --git a/src/background/tabs.js b/src/background/tabs.js index be8ef02..111bbd9 100644 --- a/src/background/tabs.js +++ b/src/background/tabs.js @@ -49,6 +49,15 @@ const selectByKeyword = (current, keyword) => { }); } +const getCompletions = (keyword) => { + return browser.tabs.query({ currentWindow: true }).then((tabs) => { + let matched = tabs.filter((t) => { + return t.url.includes(keyword) || t.title.includes(keyword) + }) + return matched; + }); +}; + const selectPrevTab = (current, count) => { return browser.tabs.query({ currentWindow: true }, (tabs) => { if (tabs.length < 2) { @@ -78,4 +87,4 @@ const reload = (current, cache) => { ); }; -export { closeTab, reopenTab, selectAt, selectByKeyword, selectNextTab, selectPrevTab, reload }; +export { closeTab, reopenTab, selectAt, selectByKeyword, getCompletions, selectPrevTab, selectNextTab, reload }; diff --git a/src/console/console-frame.js b/src/console/console-frame.js index 11c36f4..e6bf3f5 100644 --- a/src/console/console-frame.js +++ b/src/console/console-frame.js @@ -53,6 +53,9 @@ export default class ConsoleFrame { } setCompletions(completions) { - messages.send(this.element.contentWindow, completions); + messages.send(this.element.contentWindow, { + type: 'vimvixen.console.set.completions', + completions: completions + }); } } diff --git a/src/content/index.js b/src/content/index.js index 8b3eb58..e682a7f 100644 --- a/src/content/index.js +++ b/src/content/index.js @@ -83,11 +83,27 @@ window.addEventListener("keypress", (e) => { browser.runtime.sendMessage(request) .then(handleResponse) .catch((err) => { + console.error("Vim Vixen:", err); vvConsole.showError(err.message); - console.log(`Vim Vixen: ${err}`); }); }); +const doCompletion = (line) => { + if (line.startsWith('buffer ')) { + let keyword = line.replace('buffer ', ''); + + browser.runtime.sendMessage({ + type: 'event.cmd.tabs.completion', + text: keyword + }).then((completions) => { + vvConsole.setCompletions([completions]); + }).catch((e) => { + console.error("Vim Vixen:", err); + vvConsole.showError(e.message); + }); + } +}; + messages.receive(window, (message) => { switch (message.type) { case 'vimvixen.command.blur': @@ -100,16 +116,12 @@ messages.receive(window, (message) => { type: 'event.cmd.enter', text: message.value }).catch((e) => { + console.error("Vim Vixen:", err); vvConsole.showError(e.message); }); break; case 'vimvixen.command.change': - browser.runtime.sendMessage({ - type: 'event.cmd.suggest', - text: message.value - }).catch((e) => { - vvConsole.showError(e.message); - }); + doCompletion(message.value); break; default: return; From ee9359c138b146dc5a4d31e988c3a7f3ed0444e5 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Tue, 5 Sep 2017 13:56:16 +0900 Subject: [PATCH 06/10] fix completion --- src/background/index.js | 3 ++- src/console/console.js | 9 ++++++--- src/console/console.scss | 3 +++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/background/index.js b/src/background/index.js index 4a5e6d6..4aa3856 100644 --- a/src/background/index.js +++ b/src/background/index.js @@ -90,7 +90,8 @@ browser.runtime.onMessage.addListener((request, sender) => { return { caption: tab.title, content: tab.title, - url: tab.url + url: tab.url, + icon: tab.favIconUrl } }); return { diff --git a/src/console/console.js b/src/console/console.js index 3c7d61f..d139a50 100644 --- a/src/console/console.js +++ b/src/console/console.js @@ -43,7 +43,7 @@ const completeNext = () => { } let input = window.document.querySelector('#vimvixen-console-command-input'); - input.value = completionOrigin + item.content; + input.value = completionOrigin + ' ' + item.content; } const completePrev = () => { @@ -56,7 +56,7 @@ const completePrev = () => { } let input = window.document.querySelector('#vimvixen-console-command-input'); - input.value = completionOrigin + item.content; + input.value = completionOrigin + ' ' + item.content; } const handleKeydown = (e) => { @@ -80,6 +80,9 @@ const handleKeydown = (e) => { }; const handleKeyup = (e) => { + if (e.keyCode === KeyboardEvent.DOM_VK_TAB) { + return; + } if (e.target.value === prevValue) { return; } @@ -157,7 +160,7 @@ const setCompletions = (completions) => { window.completion = new Completion(flatten); let input = window.document.querySelector('#vimvixen-console-command-input'); - completionOrigin = input.value; + completionOrigin = input.value.split(' ')[0]; } messages.receive(window, (message) => { diff --git a/src/console/console.scss b/src/console/console.scss index b91e0b8..c22b14f 100644 --- a/src/console/console.scss +++ b/src/console/console.scss @@ -8,6 +8,7 @@ body { bottom: 0; left: 0; right: 0; + overflow: hidden; } .vimvixen-console { @@ -38,7 +39,9 @@ body { &-item { padding-left: 1.5rem; background-position: 0 center; + background-size: contain; background-repeat: no-repeat; + white-space: nowrap; &-caption { display: inline-block; From caf24779ddfdceb5e9a0fab4f55c92c8d52cda7f Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Tue, 5 Sep 2017 14:37:58 +0900 Subject: [PATCH 07/10] completion hightlight --- src/console/console.js | 27 +++++++++++++++++++-------- src/console/console.scss | 5 ++++- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/console/console.js b/src/console/console.js index d139a50..da6e3ca 100644 --- a/src/console/console.js +++ b/src/console/console.js @@ -43,7 +43,9 @@ const completeNext = () => { } let input = window.document.querySelector('#vimvixen-console-command-input'); - input.value = completionOrigin + ' ' + item.content; + input.value = completionOrigin + ' ' + item[0].content; + + selectCompletion(item[1]); } const completePrev = () => { @@ -56,7 +58,9 @@ const completePrev = () => { } let input = window.document.querySelector('#vimvixen-console-command-input'); - input.value = completionOrigin + ' ' + item.content; + input.value = completionOrigin + ' ' + item[0].content; + + selectCompletion(item[1]); } const handleKeydown = (e) => { @@ -126,6 +130,8 @@ const setCompletions = (completions) => { completion.style.display = 'block'; completion.innerHTML = ''; + let pairs = []; + for (let group of completions) { let title = window.document.createElement('li'); title.className = 'vimvixen-console-completion-title'; @@ -147,22 +153,27 @@ const setCompletions = (completions) => { li.className = 'vimvixen-console-completion-item'; li.append(caption); li.append(url); - li.setAttribute('data-content', item.content); completion.append(li); + + pairs.push([item, li]); } } - let flatten = []; - for (let group of completions) { - flatten = flatten.concat(group.items); - } - window.completion = new Completion(flatten); + window.completion = new Completion(pairs); let input = window.document.querySelector('#vimvixen-console-command-input'); completionOrigin = input.value.split(' ')[0]; } +const selectCompletion = (element) => { + let elements = window.document.querySelectorAll('.vimvixen-console-completion-item'); + Array.prototype.forEach.call(elements, (ele) => { + ele.className = 'vimvixen-console-completion-item'; + }); + element.classList.add('vimvixen-completion-selected'); +}; + messages.receive(window, (message) => { switch (message.type) { case 'vimvixen.console.show.command': diff --git a/src/console/console.scss b/src/console/console.scss index c22b14f..7bb46dd 100644 --- a/src/console/console.scss +++ b/src/console/console.scss @@ -43,6 +43,10 @@ body { background-repeat: no-repeat; white-space: nowrap; + &.vimvixen-completion-selected { + background-color: yellow; + } + &-caption { display: inline-block; width: 40%; @@ -53,7 +57,6 @@ body { color: green; } } - } &-error { From d8c9651b776296bdb5eb1a8687f633e60feafb10 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Tue, 5 Sep 2017 15:42:35 +0900 Subject: [PATCH 08/10] fix --- src/background/index.js | 2 -- src/content/index.js | 8 ++++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/background/index.js b/src/background/index.js index 4aa3856..8913a83 100644 --- a/src/background/index.js +++ b/src/background/index.js @@ -99,7 +99,5 @@ browser.runtime.onMessage.addListener((request, sender) => { items: items }; }); - break; } - return Promise.resolve(); }); diff --git a/src/content/index.js b/src/content/index.js index e682a7f..fdc7e89 100644 --- a/src/content/index.js +++ b/src/content/index.js @@ -97,9 +97,9 @@ const doCompletion = (line) => { text: keyword }).then((completions) => { vvConsole.setCompletions([completions]); - }).catch((e) => { + }).catch((err) => { console.error("Vim Vixen:", err); - vvConsole.showError(e.message); + vvConsole.showError(err.message); }); } }; @@ -115,9 +115,9 @@ messages.receive(window, (message) => { browser.runtime.sendMessage({ type: 'event.cmd.enter', text: message.value - }).catch((e) => { + }).catch((err) => { console.error("Vim Vixen:", err); - vvConsole.showError(e.message); + vvConsole.showError(err.message); }); break; case 'vimvixen.command.change': From e436b98808a324bdf825b521802c16b3fbf774f5 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Tue, 5 Sep 2017 18:38:08 +0900 Subject: [PATCH 09/10] clean completion --- src/console/console.js | 82 ++++++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 34 deletions(-) diff --git a/src/console/console.js b/src/console/console.js index da6e3ca..93b7297 100644 --- a/src/console/console.js +++ b/src/console/console.js @@ -6,7 +6,7 @@ const parent = window.parent; // TODO consider object-oriented var prevValue = ""; -window.completion = null; +var completion = null; var completionOrigin = ""; const blurMessage = () => { @@ -34,10 +34,10 @@ const handleBlur = () => { }; const completeNext = () => { - if (!window.completion) { + if (!completion) { return; } - let item = window.completion.next(); + let item = completion.next(); if (!item) { return; } @@ -49,10 +49,10 @@ const completeNext = () => { } const completePrev = () => { - if (!window.completion) { + if (!completion) { return; } - let item = window.completion.prev(); + let item = completion.prev(); if (!item) { return; } @@ -125,53 +125,67 @@ const showError = (text) => { completion.style.display = 'none'; } +const createCompletionTitle = (text) => { + let li = document.createElement('li'); + li.className = 'vimvixen-console-completion-title'; + li.textContent = text; + return li +} + +const createCompletionItem = (icon, caption, url) => { + let captionEle = document.createElement('span'); + captionEle.className = 'vimvixen-console-completion-item-caption'; + captionEle.textContent = caption + + let urlEle = document.createElement('span'); + urlEle.className = 'vimvixen-console-completion-item-url'; + urlEle.textContent = url + + let li = document.createElement('li'); + li.style.backgroundImage = 'url(' + icon + ')'; + li.className = 'vimvixen-console-completion-item'; + li.append(captionEle); + li.append(urlEle); + return li; +} + const setCompletions = (completions) => { - let completion = window.document.querySelector('#vimvixen-console-completion'); - completion.style.display = 'block'; - completion.innerHTML = ''; + let container = window.document.querySelector('#vimvixen-console-completion'); + container.style.display = 'block'; + container.innerHTML = ''; let pairs = []; for (let group of completions) { - let title = window.document.createElement('li'); - title.className = 'vimvixen-console-completion-title'; - title.textContent = group.name; - - completion.append(title); + let title = createCompletionTitle(group.name); + container.append(title); for (let item of group.items) { - let caption = window.document.createElement('span'); - caption.textContent = item.caption; - caption.className = 'vimvixen-console-completion-item-caption'; - - let url = window.document.createElement('span'); - url.textContent = item.url; - url.className = 'vimvixen-console-completion-item-url'; - - let li = window.document.createElement('li'); - li.style.backgroundImage = 'url(' + item.icon + ')'; - li.className = 'vimvixen-console-completion-item'; - li.append(caption); - li.append(url); - - completion.append(li); + let li = createCompletionItem(item.icon, item.caption, item.url); + container.append(li); pairs.push([item, li]); } } - window.completion = new Completion(pairs); + completion = new Completion(pairs); let input = window.document.querySelector('#vimvixen-console-command-input'); completionOrigin = input.value.split(' ')[0]; } -const selectCompletion = (element) => { - let elements = window.document.querySelectorAll('.vimvixen-console-completion-item'); - Array.prototype.forEach.call(elements, (ele) => { - ele.className = 'vimvixen-console-completion-item'; +const selectCompletion = (target) => { + let container = window.document.querySelector('#vimvixen-console-completion'); + Array.prototype.forEach.call(container.children, (ele) => { + if (!ele.classList.contains('vimvixen-console-completion-item')) { + return; + } + if (ele === target) { + ele.classList.add('vimvixen-completion-selected'); + } else { + ele.classList.remove('vimvixen-completion-selected'); + } }); - element.classList.add('vimvixen-completion-selected'); }; messages.receive(window, (message) => { From c507f7febf0d8827dafcc6fd543678af447c056c Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Tue, 5 Sep 2017 18:00:57 +0900 Subject: [PATCH 10/10] reset completion --- src/console/console.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/console/console.js b/src/console/console.js index 93b7297..c32eca0 100644 --- a/src/console/console.js +++ b/src/console/console.js @@ -111,6 +111,11 @@ const showCommand = (text) => { let input = window.document.querySelector('#vimvixen-console-command-input'); input.value = text; input.focus(); + + completion = null; + let container = window.document.querySelector('#vimvixen-console-completion'); + container.innerHTML = ''; + messages.send(parent, keyupMessage(input)); } const showError = (text) => {