Show info on yanked

jh-changes
Shin'ya Ueoka 7 years ago
parent b0d2b53281
commit 7ac00fce6f
  1. 9
      src/console/actions/console.js
  2. 3
      src/console/actions/index.js
  3. 27
      src/console/components/console.js
  4. 4
      src/console/index.html
  5. 25
      src/console/index.js
  6. 5
      src/console/reducers/index.js
  7. 10
      src/console/site.scss
  8. 7
      src/content/actions/operation.js
  9. 7
      src/content/console-frames.js
  10. 1
      src/shared/messages.js
  11. 8
      test/console/actions/console.test.js
  12. 7
      test/console/reducers/console.test.js

@ -14,6 +14,13 @@ const showError = (text) => {
};
};
const showInfo = (text) => {
return {
type: actions.CONSOLE_SHOW_INFO,
text: text
};
};
const hideCommand = () => {
return {
type: actions.CONSOLE_HIDE_COMMAND,
@ -40,6 +47,6 @@ const completionPrev = () => {
};
export {
showCommand, showError, hideCommand,
showCommand, showError, showInfo, hideCommand,
setCompletions, completionNext, completionPrev
};

@ -1,9 +1,10 @@
export default {
// console commands
CONSOLE_SHOW_COMMAND: 'console.show.command',
CONSOLE_SET_COMPLETIONS: 'console.set.completions',
CONSOLE_SHOW_ERROR: 'console.show.error',
CONSOLE_SHOW_INFO: 'console.show.info',
CONSOLE_HIDE_COMMAND: 'console.hide.command',
CONSOLE_SET_COMPLETIONS: 'console.set.completions',
CONSOLE_COMPLETION_NEXT: 'console.completion.next',
CONSOLE_COMPLETION_PREV: 'console.completion.prev',
};

@ -16,7 +16,7 @@ export default class ConsoleComponent {
input.addEventListener('keyup', this.onKeyUp.bind(this));
this.hideCommand();
this.hideError();
this.hideMessage();
}
onBlur() {
@ -78,11 +78,10 @@ export default class ConsoleComponent {
this.hideCommand();
}
if (state.mode === 'error') {
this.setErrorText(state.messageText);
this.showError();
if (state.mode === 'error' || state.mode === 'info') {
this.showMessage(state.mode, state.messageText);
} else {
this.hideError();
this.hideMessage();
}
if (state.groupSelection >= 0 && state.itemSelection >= 0) {
@ -128,21 +127,21 @@ export default class ConsoleComponent {
input.value = this.completionOrigin;
}
setErrorText(text) {
showMessage(mode, text) {
let doc = this.wrapper.ownerDocument;
let error = doc.querySelector('#vimvixen-console-error');
let error = doc.querySelector('#vimvixen-console-message');
error.classList.remove(
'vimvixen-console-info',
'vimvixen-console-error'
);
error.classList.add('vimvixen-console-' + mode);
error.textContent = text;
}
showError() {
let doc = this.wrapper.ownerDocument;
let error = doc.querySelector('#vimvixen-console-error');
error.style.display = 'block';
}
hideError() {
hideMessage() {
let doc = this.wrapper.ownerDocument;
let error = doc.querySelector('#vimvixen-console-error');
let error = doc.querySelector('#vimvixen-console-message');
error.style.display = 'none';
}
}

@ -6,8 +6,8 @@
<script src='console.js'></script>
</head>
<body class='vimvixen-console'>
<p id='vimvixen-console-error'
class='vimvixen-console-error'></p>
<p id='vimvixen-console-message'
class='vimvixen-console-message'></p>
<div id='vimvixen-console-command'>
<ul id='vimvixen-console-completion' class='vimvixen-console-completion'></ul>
<div class='vimvixen-console-command'>

@ -17,18 +17,25 @@ window.addEventListener('load', () => {
consoleComponent = new ConsoleComponent(document.body, store);
});
store.subscribe(() => {
completionComponent.update();
consoleComponent.update();
});
browser.runtime.onMessage.addListener((action) => {
switch (action.type) {
const onMessage = (message) => {
switch (message.type) {
case messages.CONSOLE_SHOW_COMMAND:
return store.dispatch(consoleActions.showCommand(action.command));
return store.dispatch(consoleActions.showCommand(message.command));
case messages.CONSOLE_SHOW_ERROR:
return store.dispatch(consoleActions.showError(action.text));
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());
}
};
store.subscribe(() => {
completionComponent.update();
consoleComponent.update();
});
browser.runtime.onMessage.addListener(onMessage);
window.addEventListener('message', (message) => {
onMessage(JSON.parse(message.data));
}, false);

@ -57,6 +57,11 @@ export default function reducer(state = defaultState, action = {}) {
mode: 'error',
messageText: action.text,
});
case actions.CONSOLE_SHOW_INFO:
return Object.assign({}, state, {
mode: 'info',
messageText: action.text,
});
case actions.CONSOLE_HIDE_COMMAND:
return Object.assign({}, state, {
mode: state.mode === 'command' ? '' : state.mode,

@ -64,12 +64,20 @@ body {
}
}
&-message {
@include consoole-font;
}
&-error {
background-color: red;
font-weight: bold;
color: white;
}
@include consoole-font;
&-info {
background-color: white;
font-weight: normal;
color: green;
}
&-command {

@ -4,6 +4,7 @@ import * as scrolls from 'content/scrolls';
import * as navigates from 'content/navigates';
import * as urls from 'content/urls';
import * as followActions from 'content/actions/follow';
import * as consoleFrames from 'content/console-frames';
const exec = (operation) => {
switch (operation.type) {
@ -34,7 +35,11 @@ const exec = (operation) => {
case operations.NAVIGATE_ROOT:
return navigates.root(window);
case operations.URLS_YANK:
return urls.yank(window);
urls.yank(window);
return consoleFrames.postMessage(window.document, {
type: messages.CONSOLE_SHOW_INFO,
text: 'Current url yanked',
});
default:
browser.runtime.sendMessage({
type: messages.BACKGROUND_OPERATION,

@ -15,4 +15,9 @@ const blur = (doc) => {
iframe.blur();
};
export { initialize, blur };
const postMessage = (doc, message) => {
let iframe = doc.getElementById('vimvixen-console-frame');
iframe.contentWindow.postMessage(JSON.stringify(message), '*');
};
export { initialize, blur, postMessage };

@ -8,6 +8,7 @@ export default {
CONSOLE_QUERY_COMPLETIONS: 'console.query.completions',
CONSOLE_SHOW_COMMAND: 'console.show.command',
CONSOLE_SHOW_ERROR: 'console.show.error',
CONSOLE_SHOW_INFO: 'console.show.info',
CONSOLE_HIDE_COMMAND: 'console.hide.command',
OPEN_URL: 'open.url',

@ -11,6 +11,14 @@ describe("console actions", () => {
});
});
describe("showInfo", () => {
it('create CONSOLE_SHOW_INFO action', () => {
let action = consoleActions.showInfo('an info');
expect(action.type).to.equal(actions.CONSOLE_SHOW_INFO);
expect(action.text).to.equal('an info');
});
});
describe("showError", () => {
it('create CONSOLE_SHOW_ERROR action', () => {
let action = consoleActions.showError('an error');

@ -20,6 +20,13 @@ describe("console reducer", () => {
expect(state).to.have.property('commandText', 'open ');
});
it('return next state for CONSOLE_SHOW_INFO', () => {
let action = { type: actions.CONSOLE_SHOW_INFO, text: 'an info' };
let state = reducer({}, action);
expect(state).to.have.property('mode', 'info');
expect(state).to.have.property('messageText', 'an info');
});
it('return next state for CONSOLE_SHOW_ERROR', () => {
let action = { type: actions.CONSOLE_SHOW_ERROR, text: 'an error' };
let state = reducer({}, action);