diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-09-17 09:00:41 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-09-17 09:00:41 +0900 |
commit | cd4708898134f5966f87df4aeaa8ed8c60e7943f (patch) | |
tree | db082d9cb2ec426010556dbc24ab439c9757afbd /src/console | |
parent | c5529958d53146c8c6826673abe6431a19f1924d (diff) | |
parent | 9ae814dfe45426f8df9b89b305392770344a7d50 (diff) |
Merge branch 'lint'
Diffstat (limited to 'src/console')
-rw-r--r-- | src/console/completion.js | 9 | ||||
-rw-r--r-- | src/console/console.js | 60 | ||||
-rw-r--r-- | src/console/frames.js | 4 |
3 files changed, 38 insertions, 35 deletions
diff --git a/src/console/completion.js b/src/console/completion.js index 0c21cb0..4c69afb 100644 --- a/src/console/completion.js +++ b/src/console/completion.js @@ -3,15 +3,16 @@ export default class Completion { if (typeof completions.length !== 'number') { throw new TypeError('completions does not have a length in number'); } - this.completions = completions + this.completions = completions; this.index = 0; } prev() { - if (this.completions.length === 0) { + let length = this.completions.length; + if (length === 0) { return null; } - this.index = (this.index + this.completions.length - 1) % this.completions.length + this.index = (this.index + length - 1) % length; return this.completions[this.index]; } @@ -20,7 +21,7 @@ export default class Completion { return null; } let item = this.completions[this.index]; - this.index = (this.index + 1) % this.completions.length + this.index = (this.index + 1) % this.completions.length; return item; } } diff --git a/src/console/console.js b/src/console/console.js index d1547b8..4471446 100644 --- a/src/console/console.js +++ b/src/console/console.js @@ -3,10 +3,10 @@ import Completion from './completion'; import messages from '../messages'; // TODO consider object-oriented -var prevValue = ""; -var completion = null; -var completionOrigin = ""; -var prevState = {}; +let prevValue = ''; +let completion = null; +let completionOrigin = ''; +let prevState = {}; const handleBlur = () => { return browser.runtime.sendMessage({ @@ -14,6 +14,20 @@ const handleBlur = () => { }); }; +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'); + } + }); +}; + const completeNext = () => { if (!completion) { return; @@ -27,7 +41,7 @@ const completeNext = () => { input.value = completionOrigin + ' ' + item[0].content; selectCompletion(item[1]); -} +}; const completePrev = () => { if (!completion) { @@ -42,12 +56,12 @@ const completePrev = () => { input.value = completionOrigin + ' ' + item[0].content; selectCompletion(item[1]); -} +}; const handleKeydown = (e) => { let input = window.document.querySelector('#vimvixen-console-command-input'); - switch(e.keyCode) { + switch (e.keyCode) { case KeyboardEvent.DOM_VK_ESCAPE: return input.blur(); case KeyboardEvent.DOM_VK_RETURN: @@ -92,17 +106,17 @@ const createCompletionTitle = (text) => { let li = document.createElement('li'); li.className = 'vimvixen-console-completion-title'; li.textContent = text; - return li -} + return li; +}; const createCompletionItem = (icon, caption, url) => { let captionEle = document.createElement('span'); captionEle.className = 'vimvixen-console-completion-item-caption'; - captionEle.textContent = caption + captionEle.textContent = caption; let urlEle = document.createElement('span'); urlEle.className = 'vimvixen-console-completion-item-url'; - urlEle.textContent = url + urlEle.textContent = url; let li = document.createElement('li'); li.style.backgroundImage = 'url(' + icon + ')'; @@ -110,24 +124,11 @@ const createCompletionItem = (icon, caption, url) => { li.append(captionEle); li.append(urlEle); return li; -} - -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'); - } - }); }; const updateCompletions = (completions) => { - let completionsContainer = window.document.querySelector('#vimvixen-console-completion'); + let completionsContainer = + window.document.querySelector('#vimvixen-console-completion'); let input = window.document.querySelector('#vimvixen-console-command-input'); completionsContainer.innerHTML = ''; @@ -148,7 +149,7 @@ const updateCompletions = (completions) => { completion = new Completion(pairs); completionOrigin = input.value.split(' ')[0]; -} +}; const update = (state) => { let error = window.document.querySelector('#vimvixen-console-error'); @@ -163,12 +164,13 @@ const update = (state) => { input.value = state.commandText; input.focus(); } - if (JSON.stringify(state.completions) !== JSON.stringify(prevState.completions)) { + if (JSON.stringify(state.completions) !== + JSON.stringify(prevState.completions)) { updateCompletions(state.completions); } prevState = state; -} +}; browser.runtime.onMessage.addListener((action) => { if (action.type === messages.STATE_UPDATE) { diff --git a/src/console/frames.js b/src/console/frames.js index ec1e38c..3f06466 100644 --- a/src/console/frames.js +++ b/src/console/frames.js @@ -8,11 +8,11 @@ const initialize = (doc) => { doc.body.append(iframe); return iframe; -} +}; const blur = (doc) => { let iframe = doc.getElementById('vimvixen-console-frame'); iframe.blur(); -} +}; export { initialize, blur }; |