|
|
@ -6,7 +6,7 @@ const parent = window.parent; |
|
|
|
|
|
|
|
|
|
|
|
// TODO consider object-oriented
|
|
|
|
// TODO consider object-oriented
|
|
|
|
var prevValue = ""; |
|
|
|
var prevValue = ""; |
|
|
|
window.completion = null; |
|
|
|
var completion = null; |
|
|
|
var completionOrigin = ""; |
|
|
|
var completionOrigin = ""; |
|
|
|
|
|
|
|
|
|
|
|
const blurMessage = () => { |
|
|
|
const blurMessage = () => { |
|
|
@ -34,10 +34,10 @@ const handleBlur = () => { |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const completeNext = () => { |
|
|
|
const completeNext = () => { |
|
|
|
if (!window.completion) { |
|
|
|
if (!completion) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
let item = window.completion.next(); |
|
|
|
let item = completion.next(); |
|
|
|
if (!item) { |
|
|
|
if (!item) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
@ -49,10 +49,10 @@ const completeNext = () => { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const completePrev = () => { |
|
|
|
const completePrev = () => { |
|
|
|
if (!window.completion) { |
|
|
|
if (!completion) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
let item = window.completion.prev(); |
|
|
|
let item = completion.prev(); |
|
|
|
if (!item) { |
|
|
|
if (!item) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
@ -125,53 +125,67 @@ const showError = (text) => { |
|
|
|
completion.style.display = 'none'; |
|
|
|
completion.style.display = 'none'; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const setCompletions = (completions) => { |
|
|
|
const createCompletionTitle = (text) => { |
|
|
|
let completion = window.document.querySelector('#vimvixen-console-completion'); |
|
|
|
let li = document.createElement('li'); |
|
|
|
completion.style.display = 'block'; |
|
|
|
li.className = 'vimvixen-console-completion-title'; |
|
|
|
completion.innerHTML = ''; |
|
|
|
li.textContent = text; |
|
|
|
|
|
|
|
return li |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let pairs = []; |
|
|
|
const createCompletionItem = (icon, caption, url) => { |
|
|
|
|
|
|
|
let captionEle = document.createElement('span'); |
|
|
|
|
|
|
|
captionEle.className = 'vimvixen-console-completion-item-caption'; |
|
|
|
|
|
|
|
captionEle.textContent = caption |
|
|
|
|
|
|
|
|
|
|
|
for (let group of completions) { |
|
|
|
let urlEle = document.createElement('span'); |
|
|
|
let title = window.document.createElement('li'); |
|
|
|
urlEle.className = 'vimvixen-console-completion-item-url'; |
|
|
|
title.className = 'vimvixen-console-completion-title'; |
|
|
|
urlEle.textContent = url |
|
|
|
title.textContent = group.name; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
completion.append(title); |
|
|
|
let li = document.createElement('li'); |
|
|
|
|
|
|
|
li.style.backgroundImage = 'url(' + icon + ')'; |
|
|
|
|
|
|
|
li.className = 'vimvixen-console-completion-item'; |
|
|
|
|
|
|
|
li.append(captionEle); |
|
|
|
|
|
|
|
li.append(urlEle); |
|
|
|
|
|
|
|
return li; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (let item of group.items) { |
|
|
|
const setCompletions = (completions) => { |
|
|
|
let caption = window.document.createElement('span'); |
|
|
|
let container = window.document.querySelector('#vimvixen-console-completion'); |
|
|
|
caption.textContent = item.caption; |
|
|
|
container.style.display = 'block'; |
|
|
|
caption.className = 'vimvixen-console-completion-item-caption'; |
|
|
|
container.innerHTML = ''; |
|
|
|
|
|
|
|
|
|
|
|
let url = window.document.createElement('span'); |
|
|
|
let pairs = []; |
|
|
|
url.textContent = item.url; |
|
|
|
|
|
|
|
url.className = 'vimvixen-console-completion-item-url'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let li = window.document.createElement('li'); |
|
|
|
for (let group of completions) { |
|
|
|
li.style.backgroundImage = 'url(' + item.icon + ')'; |
|
|
|
let title = createCompletionTitle(group.name); |
|
|
|
li.className = 'vimvixen-console-completion-item'; |
|
|
|
container.append(title); |
|
|
|
li.append(caption); |
|
|
|
|
|
|
|
li.append(url); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
completion.append(li); |
|
|
|
for (let item of group.items) { |
|
|
|
|
|
|
|
let li = createCompletionItem(item.icon, item.caption, item.url); |
|
|
|
|
|
|
|
container.append(li); |
|
|
|
|
|
|
|
|
|
|
|
pairs.push([item, li]); |
|
|
|
pairs.push([item, li]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
window.completion = new Completion(pairs); |
|
|
|
completion = new Completion(pairs); |
|
|
|
|
|
|
|
|
|
|
|
let input = window.document.querySelector('#vimvixen-console-command-input'); |
|
|
|
let input = window.document.querySelector('#vimvixen-console-command-input'); |
|
|
|
completionOrigin = input.value.split(' ')[0]; |
|
|
|
completionOrigin = input.value.split(' ')[0]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const selectCompletion = (element) => { |
|
|
|
const selectCompletion = (target) => { |
|
|
|
let elements = window.document.querySelectorAll('.vimvixen-console-completion-item'); |
|
|
|
let container = window.document.querySelector('#vimvixen-console-completion'); |
|
|
|
Array.prototype.forEach.call(elements, (ele) => { |
|
|
|
Array.prototype.forEach.call(container.children, (ele) => { |
|
|
|
ele.className = 'vimvixen-console-completion-item'; |
|
|
|
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) => { |
|
|
|
messages.receive(window, (message) => { |
|
|
|