first find implementation

This commit is contained in:
Shin'ya Ueoka 2017-11-09 21:05:02 +09:00
parent 956dd937d3
commit e021504356
8 changed files with 74 additions and 25 deletions

View file

@ -25,23 +25,18 @@ export default class ConsoleComponent {
}
onBlur() {
return browser.runtime.sendMessage({
type: messages.CONSOLE_BLURRED,
});
let state = this.store.getState();
if (state.mode === 'command') {
this.hideCommand();
}
}
onKeyDown(e) {
let doc = this.wrapper.ownerDocument;
let input = doc.querySelector('#vimvixen-console-command-input');
switch (e.keyCode) {
case KeyboardEvent.DOM_VK_ESCAPE:
return input.blur();
return this.hideCommand();
case KeyboardEvent.DOM_VK_RETURN:
return browser.runtime.sendMessage({
type: messages.CONSOLE_ENTERED,
text: e.target.value
}).then(this.onBlur);
return this.onEntered(e.target.value);
case KeyboardEvent.DOM_VK_TAB:
if (e.shiftKey) {
this.store.dispatch(consoleActions.completionPrev());
@ -54,6 +49,22 @@ export default class ConsoleComponent {
}
}
onEntered(value) {
let state = this.store.getState();
if (state.mode === 'command') {
browser.runtime.sendMessage({
type: messages.CONSOLE_ENTER_COMMAND,
text: value,
}).then(this.hideCommand);
} else if (state.mode === 'find') {
this.hideCommand();
window.top.postMessage(JSON.stringify({
type: messages.CONSOLE_ENTER_FIND,
text: value,
}), '*');
}
}
onInput(e) {
this.store.dispatch(consoleActions.setConsoleText(e.target.value));
@ -78,6 +89,13 @@ export default class ConsoleComponent {
}
}
hideCommand() {
this.store.dispatch(consoleActions.hideCommand());
window.top.postMessage(JSON.stringify({
type: messages.CONSOLE_UNFOCUS,
}), '*');
}
update() {
let state = this.store.getState();

View file

@ -24,8 +24,6 @@ const onMessage = (message) => {
return store.dispatch(consoleActions.showError(message.text));
case messages.CONSOLE_SHOW_INFO:
return store.dispatch(consoleActions.showInfo(message.text));
case messages.CONSOLE_HIDE_COMMAND:
return store.dispatch(consoleActions.hideCommand());
}
};