more strict lint
This commit is contained in:
parent
c5529958d5
commit
9ae814dfe4
21 changed files with 211 additions and 157 deletions
|
@ -5,9 +5,10 @@ import * as commandActions from '../actions/command';
|
|||
import * as consoleActions from '../actions/console';
|
||||
import reducers from '../reducers';
|
||||
import messages from '../messages';
|
||||
import * as store from '../store'
|
||||
import * as store from '../store';
|
||||
|
||||
let prevInput = [];
|
||||
|
||||
const backgroundStore = store.createStore(reducers, (e, sender) => {
|
||||
console.error('Vim-Vixen:', e);
|
||||
if (sender) {
|
||||
|
@ -15,9 +16,9 @@ const backgroundStore = store.createStore(reducers, (e, sender) => {
|
|||
}
|
||||
});
|
||||
backgroundStore.subscribe((sender) => {
|
||||
let currentInput = backgroundStore.getState().input
|
||||
let currentInput = backgroundStore.getState().input;
|
||||
if (JSON.stringify(prevInput) === JSON.stringify(currentInput)) {
|
||||
return
|
||||
return;
|
||||
}
|
||||
prevInput = currentInput;
|
||||
|
||||
|
@ -39,13 +40,14 @@ backgroundStore.subscribe((sender) => {
|
|||
|
||||
const keyQueueChanged = (state, sender) => {
|
||||
let prefix = keys.asKeymapChars(state.input.keys);
|
||||
let matched = Object.keys(keys.defaultKeymap).filter((keys) => {
|
||||
return keys.startsWith(prefix);
|
||||
let matched = Object.keys(keys.defaultKeymap).filter((keyStr) => {
|
||||
return keyStr.startsWith(prefix);
|
||||
});
|
||||
if (matched.length == 0) {
|
||||
if (matched.length === 0) {
|
||||
backgroundStore.dispatch(inputActions.clearKeys(), sender);
|
||||
return Promise.resolve();
|
||||
} else if (matched.length > 1 || matched.length === 1 && prefix !== matched[0]) {
|
||||
} else if (matched.length > 1 ||
|
||||
matched.length === 1 && prefix !== matched[0]) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
let action = keys.defaultKeymap[matched];
|
||||
|
@ -56,15 +58,19 @@ const keyQueueChanged = (state, sender) => {
|
|||
const handleMessage = (message, sender) => {
|
||||
switch (message.type) {
|
||||
case messages.KEYDOWN:
|
||||
return backgroundStore.dispatch(inputActions.keyPress(message.code, message.ctrl), sender);
|
||||
return backgroundStore.dispatch(
|
||||
inputActions.keyPress(message.code, message.ctrl), sender);
|
||||
case messages.CONSOLE_BLURRED:
|
||||
return backgroundStore.dispatch(consoleActions.hide(), sender);
|
||||
return backgroundStore.dispatch(
|
||||
consoleActions.hide(), sender);
|
||||
case messages.CONSOLE_ENTERED:
|
||||
return backgroundStore.dispatch(commandActions.exec(message.text), sender);
|
||||
return backgroundStore.dispatch(
|
||||
commandActions.exec(message.text), sender);
|
||||
case messages.CONSOLE_CHANGEED:
|
||||
return backgroundStore.dispatch(commandActions.complete(message.text), sender);
|
||||
return backgroundStore.dispatch(
|
||||
commandActions.complete(message.text), sender);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
browser.runtime.onMessage.addListener((message, sender) => {
|
||||
try {
|
||||
|
|
|
@ -30,28 +30,26 @@ const defaultKeymap = {
|
|||
'F': { type: operations.FOLLOW_START, newTab: true },
|
||||
'H': { type: operations.HISTORY_PREV },
|
||||
'L': { type: operations.HISTORY_NEXT },
|
||||
}
|
||||
};
|
||||
|
||||
const asKeymapChars = (keys) => {
|
||||
return keys.map((k) => {
|
||||
let c = String.fromCharCode(k.code);
|
||||
if (k.ctrl) {
|
||||
return '<C-' + c.toUpperCase() + '>';
|
||||
} else {
|
||||
return c
|
||||
}
|
||||
return c;
|
||||
}).join('');
|
||||
}
|
||||
};
|
||||
|
||||
const asCaretChars = (keys) => {
|
||||
return keys.map((k) => {
|
||||
let c = String.fromCharCode(k.code);
|
||||
if (k.ctrl) {
|
||||
return '^' + c.toUpperCase();
|
||||
} else {
|
||||
return c;
|
||||
}
|
||||
return c;
|
||||
}).join('');
|
||||
}
|
||||
};
|
||||
|
||||
export { defaultKeymap, asKeymapChars, asCaretChars };
|
||||
|
|
|
@ -12,9 +12,8 @@ const reopenTab = () => {
|
|||
let session = sessions[0];
|
||||
if (session.tab) {
|
||||
return browser.sessions.restore(session.tab.sessionId);
|
||||
} else {
|
||||
return browser.sessions.restore(session.window.sessionId);
|
||||
}
|
||||
return browser.sessions.restore(session.window.sessionId);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -24,20 +23,20 @@ const selectAt = (index) => {
|
|||
return;
|
||||
}
|
||||
if (index < 0 || tabs.length <= index) {
|
||||
throw new RangeError(`tab ${index} does not exist`)
|
||||
throw new RangeError(`tab ${index} does not exist`);
|
||||
}
|
||||
let id = tabs[index].id;
|
||||
return browser.tabs.update(id, { active: true })
|
||||
return browser.tabs.update(id, { active: true });
|
||||
});
|
||||
};
|
||||
|
||||
const selectByKeyword = (current, keyword) => {
|
||||
return browser.tabs.query({ currentWindow: true }).then((tabs) => {
|
||||
let matched = tabs.filter((t) => {
|
||||
return t.url.includes(keyword) || t.title.includes(keyword)
|
||||
})
|
||||
return t.url.includes(keyword) || t.title.includes(keyword);
|
||||
});
|
||||
|
||||
if (matched.length == 0) {
|
||||
if (matched.length === 0) {
|
||||
throw new RangeError('No matching buffer for ' + keyword);
|
||||
}
|
||||
for (let tab of matched) {
|
||||
|
@ -47,13 +46,13 @@ const selectByKeyword = (current, keyword) => {
|
|||
}
|
||||
return browser.tabs.update(matched[0].id, { active: true });
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
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 t.url.includes(keyword) || t.title.includes(keyword);
|
||||
});
|
||||
return matched;
|
||||
});
|
||||
};
|
||||
|
@ -63,9 +62,9 @@ const selectPrevTab = (current, count) => {
|
|||
if (tabs.length < 2) {
|
||||
return;
|
||||
}
|
||||
let select = (current - count) % tabs.length
|
||||
let select = (current - count) % tabs.length;
|
||||
let id = tabs[select].id;
|
||||
return browser.tabs.update(id, { active: true })
|
||||
return browser.tabs.update(id, { active: true });
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -74,9 +73,9 @@ const selectNextTab = (current, count) => {
|
|||
if (tabs.length < 2) {
|
||||
return;
|
||||
}
|
||||
let select = (current + count + tabs.length) % tabs.length
|
||||
let select = (current + count + tabs.length) % tabs.length;
|
||||
let id = tabs[select].id;
|
||||
return browser.tabs.update(id, { active: true })
|
||||
return browser.tabs.update(id, { active: true });
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -87,4 +86,7 @@ const reload = (current, cache) => {
|
|||
);
|
||||
};
|
||||
|
||||
export { closeTab, reopenTab, selectAt, selectByKeyword, getCompletions, selectPrevTab, selectNextTab, reload };
|
||||
export {
|
||||
closeTab, reopenTab, selectAt, selectByKeyword, getCompletions,
|
||||
selectPrevTab, selectNextTab, reload
|
||||
};
|
||||
|
|
Reference in a new issue