mirror of
https://github.com/He4eT/tabswitcher.git
synced 2026-05-05 01:17:23 +00:00
pages/search: store: closeCurrentTab
This commit is contained in:
parent
dbb7724253
commit
c6f4fda801
4 changed files with 12 additions and 13 deletions
|
|
@ -31,8 +31,8 @@ function openHelp () {
|
||||||
location.href = helpLink
|
location.href = helpLink
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeCurrentTab () {
|
function closeCurrentTab (store) {
|
||||||
window.close()
|
store.actions.closeCurrentTab()
|
||||||
}
|
}
|
||||||
|
|
||||||
function reloadCurrentTab () {
|
function reloadCurrentTab () {
|
||||||
|
|
@ -46,11 +46,12 @@ const getTabByLabel = (store, label) => {
|
||||||
return tabs.find(tab => tab.label === label)
|
return tabs.find(tab => tab.label === label)
|
||||||
}
|
}
|
||||||
|
|
||||||
function switchToTab (store, label) {
|
function switchToTab (store, label, flush) {
|
||||||
const tab = getTabByLabel(store, label)
|
const tab = getTabByLabel(store, label)
|
||||||
if (tab) {
|
if (tab) {
|
||||||
|
flush()
|
||||||
store.actions.goToTab(tab.id)
|
store.actions.goToTab(tab.id)
|
||||||
closeCurrentTab()
|
store.actions.closeCurrentTab()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,12 +38,6 @@ export const attachInputHandlers = (store) => {
|
||||||
const actionbox = document.getElementById('actionbox')
|
const actionbox = document.getElementById('actionbox')
|
||||||
actionbox.value = ''
|
actionbox.value = ''
|
||||||
|
|
||||||
/* Switch to tab */
|
|
||||||
const switchToTab = (tabId) => {
|
|
||||||
store.actions.goToTab(parseInt(tabId))
|
|
||||||
window.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Arrow keys */
|
/* Arrow keys */
|
||||||
document.addEventListener('keydown', (e) => {
|
document.addEventListener('keydown', (e) => {
|
||||||
focusButtonsWithArrows(e, () => {
|
focusButtonsWithArrows(e, () => {
|
||||||
|
|
@ -58,8 +52,8 @@ export const attachInputHandlers = (store) => {
|
||||||
/* Buttons */
|
/* Buttons */
|
||||||
document.addEventListener('click', (event) => {
|
document.addEventListener('click', (event) => {
|
||||||
if (event.target.classList.contains('tab')) {
|
if (event.target.classList.contains('tab')) {
|
||||||
const tabId = event.target.dataset.id
|
const tabId = parseInt(event.target.dataset.id)
|
||||||
switchToTab(tabId)
|
store.actions.goToTab(tabId)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -82,7 +76,7 @@ export const attachInputHandlers = (store) => {
|
||||||
let visibleTabs = store.getCurrentState().results
|
let visibleTabs = store.getCurrentState().results
|
||||||
if (visibleTabs.length > 0) {
|
if (visibleTabs.length > 0) {
|
||||||
const tabId = visibleTabs[0].obj.id
|
const tabId = visibleTabs[0].obj.id
|
||||||
switchToTab(tabId)
|
store.actions.goToTab(tabId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ const fuzzysort = window.fuzzysort
|
||||||
export const init = ({
|
export const init = ({
|
||||||
tabs: browserTabs,
|
tabs: browserTabs,
|
||||||
onStateUpdate,
|
onStateUpdate,
|
||||||
|
closeCurrentTab,
|
||||||
}) => {
|
}) => {
|
||||||
/* Initial state */
|
/* Initial state */
|
||||||
const state = {
|
const state = {
|
||||||
|
|
@ -66,7 +67,9 @@ export const init = ({
|
||||||
goToTab(id) {
|
goToTab(id) {
|
||||||
browserTabs.update(id, { active: true })
|
browserTabs.update(id, { active: true })
|
||||||
.then(updateState)
|
.then(updateState)
|
||||||
|
.then(closeCurrentTab)
|
||||||
},
|
},
|
||||||
|
closeCurrentTab,
|
||||||
closeTab(id) {
|
closeTab(id) {
|
||||||
browserTabs.remove(id)
|
browserTabs.remove(id)
|
||||||
.then(updateState)
|
.then(updateState)
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import * as inputHandlers from './modules/inputHandlers.js'
|
||||||
const store = Store.init({
|
const store = Store.init({
|
||||||
tabs: browser.tabs,
|
tabs: browser.tabs,
|
||||||
onStateUpdate: dom.updateSearchResults,
|
onStateUpdate: dom.updateSearchResults,
|
||||||
|
closeCurrentTab: () => window.close(),
|
||||||
})
|
})
|
||||||
|
|
||||||
void inputHandlers.attachInputHandlers(store)
|
void inputHandlers.attachInputHandlers(store)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue