diff options
Diffstat (limited to 'src')
50 files changed, 796 insertions, 266 deletions
diff --git a/src/background/actions/command.js b/src/background/actions/command.js index 4c52bca..f1ee5b5 100644 --- a/src/background/actions/command.js +++ b/src/background/actions/command.js @@ -1,5 +1,7 @@ +import messages from 'shared/messages'; import actions from '../actions'; -import * as tabs from 'background/tabs'; +import * as tabs from '../shared/tabs'; +import * as bookmarks from '../shared/bookmarks'; import * as parsers from 'shared/commands/parsers'; import * as properties from 'shared/settings/properties'; @@ -17,6 +19,14 @@ const tabopenCommand = (url) => { return browser.tabs.create({ url: url }); }; +const tabcloseCommand = () => { + return browser.tabs.query({ + active: true, currentWindow: true + }).then((tabList) => { + return browser.tabs.remove(tabList.map(tab => tab.id)); + }); +}; + const winopenCommand = (url) => { return browser.windows.create({ url }); }; @@ -39,6 +49,14 @@ const bufferCommand = (keywords) => { }); }; +const addBookmarkCommand = (tab, args) => { + if (!args[0]) { + return Promise.resolve(); + } + + return bookmarks.create(args.join(' '), tab.url); +}; + const setCommand = (args) => { if (!args[0]) { return Promise.resolve(); @@ -52,7 +70,8 @@ const setCommand = (args) => { }; }; -const exec = (line, settings) => { +// eslint-disable-next-line complexity +const exec = (tab, line, settings) => { let [name, args] = parsers.parseCommandLine(line); switch (name) { @@ -68,8 +87,36 @@ const exec = (line, settings) => { case 'b': case 'buffer': return bufferCommand(args); + case 'bd': + case 'bdel': + case 'bdelete': + return tabs.closeTabByKeywords(args.join(' ')); + case 'bd!': + case 'bdel!': + case 'bdelete!': + return tabs.closeTabByKeywordsForce(args.join(' ')); + case 'bdeletes': + return tabs.closeTabsByKeywords(args.join(' ')); + case 'bdeletes!': + return tabs.closeTabsByKeywordsForce(args.join(' ')); + case 'addbookmark': + return addBookmarkCommand(tab, args).then((item) => { + if (!item) { + return browser.tabs.sendMessage(tab.id, { + type: messages.CONSOLE_SHOW_ERROR, + text: 'Could not create a bookmark', + }); + } + return browser.tabs.sendMessage(tab.id, { + type: messages.CONSOLE_SHOW_INFO, + text: 'Saved current page: ' + item.url, + }); + }); case 'set': return setCommand(args); + case 'q': + case 'quit': + return tabcloseCommand(); case '': return Promise.resolve(); } diff --git a/src/background/actions/find.js b/src/background/actions/find.js new file mode 100644 index 0000000..8da5572 --- /dev/null +++ b/src/background/actions/find.js @@ -0,0 +1,10 @@ +import actions from './index'; + +const setKeyword = (keyword) => { + return { + type: actions.FIND_SET_KEYWORD, + keyword, + }; +}; + +export { setKeyword }; diff --git a/src/background/actions/index.js b/src/background/actions/index.js index efe4074..3833389 100644 --- a/src/background/actions/index.js +++ b/src/background/actions/index.js @@ -2,4 +2,10 @@ export default { // Settings SETTING_SET_SETTINGS: 'setting.set.settings', SETTING_SET_PROPERTY: 'setting.set.property', + + // Find + FIND_SET_KEYWORD: 'find.set.keyword', + + // Tab + TAB_SELECTED: 'tab.selected', }; diff --git a/src/background/actions/operation.js b/src/background/actions/operation.js deleted file mode 100644 index 1188ea2..0000000 --- a/src/background/actions/operation.js +++ /dev/null @@ -1,82 +0,0 @@ -import operations from 'shared/operations'; -import messages from 'shared/messages'; -import * as tabs from 'background/tabs'; -import * as zooms from 'background/zooms'; - -const sendConsoleShowCommand = (tab, command) => { - return browser.tabs.sendMessage(tab.id, { - type: messages.CONSOLE_SHOW_COMMAND, - command, - }); -}; - -// This switch statement is only gonna get longer as more -// features are added, so disable complexity check -/* eslint-disable complexity */ -const exec = (operation, tab) => { - switch (operation.type) { - case operations.TAB_CLOSE: - return tabs.closeTab(tab.id); - case operations.TAB_CLOSE_FORCE: - return tabs.closeTabForce(tab.id); - case operations.TAB_REOPEN: - return tabs.reopenTab(); - case operations.TAB_PREV: - return tabs.selectPrevTab(tab.index, operation.count); - case operations.TAB_NEXT: - return tabs.selectNextTab(tab.index, operation.count); - case operations.TAB_FIRST: - return tabs.selectFirstTab(); - case operations.TAB_LAST: - return tabs.selectLastTab(); - case operations.TAB_PREV_SEL: - return tabs.selectPrevSelTab(); - case operations.TAB_RELOAD: - return tabs.reload(tab, operation.cache); - case operations.TAB_PIN: - return tabs.updateTabPinned(tab, true); - case operations.TAB_UNPIN: - return tabs.updateTabPinned(tab, false); - case operations.TAB_TOGGLE_PINNED: - return tabs.toggleTabPinned(tab); - case operations.TAB_DUPLICATE: - return tabs.duplicate(tab.id); - case operations.ZOOM_IN: - return zooms.zoomIn(); - case operations.ZOOM_OUT: - return zooms.zoomOut(); - case operations.ZOOM_NEUTRAL: - return zooms.neutral(); - case operations.COMMAND_SHOW: - return sendConsoleShowCommand(tab, ''); - case operations.COMMAND_SHOW_OPEN: - if (operation.alter) { - // alter url - return sendConsoleShowCommand(tab, 'open ' + tab.url); - } - return sendConsoleShowCommand(tab, 'open '); - case operations.COMMAND_SHOW_TABOPEN: - if (operation.alter) { - // alter url - return sendConsoleShowCommand(tab, 'tabopen ' + tab.url); - } - return sendConsoleShowCommand(tab, 'tabopen '); - case operations.COMMAND_SHOW_WINOPEN: - if (operation.alter) { - // alter url - return sendConsoleShowCommand(tab, 'winopen ' + tab.url); - } - return sendConsoleShowCommand(tab, 'winopen '); - case operations.COMMAND_SHOW_BUFFER: - return sendConsoleShowCommand(tab, 'buffer '); - case operations.FIND_START: - return browser.tabs.sendMessage(tab.id, { - type: messages.CONSOLE_SHOW_FIND - }); - default: - return Promise.resolve(); - } -}; -/* eslint-enable complexity */ - -export { exec }; diff --git a/src/background/actions/tab.js b/src/background/actions/tab.js index e512b6f..0d439fd 100644 --- a/src/background/actions/tab.js +++ b/src/background/actions/tab.js @@ -1,9 +1,30 @@ -const openNewTab = (url) => { - return browser.tabs.create({ url: url }); +import actions from './index'; + +const openNewTab = (url, openerTabId, background = false, adjacent = false) => { + if (adjacent) { + return browser.tabs.query({ + active: true, currentWindow: true + }).then((tabs) => { + return browser.tabs.create({ + url, + openerTabId, + active: !background, + index: tabs[0].index + 1 + }); + }); + } + return browser.tabs.create({ url, active: !background }); }; const openToTab = (url, tab) => { return browser.tabs.update(tab.id, { url: url }); }; -export { openToTab, openNewTab }; +const selected = (tabId) => { + return { + type: actions.TAB_SELECTED, + tabId, + }; +}; + +export { openNewTab, openToTab, selected }; diff --git a/src/background/components/background.js b/src/background/components/background.js index 9578e78..29124a6 100644 --- a/src/background/components/background.js +++ b/src/background/components/background.js @@ -1,9 +1,9 @@ import messages from 'shared/messages'; -import * as operationActions from 'background/actions/operation'; import * as commandActions from 'background/actions/command'; import * as settingActions from 'background/actions/setting'; +import * as findActions from 'background/actions/find'; import * as tabActions from 'background/actions/tab'; -import * as commands from 'shared/commands'; +import * as completions from '../shared/completions'; export default class BackgroundComponent { constructor(store) { @@ -23,31 +23,36 @@ export default class BackgroundComponent { onMessage(message, sender) { let settings = this.store.getState().setting; + let find = this.store.getState().find; + switch (message.type) { - case messages.BACKGROUND_OPERATION: - return this.store.dispatch( - operationActions.exec(message.operation, sender.tab), - sender); case messages.OPEN_URL: if (message.newTab) { - return this.store.dispatch( - tabActions.openNewTab(message.url), sender); + let action = tabActions.openNewTab( + message.url, sender.tab.id, message.background, + settings.value.properties.adjacenttab); + return this.store.dispatch(action, sender); } return this.store.dispatch( tabActions.openToTab(message.url, sender.tab), sender); case messages.CONSOLE_ENTER_COMMAND: this.store.dispatch( - commandActions.exec(message.text, settings.value), + commandActions.exec(sender.tab, message.text, settings.value), sender ); return this.broadcastSettingsChanged(); case messages.SETTINGS_QUERY: return Promise.resolve(this.store.getState().setting.value); case messages.CONSOLE_QUERY_COMPLETIONS: - return commands.complete(message.text, settings.value); + return completions.complete(message.text, settings.value); case messages.SETTINGS_RELOAD: this.store.dispatch(settingActions.load()); return this.broadcastSettingsChanged(); + case messages.FIND_GET_KEYWORD: + return Promise.resolve(find.keyword); + case messages.FIND_SET_KEYWORD: + this.store.dispatch(findActions.setKeyword(message.keyword)); + return Promise.resolve({}); } } diff --git a/src/background/components/indicator.js b/src/background/components/indicator.js new file mode 100644 index 0000000..cceb119 --- /dev/null +++ b/src/background/components/indicator.js @@ -0,0 +1,45 @@ +import * as indicators from '../shared/indicators'; +import messages from 'shared/messages'; + +export default class IndicatorComponent { + constructor(store) { + this.store = store; + + messages.onMessage(this.onMessage.bind(this)); + + browser.browserAction.onClicked.addListener(this.onClicked); + browser.tabs.onActivated.addListener((info) => { + return browser.tabs.query({ currentWindow: true }).then(() => { + return this.onTabActivated(info); + }); + }); + } + + onTabActivated(info) { + return browser.tabs.sendMessage(info.tabId, { + type: messages.ADDON_ENABLED_QUERY, + }).then((resp) => { + return this.updateIndicator(resp.enabled); + }); + } + + onClicked(tab) { + browser.tabs.sendMessage(tab.id, { + type: messages.ADDON_TOGGLE_ENABLED, + }); + } + + onMessage(message) { + switch (message.type) { + case messages.ADDON_ENABLED_RESPONSE: + return this.updateIndicator(message.enabled); + } + } + + updateIndicator(enabled) { + if (enabled) { + return indicators.enable(); + } + return indicators.disable(); + } +} diff --git a/src/background/components/operation.js b/src/background/components/operation.js new file mode 100644 index 0000000..58edb8c --- /dev/null +++ b/src/background/components/operation.js @@ -0,0 +1,123 @@ +import messages from 'shared/messages'; +import operations from 'shared/operations'; +import * as tabs from '../shared//tabs'; +import * as zooms from '../shared/zooms'; + +export default class BackgroundComponent { + constructor(store) { + this.store = store; + + browser.runtime.onMessage.addListener((message, sender) => { + try { + return this.onMessage(message, sender); + } catch (e) { + return browser.tabs.sendMessage(sender.tab.id, { + type: messages.CONSOLE_SHOW_ERROR, + text: e.message, + }); + } + }); + } + + onMessage(message, sender) { + switch (message.type) { + case messages.BACKGROUND_OPERATION: + return this.store.dispatch( + this.exec(message.operation, sender.tab), + sender); + } + } + + // eslint-disable-next-line complexity + exec(operation, tab) { + let tabState = this.store.getState().tab; + + switch (operation.type) { + case operations.TAB_CLOSE: + return tabs.closeTab(tab.id); + case operations.TAB_CLOSE_FORCE: + return tabs.closeTabForce(tab.id); + case operations.TAB_REOPEN: + return tabs.reopenTab(); + case operations.TAB_PREV: + return tabs.selectPrevTab(tab.index, operation.count); + case operations.TAB_NEXT: + return tabs.selectNextTab(tab.index, operation.count); + case operations.TAB_FIRST: + return tabs.selectFirstTab(); + case operations.TAB_LAST: + return tabs.selectLastTab(); + case operations.TAB_PREV_SEL: + if (tabState.previousSelected > 0) { + return tabs.selectTab(tabState.previousSelected); + } + break; + case operations.TAB_RELOAD: + return tabs.reload(tab, operation.cache); + case operations.TAB_PIN: + return tabs.updateTabPinned(tab, true); + case operations.TAB_UNPIN: + return tabs.updateTabPinned(tab, false); + case operations.TAB_TOGGLE_PINNED: + return tabs.toggleTabPinned(tab); + case operations.TAB_DUPLICATE: + return tabs.duplicate(tab.id); + case operations.ZOOM_IN: + return zooms.zoomIn(); + case operations.ZOOM_OUT: + return zooms.zoomOut(); + case operations.ZOOM_NEUTRAL: + return zooms.neutral(); + case operations.COMMAND_SHOW: + return this.sendConsoleShowCommand(tab, ''); + case operations.COMMAND_SHOW_OPEN: + if (operation.alter) { + // alter url + return this.sendConsoleShowCommand(tab, 'open ' + tab.url); + } + return this.sendConsoleShowCommand(tab, 'open '); + case operations.COMMAND_SHOW_TABOPEN: + if (operation.alter) { + // alter url + return this.sendConsoleShowCommand(tab, 'tabopen ' + tab.url); + } + return this.sendConsoleShowCommand(tab, 'tabopen '); + case operations.COMMAND_SHOW_WINOPEN: + if (operation.alter) { + // alter url + return this.sendConsoleShowCommand(tab, 'winopen ' + tab.url); + } + return this.sendConsoleShowCommand(tab, 'winopen '); + case operations.COMMAND_SHOW_BUFFER: + return this.sendConsoleShowCommand(tab, 'buffer '); + case operations.COMMAND_SHOW_ADDBOOKMARK: + if (operation.alter) { + return this.sendConsoleShowCommand(tab, 'addbookmark ' + tab.title); + } + return this.sendConsoleShowCommand(tab, 'addbookmark '); + case operations.FIND_START: + return browser.tabs.sendMessage(tab.id, { + type: messages.CONSOLE_SHOW_FIND + }); + case operations.CANCEL: + return browser.tabs.sendMessage(tab.id, { + type: messages.CONSOLE_HIDE, + }); + case operations.PAGE_SOURCE: + return browser.tabs.create({ + url: 'view-source:' + tab.url, + index: tab.index + 1, + openerTabId: tab.id, + }); + default: + return Promise.resolve(); + } + } + + sendConsoleShowCommand(tab, command) { + return browser.tabs.sendMessage(tab.id, { + type: messages.CONSOLE_SHOW_COMMAND, + command, + }); + } +} diff --git a/src/background/components/tab.js b/src/background/components/tab.js new file mode 100644 index 0000000..b273546 --- /dev/null +++ b/src/background/components/tab.js @@ -0,0 +1,17 @@ +import * as tabActions from '../actions/tab'; + +export default class TabComponent { + constructor(store) { + this.store = store; + + browser.tabs.onActivated.addListener((info) => { + return browser.tabs.query({ currentWindow: true }).then(() => { + return this.onTabActivated(info); + }); + }); + } + + onTabActivated(info) { + return this.store.dispatch(tabActions.selected(info.tabId)); + } +} diff --git a/src/background/index.js b/src/background/index.js index 3ef712f..3f1013c 100644 --- a/src/background/index.js +++ b/src/background/index.js @@ -1,8 +1,12 @@ import * as settingActions from 'background/actions/setting'; import messages from 'shared/messages'; import BackgroundComponent from 'background/components/background'; +import OperationComponent from 'background/components/operation'; +import TabComponent from 'background/components/tab'; +import IndicatorComponent from 'background/components/indicator'; import reducers from 'background/reducers'; import { createStore } from 'shared/store'; +import * as versions from 'shared/versions'; const store = createStore(reducers, (e, sender) => { console.error('Vim-Vixen:', e); @@ -13,7 +17,21 @@ const store = createStore(reducers, (e, sender) => { }); } }); -// eslint-disable-next-line no-unused-vars + +/* eslint-disable no-unused-vars */ const backgroundComponent = new BackgroundComponent(store); +const operationComponent = new OperationComponent(store); +const tabComponent = new TabComponent(store); +const indicatorComponent = new IndicatorComponent(store); +/* eslint-enable no-unused-vars */ store.dispatch(settingActions.load()); + +versions.checkUpdated().then((updated) => { + if (!updated) { + return; + } + return versions.notify(); +}).then(() => { + return versions.commit(); +}); diff --git a/src/background/reducers/find.js b/src/background/reducers/find.js new file mode 100644 index 0000000..4ded801 --- /dev/null +++ b/src/background/reducers/find.js @@ -0,0 +1,16 @@ +import actions from 'content/actions'; + +const defaultState = { + keyword: null, +}; + +export default function reducer(state = defaultState, action = {}) { + switch (action.type) { + case actions.FIND_SET_KEYWORD: + return Object.assign({}, state, { + keyword: action.keyword, + }); + default: + return state; + } +} diff --git a/src/background/reducers/index.js b/src/background/reducers/index.js index dab0c62..5729f0a 100644 --- a/src/background/reducers/index.js +++ b/src/background/reducers/index.js @@ -1,12 +1,18 @@ import settingReducer from './setting'; +import findReducer from './find'; +import tabReducer from './tab'; // Make setting reducer instead of re-use const defaultState = { setting: settingReducer(undefined, {}), + find: findReducer(undefined, {}), + tab: tabReducer(undefined, {}), }; export default function reducer(state = defaultState, action = {}) { return Object.assign({}, state, { setting: settingReducer(state.setting, action), + find: findReducer(state.find, action), + tab: tabReducer(state.tab, action), }); } diff --git a/src/background/reducers/tab.js b/src/background/reducers/tab.js new file mode 100644 index 0000000..e0cdf32 --- /dev/null +++ b/src/background/reducers/tab.js @@ -0,0 +1,19 @@ +import actions from 'background/actions'; + +const defaultState = { + previousSelected: -1, + currentSelected: -1, +}; + +export default function reducer(state = defaultState, action = {}) { + switch (action.type) { + case actions.TAB_SELECTED: + return { + previousSelected: state.currentSelected, + currentSelected: action.tabId, + }; + default: + return state; + } +} + diff --git a/src/background/shared/bookmarks.js b/src/background/shared/bookmarks.js new file mode 100644 index 0000000..5e7927b --- /dev/null +++ b/src/background/shared/bookmarks.js @@ -0,0 +1,9 @@ +const create = (title, url) => { + return browser.bookmarks.create({ + type: 'bookmark', + title, + url, + }); +}; + +export { create }; diff --git a/src/background/shared/completions/bookmarks.js b/src/background/shared/completions/bookmarks.js new file mode 100644 index 0000000..1adb350 --- /dev/null +++ b/src/background/shared/completions/bookmarks.js @@ -0,0 +1,15 @@ +const getCompletions = (keywords) => { + return browser.bookmarks.search({ query: keywords }).then((items) => { + return items.filter((item) => { + let url = undefined; + try { + url = new URL(item.url); + } catch (e) { + return false; + } + return item.type === 'bookmark' && url.protocol !== 'place:'; + }).slice(0, 10); + }); +}; + +export { getCompletions }; diff --git a/src/background/histories.js b/src/background/shared/completions/histories.js index a7d3d47..a7d3d47 100644 --- a/src/background/histories.js +++ b/src/background/shared/completions/histories.js diff --git a/src/background/shared/completions/index.js b/src/background/shared/completions/index.js new file mode 100644 index 0000000..728cee7 --- /dev/null +++ b/src/background/shared/completions/index.js @@ -0,0 +1,129 @@ +import * as tabs from './tabs'; +import * as histories from './histories'; +import * as bookmarks from './bookmarks'; + +const getSearchCompletions = (command, keywords, searchConfig) => { + let engineNames = Object.keys(searchConfig.engines); + let engineItems = engineNames.filter(name => name.startsWith(keywords)) + .map(name => ({ + caption: name, + content: command + ' ' + name + })); + return Promise.resolve(engineItems); +}; + +const getHistoryCompletions = (command, keywords) => { + return histories.getCompletions(keywords).then((pages) => { + return pages.map((page) => { + return { + caption: page.title, + content: command + ' ' + page.url, + url: page.url + }; + }); + }); +}; + +const getBookmarksCompletions = (command, keywords) => { + return bookmarks.getCompletions(keywords).then((items) => { + return items.map((item) => { + return { + caption: item.title, + content: command + ' ' + item.url, + url: item.url, + }; + }); + }); +}; + +const getOpenCompletions = (command, keywords, searchConfig) => { + return Promise.all([ + getSearchCompletions(command, keywords, searchConfig), + getHistoryCompletions(command, keywords), + getBookmarksCompletions(command, keywords), + ]).then(([engineItems, historyItems, bookmarkItems]) => { + let completions = []; + if (engineItems.length > 0) { + completions.push({ + name: 'Search Engines', + items: engineItems + }); + } + if (historyItems.length > 0) { + completions.push({ + name: 'History', + items: historyItems + }); + } + if (bookmarkItems.length > 0) { + completions.push({ + name: 'Bookmarks', + items: bookmarkItems + }); + } + return completions; + }); +}; + +const getBufferCompletions = (command, keywords, excludePinned) => { + return tabs.getCompletions(keywords, excludePinned).then((got) => { + let items = got.map((tab) => { + return { + caption: tab.title, + content: command + ' ' + tab.title, + url: tab.url, + icon: tab.favIconUrl + }; + }); + return [ + { + name: 'Buffers', + items: items + } + ]; + }); +}; + +const getCompletions = (line, settings) => { + let typedWords = line.trim().split(/ +/); + let typing = ''; + if (!line.endsWith(' ')) { + typing = typedWords.pop(); + } + + if (typedWords.length === 0) { + return Promise.resolve([]); + } + let name = typedWords.shift(); + let keywords = typedWords.concat(typing).join(' '); + + switch (name) { + case 'o': + case 'open': + case 't': + case 'tabopen': + case 'w': + case 'winopen': + return getOpenCompletions(name, keywords, settings.search); + case 'b': + case 'buffer': + return getBufferCompletions(name, keywords, false); + case 'bd!': + case 'bdel!': + case 'bdelete!': + case 'bdeletes!': + return getBufferCompletions(name, keywords, false); + case 'bd': + case 'bdel': + case 'bdelete': + case 'bdeletes': + return getBufferCompletions(name, keywords, true); + } + return Promise.resolve([]); +}; + +const complete = (line, settings) => { + return getCompletions(line, settings); +}; + +export { complete }; diff --git a/src/background/shared/completions/tabs.js b/src/background/shared/completions/tabs.js new file mode 100644 index 0000000..bdb2741 --- /dev/null +++ b/src/background/shared/completions/tabs.js @@ -0,0 +1,8 @@ +import * as tabs from '../tabs'; + +const getCompletions = (keyword, excludePinned) => { + return tabs.queryByKeyword(keyword, excludePinned); +}; + + +export { getCompletions }; diff --git a/src/background/shared/indicators.js b/src/background/shared/indicators.js new file mode 100644 index 0000000..74002c4 --- /dev/null +++ b/src/background/shared/indicators.js @@ -0,0 +1,13 @@ +const enable = () => { + return browser.browserAction.setIcon({ + path: 'resources/enabled_32x32.png', + }); +}; + +const disable = () => { + return browser.browserAction.setIcon({ + path: 'resources/disabled_32x32.png', + }); +}; + +export { enable, disable }; diff --git a/src/background/tabs.js b/src/background/shared/tabs.js index e939870..62e26ac 100644 --- a/src/background/tabs.js +++ b/src/background/shared/tabs.js @@ -1,12 +1,4 @@ -let prevSelTab = 1; -let currSelTab = 1; - -browser.tabs.onActivated.addListener((activeInfo) => { - return browser.tabs.query({ currentWindow: true }).then(() => { - prevSelTab = currSelTab; - currSelTab = activeInfo.tabId; - }); -}); +import * as tabCompletions from './completions/tabs'; const closeTab = (id) => { return browser.tabs.get(id).then((tab) => { @@ -20,6 +12,52 @@ const closeTabForce = (id) => { return browser.tabs.remove(id); }; +const queryByKeyword = (keyword, excludePinned = false) => { + return browser.tabs.query({ currentWindow: true }).then((tabs) => { + return tabs.filter((t) => { + return t.url.toLowerCase().includes(keyword.toLowerCase()) || + t.title && t.title.toLowerCase().includes(keyword.toLowerCase()); + }).filter((t) => { + return !(excludePinned && t.pinned); + }); + }); +}; + +const closeTabByKeywords = (keyword) => { + return queryByKeyword(keyword, false).then((tabs) => { + if (tabs.length === 0) { + throw new Error('No matching buffer for ' + keyword); + } else if (tabs.length > 1) { + throw new Error('More than one match for ' + keyword); + } + browser.tabs.remove(tabs[0].id); + }); +}; + +const closeTabByKeywordsForce = (keyword) => { + return queryByKeyword(keyword, true).then((tabs) => { + if (tabs.length === 0) { + throw new Error('No matching buffer for ' + keyword); + } else if (tabs.length > 1) { + throw new Error('More than one match for ' + keyword); + } + browser.tabs.remove(tabs[0].id); + }); +}; + +const closeTabsByKeywords = (keyword) => { + tabCompletions.getCompletions(keyword).then((tabs) => { + let tabs2 = tabs.filter(tab => !tab.pinned); + browser.tabs.remove(tabs2.map(tab => tab.id)); + }); +}; + +const closeTabsByKeywordsForce = (keyword) => { + tabCompletions.getCompletions(keyword).then((tabs) => { + browser.tabs.remove(tabs.map(tab => tab.id)); + }); +}; + const reopenTab = () => { return browser.sessions.getRecentlyClosed({ maxResults: 1 @@ -49,29 +87,16 @@ const selectAt = (index) => { }; 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); - }); - - if (matched.length === 0) { + return queryByKeyword(keyword).then((tabs) => { + if (tabs.length === 0) { throw new RangeError('No matching buffer for ' + keyword); } - for (let tab of matched) { + for (let tab of tabs) { if (tab.index > current.index) { return browser.tabs.update(tab.id, { active: true }); } } - 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 && t.title.includes(keyword); - }); - return matched; + return browser.tabs.update(tabs[0].id, { active: true }); }); }; @@ -111,8 +136,8 @@ const selectLastTab = () => { }); }; -const selectPrevSelTab = () => { - return browser.tabs.update(prevSelTab, { active: true }); +const selectTab = (id) => { + return browser.tabs.update(id, { active: true }); }; const reload = (current, cache) => { @@ -138,8 +163,11 @@ const duplicate = (id) => { }; export { - closeTab, closeTabForce, reopenTab, selectAt, selectByKeyword, - getCompletions, selectPrevTab, selectNextTab, selectFirstTab, - selectLastTab, selectPrevSelTab, reload, updateTabPinned, + closeTab, closeTabForce, + queryByKeyword, closeTabByKeywords, closeTabByKeywordsForce, + closeTabsByKeywords, closeTabsByKeywordsForce, + reopenTab, selectAt, selectByKeyword, + selectPrevTab, selectNextTab, selectFirstTab, + selectLastTab, selectTab, reload, updateTabPinned, toggleTabPinned, duplicate }; diff --git a/src/background/zooms.js b/src/background/shared/zooms.js index e3e2aa6..e3e2aa6 100644 --- a/src/background/zooms.js +++ b/src/background/shared/zooms.js diff --git a/src/console/actions/console.js b/src/console/actions/console.js index 2cf8e8d..f80045f 100644 --- a/src/console/actions/console.js +++ b/src/console/actions/console.js @@ -1,5 +1,11 @@ import actions from 'console/actions'; +const hide = () => { + return { + type: actions.CONSOLE_HIDE, + }; +}; + const showCommand = (text) => { return { type: actions.CONSOLE_SHOW_COMMAND, @@ -61,6 +67,6 @@ const completionPrev = () => { }; export { - showCommand, showFind, showError, showInfo, hideCommand, setConsoleText, + hide, showCommand, showFind, showError, showInfo, hideCommand, setConsoleText, setCompletions, completionNext, completionPrev }; diff --git a/src/console/actions/index.js b/src/console/actions/index.js index a85e329..b394179 100644 --- a/src/console/actions/index.js +++ b/src/console/actions/index.js @@ -1,5 +1,6 @@ export default { // console commands + CONSOLE_HIDE: 'console.hide', CONSOLE_SHOW_COMMAND: 'console.show.command', CONSOLE_SHOW_ERROR: 'console.show.error', CONSOLE_SHOW_INFO: 'console.show.info', diff --git a/src/console/components/console.js b/src/console/components/console.js index 7c23dab..a9ae4ed 100644 --- a/src/console/components/console.js +++ b/src/console/components/console.js @@ -50,6 +50,9 @@ export default class ConsoleComponent { } onKeyDown(e) { + if (e.keyCode === KeyboardEvent.DOM_VK_ESCAPE && e.ctrlKey) { + return this.hideCommand(); + } switch (e.keyCode) { case KeyboardEvent.DOM_VK_ESCAPE: return this.hideCommand(); diff --git a/src/console/index.js b/src/console/index.js index 86edd9a..156456c 100644 --- a/src/console/index.js +++ b/src/console/index.js @@ -24,6 +24,8 @@ 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: + return store.dispatch(consoleActions.hide()); } }; diff --git a/src/console/reducers/index.js b/src/console/reducers/index.js index 60c0007..2aec55c 100644 --- a/src/console/reducers/index.js +++ b/src/console/reducers/index.js @@ -53,6 +53,10 @@ const nextConsoleText = (completions, group, item, defaults) => { export default function reducer(state = defaultState, action = {}) { switch (action.type) { + case actions.CONSOLE_HIDE: + return Object.assign({}, state, { + mode: '', + }); case actions.CONSOLE_SHOW_COMMAND: return Object.assign({}, state, { mode: 'command', diff --git a/src/content/actions/find.js b/src/content/actions/find.js index 80d6210..c7345cc 100644 --- a/src/content/actions/find.js +++ b/src/content/actions/find.js @@ -5,6 +5,7 @@ // NOTE: window.find is not standard API // https://developer.mozilla.org/en-US/docs/Web/API/Window/find +import messages from 'shared/messages'; import actions from 'content/actions'; import * as consoleFrames from '../console-frames'; @@ -14,6 +15,13 @@ const postPatternNotFound = (pattern) => { 'Pattern not found: ' + pattern); }; +const postPatternFound = (pattern) => { + return consoleFrames.postInfo( + window.document, + 'Pattern found: ' + pattern, + ); +}; + const find = (string, backwards) => { let caseSensitive = false; let wrapScan = true; @@ -24,32 +32,49 @@ const find = (string, backwards) => { return window.find(string, caseSensitive, backwards, wrapScan); }; -const findNext = (keyword, reset, backwards) => { +const findNext = (currentKeyword, reset, backwards) => { if (reset) { window.getSelection().removeAllRanges(); } - let found = find(keyword, backwards); - if (!found) { - window.getSelection().removeAllRanges(); - found = find(keyword, backwards); + let promise = Promise.resolve(currentKeyword); + if (currentKeyword) { + browser.runtime.sendMessage({ + type: messages.FIND_SET_KEYWORD, + keyword: currentKeyword, + }); + } else { + promise = browser.runtime.sendMessage({ + type: messages.FIND_GET_KEYWORD, + }); } - if (!found) { - postPatternNotFound(keyword); - } - return { - type: actions.FIND_SET_KEYWORD, - keyword, - found, - }; + + return promise.then((keyword) => { + let found = find(keyword, backwards); + if (!found) { + window.getSelection().removeAllRanges(); + found = find(keyword, backwards); + } + if (found) { + postPatternFound(keyword); + } else { + postPatternNotFound(keyword); + } + + return { + type: actions.FIND_SET_KEYWORD, + keyword, + found, + }; + }); }; -const next = (keyword, reset) => { - return findNext(keyword, reset, false); +const next = (currentKeyword, reset) => { + return findNext(currentKeyword, reset, false); }; -const prev = (keyword, reset) => { - return findNext(keyword, reset, true); +const prev = (currentKeyword, reset) => { + return findNext(currentKeyword, reset, true); }; export { next, prev }; diff --git a/src/content/actions/follow-controller.js b/src/content/actions/follow-controller.js index 3fd4dce..006b248 100644 --- a/src/content/actions/follow-controller.js +++ b/src/content/actions/follow-controller.js @@ -1,9 +1,10 @@ import actions from 'content/actions'; -const enable = (newTab) => { +const enable = (newTab, background) => { return { type: actions.FOLLOW_CONTROLLER_ENABLE, newTab, + background, }; }; diff --git a/src/content/actions/operation.js b/src/content/actions/operation.js index 5fd0f48..9171766 100644 --- a/src/content/actions/operation.js +++ b/src/content/actions/operation.js @@ -44,7 +44,8 @@ const exec = (operation, repeat, settings) => { case operations.FOLLOW_START: return window.top.postMessage(JSON.stringify({ type: messages.FOLLOW_START, - newTab: operation.newTab + newTab: operation.newTab, + background: operation.background, }), '*'); case operations.NAVIGATE_HISTORY_PREV: return navigates.historyPrev(window); @@ -62,10 +63,7 @@ const exec = (operation, repeat, settings) => { return focuses.focusInput(); case operations.URLS_YANK: urls.yank(window); - return consoleFrames.postMessage(window.document, { - type: messages.CONSOLE_SHOW_INFO, - text: 'Current url yanked', - }); + return consoleFrames.postInfo(window.document, 'Current url yanked'); case operations.URLS_PASTE: return urls.paste(window, operation.newTab ? operation.newTab : false); default: diff --git a/src/content/actions/setting.js b/src/content/actions/setting.js index 0238c71..4c1e385 100644 --- a/src/content/actions/setting.js +++ b/src/content/actions/setting.js @@ -1,10 +1,17 @@ import actions from 'content/actions'; import * as keyUtils from 'shared/utils/keys'; +import operations from 'shared/operations'; + +const reservedKeymaps = { + '<Esc>': { type: operations.CANCEL }, + '<C-[>': { type: operations.CANCEL }, +}; const set = (value) => { let entries = []; if (value.keymaps) { - entries = Object.entries(value.keymaps).map((entry) => { + let keymaps = Object.assign({}, value.keymaps, reservedKeymaps); + entries = Object.entries(keymaps).map((entry) => { return [ keyUtils.fromMapKeys(entry[0]), entry[1], diff --git a/src/content/components/common/follow.js b/src/content/components/common/follow.js index 42dd897..2a55ea3 100644 --- a/src/content/components/common/follow.js +++ b/src/content/components/common/follow.js @@ -50,6 +50,7 @@ export default class Follow { this.win = win; this.store = store; this.newTab = false; + this.background = false; this.hints = {}; this.targets = []; @@ -63,6 +64,7 @@ export default class Follow { this.win.parent.postMessage(JSON.stringify({ type: messages.FOLLOW_KEY_PRESS, key: key.key, + ctrlKey: key.ctrlKey, }), '*'); return true; } @@ -84,6 +86,7 @@ export default class Follow { type: messages.OPEN_URL, url: element.href, newTab: true, + background: this.background, }); } @@ -95,12 +98,13 @@ export default class Follow { }), '*'); } - createHints(keysArray, newTab) { + createHints(keysArray, newTab, background) { if (keysArray.length !== this.targets.length) { throw new Error('illegal hint count'); } this.newTab = newTab; + this.background = background; this.hints = {}; for (let i = 0; i < keysArray.length; ++i) { let keys = keysArray[i]; @@ -166,7 +170,8 @@ export default class Follow { case messages.FOLLOW_REQUEST_COUNT_TARGETS: return this.countHints(sender, message.viewSize, message.framePosition); case messages.FOLLOW_CREATE_HINTS: - return this.createHints(message.keysArray, message.newTab); + return this.createHints( + message.keysArray, message.newTab, message.background); case messages.FOLLOW_SHOW_HINTS: return this.showHints(message.keys); case messages.FOLLOW_ACTIVATE: diff --git a/src/content/components/common/index.js b/src/content/components/common/index.js index 565632c..9b7b083 100644 --- a/src/content/components/common/index.js +++ b/src/content/components/common/index.js @@ -3,6 +3,7 @@ import KeymapperComponent from './keymapper'; import FollowComponent from './follow'; import * as settingActions from 'content/actions/setting'; import messages from 'shared/messages'; +import * as addonActions from '../../actions/addon'; export default class Common { constructor(win, store) { @@ -14,16 +15,32 @@ export default class Common { input.onKey(key => keymapper.key(key)); this.store = store; + this.prevEnabled = undefined; this.reloadSettings(); messages.onMessage(this.onMessage.bind(this)); + store.subscribe(() => this.update()); } onMessage(message) { switch (message.type) { case messages.SETTINGS_CHANGED: - this.reloadSettings(); + return this.reloadSettings(); + case messages.ADDON_TOGGLE_ENABLED: + return this.store.dispatch(addonActions.toggleEnabled()); + } + } + + update() { + let enabled = this.store.getState().addon.enabled; + if (enabled !== this.prevEnabled) { + this.prevEnabled = enabled; + + browser.runtime.sendMessage({ + type: messages.ADDON_ENABLED_RESPONSE, + enabled, + }); } } diff --git a/src/content/components/common/input.js b/src/content/components/common/input.js index 22b0a91..eefaf10 100644 --- a/src/content/components/common/input.js +++ b/src/content/components/common/input.js @@ -1,6 +1,10 @@ import * as dom from 'shared/utils/dom'; import * as keys from 'shared/utils/keys'; +const cancelKey = (e) => { + return e.key === 'Escape' || e.key === '[' && e.ctrlKey; +}; + export default class InputComponent { constructor(target) { this.pressed = {}; @@ -37,7 +41,7 @@ export default class InputComponent { capture(e) { if (this.fromInput(e)) { - if (e.key === 'Escape' && e.target.blur) { + if (cancelKey(e) && e.target.blur) { e.target.blur(); } return; diff --git a/src/content/components/top-content/find.js b/src/content/components/top-content/find.js index bccf040..4d46d79 100644 --- a/src/content/components/top-content/find.js +++ b/src/content/components/top-content/find.js @@ -1,6 +1,5 @@ import * as findActions from 'content/actions/find'; import messages from 'shared/messages'; -import * as consoleFrames from '../../console-frames'; export default class FindComponent { constructor(win, store) { @@ -32,23 +31,11 @@ export default class FindComponent { next() { let state = this.store.getState().find; - - if (!state.found) { - return consoleFrames.postError( - window.document, - 'Pattern not found: ' + state.keyword); - } return this.store.dispatch(findActions.next(state.keyword, false)); } prev() { let state = this.store.getState().find; - - if (!state.found) { - return consoleFrames.postError( - window.document, - 'Pattern not found: ' + state.keyword); - } return this.store.dispatch(findActions.prev(state.keyword, false)); } } diff --git a/src/content/components/top-content/follow-controller.js b/src/content/components/top-content/follow-controller.js index 1e7f3cd..7f36604 100644 --- a/src/content/components/top-content/follow-controller.js +++ b/src/content/components/top-content/follow-controller.js @@ -28,11 +28,11 @@ export default class FollowController { switch (message.type) { case messages.FOLLOW_START: return this.store.dispatch( - followControllerActions.enable(message.newTab)); + followControllerActions.enable(message.newTab, message.background)); case messages.FOLLOW_RESPONSE_COUNT_TARGETS: return this.create(message.count, sender); case messages.FOLLOW_KEY_PRESS: - return this.keyPress(message.key); + return this.keyPress(message.key, message.ctrlKey); } } @@ -69,7 +69,11 @@ export default class FollowController { }); } - keyPress(key) { + keyPress(key, ctrlKey) { + if (key === '[' && ctrlKey) { + this.store.dispatch(followControllerActions.disable()); + return true; + } switch (key) { case 'Enter': this.activate(); @@ -125,6 +129,7 @@ export default class FollowController { type: messages.FOLLOW_CREATE_HINTS, keysArray: produced, newTab: this.state.newTab, + background: this.state.background, }), '*'); } diff --git a/src/content/components/top-content/index.js b/src/content/components/top-content/index.js index cf21ec4..a0d0480 100644 --- a/src/content/components/top-content/index.js +++ b/src/content/components/top-content/index.js @@ -44,15 +44,24 @@ export default class TopContent { .some(regex => regex.test(partial)); if (matched) { this.store.dispatch(addonActions.disable()); + } else { + this.store.dispatch(addonActions.enable()); } } onMessage(message) { + let addonState = this.store.getState().addon; + switch (message.type) { case messages.CONSOLE_UNFOCUS: this.win.focus(); consoleFrames.blur(window.document); return Promise.resolve(); + case messages.ADDON_ENABLED_QUERY: + return Promise.resolve({ + type: messages.ADDON_ENABLED_RESPONSE, + enabled: addonState.enabled, + }); } } } diff --git a/src/content/console-frames.js b/src/content/console-frames.js index 515ae09..0c0ec02 100644 --- a/src/content/console-frames.js +++ b/src/content/console-frames.js @@ -28,4 +28,11 @@ const postError = (doc, message) => { }); }; -export { initialize, blur, postMessage, postError }; +const postInfo = (doc, message) => { + return postMessage(doc, { + type: messages.CONSOLE_SHOW_INFO, + text: message, + }); +}; + +export { initialize, blur, postError, postInfo }; diff --git a/src/content/reducers/find.js b/src/content/reducers/find.js index eb43c37..8d63ee5 100644 --- a/src/content/reducers/find.js +++ b/src/content/reducers/find.js @@ -1,7 +1,7 @@ import actions from 'content/actions'; const defaultState = { - keyword: '', + keyword: null, found: false, }; diff --git a/src/content/reducers/follow-controller.js b/src/content/reducers/follow-controller.js index 2afb232..78fd848 100644 --- a/src/content/reducers/follow-controller.js +++ b/src/content/reducers/follow-controller.js @@ -3,6 +3,7 @@ import actions from 'content/actions'; const defaultState = { enabled: false, newTab: false, + background: false, keys: '', }; @@ -12,6 +13,7 @@ export default function reducer(state = defaultState, action = {}) { return Object.assign({}, state, { enabled: true, newTab: action.newTab, + background: action.background, keys: '', }); case actions.FOLLOW_CONTROLLER_DISABLE: diff --git a/src/settings/components/form/keymaps-form.jsx b/src/settings/components/form/keymaps-form.jsx index 0e4a223..f0f69cf 100644 --- a/src/settings/components/form/keymaps-form.jsx +++ b/src/settings/components/form/keymaps-form.jsx @@ -36,6 +36,7 @@ const KeyMapFields = [ ['navigate.link.prev', 'Open previous link'], ['navigate.parent', 'Go to parent directory'], ['navigate.root', 'Go to root directory'], + ['page.source', 'Open page source'], ['focus.input', 'Focus input'], ], [ ['find.start', 'Start find mode'], @@ -50,6 +51,7 @@ const KeyMapFields = [ ['command.show.winopen?{"alter":false}', 'Open URL in new window'], ['command.show.winopen?{"alter":true}', 'Alter URL in new window'], ['command.show.buffer', 'Open buffer command'], + ['command.show.addbookmark?{"alter":true}', 'Open addbookmark command'], ], [ ['addon.toggle.enabled', 'Enable or disable'], ['urls.yank', 'Copy current URL'], @@ -58,6 +60,7 @@ const KeyMapFields = [ ['zoom.in', 'Zoom-in'], ['zoom.out', 'Zoom-out'], ['zoom.neutral', 'Reset zoom level'], + ['page.source', 'Open a page source'], ] ]; diff --git a/src/settings/components/index.jsx b/src/settings/components/index.jsx index e96fac3..e13bfa1 100644 --- a/src/settings/components/index.jsx +++ b/src/settings/components/index.jsx @@ -83,7 +83,7 @@ class SettingsComponent extends Component { <Input type='textarea' name='json' - label='Plane JSON' + label='Plain JSON' spellCheck='false' error={this.state.errors.json} onChange={this.bindValue.bind(this)} diff --git a/src/shared/commands/complete.js b/src/shared/commands/complete.js deleted file mode 100644 index 0bdbab8..0000000 --- a/src/shared/commands/complete.js +++ /dev/null @@ -1,84 +0,0 @@ -import * as tabs from 'background/tabs'; -import * as histories from 'background/histories'; - -const getOpenCompletions = (command, keywords, searchConfig) => { - return histories.getCompletions(keywords).then((pages) => { - let historyItems = pages.map((page) => { - return { - caption: page.title, - content: command + ' ' + page.url, - url: page.url - }; - }); - let engineNames = Object.keys(searchConfig.engines); - let engineItems = engineNames.filter(name => name.startsWith(keywords)) - .map(name => ({ - caption: name, - content: command + ' ' + name - })); - - let completions = []; - if (engineItems.length > 0) { - completions.push({ - name: 'Search Engines', - items: engineItems - }); - } - if (historyItems.length > 0) { - completions.push({ - name: 'History', - items: historyItems - }); - } - return completions; - }); -}; - -const getCompletions = (line, settings) => { - let typedWords = line.trim().split(/ +/); - let typing = ''; - if (!line.endsWith(' ')) { - typing = typedWords.pop(); - } - - if (typedWords.length === 0) { - return Promise.resolve([]); - } - let name = typedWords.shift(); - let keywords = typedWords.concat(typing).join(' '); - - switch (name) { - case 'o': - case 'open': - case 't': - case 'tabopen': - case 'w': - case 'winopen': - return getOpenCompletions(name, keywords, settings.search); - case 'b': - case 'buffer': - return tabs.getCompletions(keywords).then((gotTabs) => { - let items = gotTabs.map((tab) => { - return { - caption: tab.title, - content: name + ' ' + tab.title, - url: tab.url, - icon: tab.favIconUrl - }; - }); - return [ - { - name: 'Buffers', - items: items - } - ]; - }); - } - return Promise.resolve([]); -}; - -const complete = (line, settings) => { - return getCompletions(line, settings); -}; - -export default complete; diff --git a/src/shared/commands/index.js b/src/shared/commands/index.js deleted file mode 100644 index 78cb4df..0000000 --- a/src/shared/commands/index.js +++ /dev/null @@ -1,3 +0,0 @@ -import complete from './complete'; - -export { complete }; diff --git a/src/shared/messages.js b/src/shared/messages.js index de00a3f..1f9c816 100644 --- a/src/shared/messages.js +++ b/src/shared/messages.js @@ -32,6 +32,7 @@ export default { CONSOLE_SHOW_ERROR: 'console.show.error', CONSOLE_SHOW_INFO: 'console.show.info', CONSOLE_SHOW_FIND: 'console.show.find', + CONSOLE_HIDE: 'console.hide', FOLLOW_START: 'follow.start', FOLLOW_REQUEST_COUNT_TARGETS: 'follow.request.count.targets', @@ -44,6 +45,12 @@ export default { FIND_NEXT: 'find.next', FIND_PREV: 'find.prev', + FIND_GET_KEYWORD: 'find.get.keyword', + FIND_SET_KEYWORD: 'find.set.keyword', + + ADDON_ENABLED_QUERY: 'addon.enabled.query', + ADDON_ENABLED_RESPONSE: 'addon.enabled.response', + ADDON_TOGGLE_ENABLED: 'addon.toggle.enabled', OPEN_URL: 'open.url', diff --git a/src/shared/operations.js b/src/shared/operations.js index 008e9eb..b022537 100644 --- a/src/shared/operations.js +++ b/src/shared/operations.js @@ -1,4 +1,7 @@ export default { + // Hide console, or cancel some user actions + CANCEL: 'cancel', + // Addons ADDON_ENABLE: 'addon.enable', ADDON_DISABLE: 'addon.disable', @@ -10,6 +13,7 @@ export default { COMMAND_SHOW_TABOPEN: 'command.show.tabopen', COMMAND_SHOW_WINOPEN: 'command.show.winopen', COMMAND_SHOW_BUFFER: 'command.show.buffer', + COMMAND_SHOW_ADDBOOKMARK: 'command.show.addbookmark', // Scrolls SCROLL_VERTICALLY: 'scroll.vertically', @@ -34,6 +38,9 @@ export default { // Focus FOCUS_INPUT: 'focus.input', + // Page + PAGE_SOURCE: 'page.source', + // Tabs TAB_CLOSE: 'tabs.close', TAB_CLOSE_FORCE: 'tabs.close.force', diff --git a/src/shared/settings/default.js b/src/shared/settings/default.js index 3c4dcac..a435099 100644 --- a/src/shared/settings/default.js +++ b/src/shared/settings/default.js @@ -11,6 +11,7 @@ export default { "w": { "type": "command.show.winopen", "alter": false }, "W": { "type": "command.show.winopen", "alter": true }, "b": { "type": "command.show.buffer" }, + "a": { "type": "command.show.addbookmark", "alter": true }, "k": { "type": "scroll.vertically", "count": -1 }, "j": { "type": "scroll.vertically", "count": 1 }, "h": { "type": "scroll.horizonally", "count": -1 }, @@ -27,6 +28,8 @@ export default { "u": { "type": "tabs.reopen" }, "K": { "type": "tabs.prev", "count": 1 }, "J": { "type": "tabs.next", "count": 1 }, + "gT": { "type": "tabs.prev", "count": 1 }, + "gt": { "type": "tabs.next", "count": 1 }, "g0": { "type": "tabs.first" }, "g$": { "type": "tabs.last" }, "<C-6>": { "type": "tabs.prevsel" }, @@ -37,8 +40,8 @@ export default { "zi": { "type": "zoom.in" }, "zo": { "type": "zoom.out" }, "zz": { "type": "zoom.neutral" }, - "f": { "type": "follow.start", "newTab": false }, - "F": { "type": "follow.start", "newTab": true }, + "f": { "type": "follow.start", "newTab": false, "background": false }, + "F": { "type": "follow.start", "newTab": true, "background": false }, "H": { "type": "navigate.history.prev" }, "L": { "type": "navigate.history.next" }, "[[": { "type": "navigate.link.prev" }, @@ -46,6 +49,7 @@ export default { "gu": { "type": "navigate.parent" }, "gU": { "type": "navigate.root" }, "gi": { "type": "focus.input" }, + "gf": { "type": "page.source" }, "y": { "type": "urls.yank" }, "p": { "type": "urls.paste", "newTab": false }, "P": { "type": "urls.paste", "newTab": true }, diff --git a/src/shared/settings/properties.js b/src/shared/settings/properties.js index 37dc881..4bda8d6 100644 --- a/src/shared/settings/properties.js +++ b/src/shared/settings/properties.js @@ -5,12 +5,14 @@ const types = { hintchars: 'string', smoothscroll: 'boolean', + adjacenttab: 'boolean', }; // describe default values of a property const defaults = { hintchars: 'abcdefghijklmnopqrstuvwxyz', smoothscroll: false, + adjacenttab: true, }; export { types, defaults }; diff --git a/src/shared/versions/index.js b/src/shared/versions/index.js new file mode 100644 index 0000000..ee9f3b5 --- /dev/null +++ b/src/shared/versions/index.js @@ -0,0 +1,39 @@ +import * as storage from './storage'; +import * as releaseNotes from './release-notes'; +import manifest from '../../../manifest.json'; + +const NOTIFICATION_ID = 'vimvixen-update'; + +const notificationClickListener = (id) => { + if (id !== NOTIFICATION_ID) { + return; + } + + browser.tabs.create({ url: releaseNotes.url(manifest.version) }); + browser.notifications.onClicked.removeListener(notificationClickListener); +}; + +const checkUpdated = () => { + return storage.load().then((prev) => { + if (!prev) { + return true; + } + return manifest.version !== prev; + }); +}; + +const notify = () => { + browser.notifications.onClicked.addListener(notificationClickListener); + return browser.notifications.create(NOTIFICATION_ID, { + 'type': 'basic', + 'iconUrl': browser.extension.getURL('resources/icon_48x48.png'), + 'title': 'Vim Vixen ' + manifest.version + ' has been installed', + 'message': 'Click here to see release notes', + }); +}; + +const commit = () => { + storage.save(manifest.version); +}; + +export { checkUpdated, notify, commit }; diff --git a/src/shared/versions/release-notes.js b/src/shared/versions/release-notes.js new file mode 100644 index 0000000..6ef2335 --- /dev/null +++ b/src/shared/versions/release-notes.js @@ -0,0 +1,8 @@ +const url = (version) => { + if (version) { + return 'https://github.com/ueokande/vim-vixen/releases/tag/' + version; + } + return 'https://github.com/ueokande/vim-vixen/releases/'; +}; + +export { url }; diff --git a/src/shared/versions/storage.js b/src/shared/versions/storage.js new file mode 100644 index 0000000..37603c8 --- /dev/null +++ b/src/shared/versions/storage.js @@ -0,0 +1,11 @@ +const load = () => { + return browser.storage.local.get('version').then(({ version }) => { + return version; + }); +}; + +const save = (version) => { + return browser.storage.local.set({ version }); +}; + +export { load, save }; |