From 4341f5ab620bc9e7b1e8b02f74167fa8c77c8f90 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Mon, 4 Sep 2017 07:54:27 +0900 Subject: select tab as rotations --- src/background/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/background/index.js') 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'); }; -- cgit v1.2.3 From 73a4fe0bb1f8a7296f0a174e84111ce021f1c14e Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Tue, 5 Sep 2017 13:44:21 +0900 Subject: 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(-) (limited to 'src/background/index.js') 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; -- cgit v1.2.3 From ee9359c138b146dc5a4d31e988c3a7f3ed0444e5 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Tue, 5 Sep 2017 13:56:16 +0900 Subject: fix completion --- src/background/index.js | 3 ++- src/console/console.js | 9 ++++++--- src/console/console.scss | 3 +++ 3 files changed, 11 insertions(+), 4 deletions(-) (limited to 'src/background/index.js') 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; -- cgit v1.2.3 From d8c9651b776296bdb5eb1a8687f633e60feafb10 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Tue, 5 Sep 2017 15:42:35 +0900 Subject: fix --- src/background/index.js | 2 -- src/content/index.js | 8 ++++---- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'src/background/index.js') 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': -- cgit v1.2.3