Skip to content

Commit

Permalink
feat: Add c t and c , to copy tabs information in different ways
Browse files Browse the repository at this point in the history
  • Loading branch information
xcv58 committed Apr 14, 2020
1 parent 266204f commit 0d8e9ff
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
24 changes: 22 additions & 2 deletions src/js/stores/ShortcutStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,29 @@ export default class ShortcutStore {
'c c',
(event) => {
preventDefault(event)
this.store.copyURL()
this.store.copyTabsInfo()
},
'Copy URL (separated by new line)'
'Copy selected/focused tabs URL (separated by new line)'
],
[
'c t',
(event) => {
preventDefault(event)
this.store.copyTabsInfo({
includeTitle: true
})
},
'Copy selected/focused tabs title & URL'
],
[
'c ,',
(event) => {
preventDefault(event)
this.store.copyTabsInfo({
delimiter: ', '
})
},
'Copy selected/focused tabs URL (separated by comma `,`)'
]
]

Expand Down
11 changes: 9 additions & 2 deletions src/js/stores/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,19 @@ export default class Store {
}

@action
copyURL = async () => {
copyTabsInfo = async ({ includeTitle = false, delimiter = '\n' } = {}) => {
const tabs = this._getFocusedOrSelectedTab()
if (!tabs || !tabs.length) {
return
}
const text = tabs.map((x) => x.url).join('\n')
const text = tabs
.map((x) => {
if (includeTitle) {
return `${x.title}\n${x.url}\n`
}
return x.url
})
.join(delimiter)
await writeToClipboard(text)
this.tabStore.unselectAll()
}
Expand Down

0 comments on commit 0d8e9ff

Please sign in to comment.