Skip to content

Commit

Permalink
Merge pull request #160 from PasteBar/fix-quick-paste-window-shortcut…
Browse files Browse the repository at this point in the history
…s-numbers-is-wrong-when-using-search

Fix quick paste window shortcuts numbers is wrong when using search
  • Loading branch information
kurdin authored Sep 1, 2024
2 parents fa21247 + fb264f6 commit 44c879b
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/grumpy-mangos-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'pastebar-app-ui': patch
---

Update to shortcut for quick copy paste ctrl + number added cmd key press on mac
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ interface ClipboardHistoryQuickPasteRowProps {
index?: number
style?: CSSProperties
isExpanded: boolean
isWindows?: boolean
isWrapText: boolean
isSelected?: boolean
isDeleting?: boolean
Expand Down Expand Up @@ -125,6 +126,7 @@ export function ClipboardHistoryQuickPasteRowComponent({
isScrolling = false,
isPinnedTop = false,
isPinnedTopFirst = false,
isWindows,
isDisabledPinnedMoveUp = false,
isDisabledPinnedMoveDown = false,
isExpanded = false,
Expand Down Expand Up @@ -306,7 +308,9 @@ export function ClipboardHistoryQuickPasteRowComponent({
}, [clipboard?.isLink, hasLinkCard])

const showCopyPasteIndexNumber =
isKeyCtrlPressed.value && typeof index !== 'undefined' && index < 10
(isKeyCtrlPressed.value || (isKeyAltPressed.value && !isWindows)) &&
typeof index !== 'undefined' &&
index < 10

const pinnedTopOffsetFirst = !isPinnedTopFirst ? 'top-[-10px]' : 'top-[5px]'
const bgToolsPanel = `${
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,9 @@ export function ClipboardHistoryRowComponent({
}, [clipboard?.isLink, hasLinkCard])

const showCopyPasteIndexNumber =
isKeyCtrlPressed.value && typeof index !== 'undefined' && index < 10
(isKeyCtrlPressed.value || (isKeyAltPressed.value && !isWindows)) &&
typeof index !== 'undefined' &&
index < 10

const pinnedTopOffsetFirst = !isPinnedTopFirst ? 'top-[-10px]' : 'top-[5px]'
const bgToolsPanel = `${
Expand Down
27 changes: 27 additions & 0 deletions packages/pastebar-app-ui/src/pages/main/ClipboardHistoryPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ export default function ClipboardHistoryPage() {
useHotkeys(
[...Array(10).keys()].map(i => `ctrl+${i.toString()}`),
e => {
e.preventDefault()
const index = e.key === '0' ? 9 : Number(e.key) - 1
const itemId = clipboardHistory[Number(index)]?.historyId

Expand All @@ -325,12 +326,35 @@ export default function ClipboardHistoryPage() {
}

setCopiedItem(itemId)
},
{
enableOnFormTags: ['input'],
}
)

useHotkeys(
[...Array(10).keys()].map(i => `meta+${i.toString()}`),
e => {
e.preventDefault()
const index = e.key === '0' ? 9 : Number(e.key) - 1
const itemId = clipboardHistory[Number(index)]?.historyId

if (!itemId) {
return
}

setCopiedItem(itemId)
},
{
enabled: !isWindows,
enableOnFormTags: ['input'],
}
)

useHotkeys(
[...Array(10).keys()].map(i => `ctrl+${isWindows ? 'alt' : 'meta'}+${i.toString()}`),
e => {
e.preventDefault()
const index = e.key === '0' ? 9 : Number(e.key) - 1
const itemId = clipboardHistory[Number(index)]?.historyId

Expand All @@ -339,6 +363,9 @@ export default function ClipboardHistoryPage() {
}

setPastedItem(itemId)
},
{
enableOnFormTags: ['input'],
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,28 @@ export default function ClipboardHistoryQuickPastePage() {
}

invokeCopyPasteHistoryItem(itemId)
},
{
enableOnFormTags: ['input'],
}
)

useHotkeys(
[...Array(10).keys()].map(i => `meta+${i.toString()}`),
e => {
e.preventDefault()
const index = e.key === '0' ? 9 : Number(e.key) - 1
const itemId = clipboardHistory[Number(index)]?.historyId

if (!itemId) {
return
}

invokeCopyPasteHistoryItem(itemId)
},
{
enabled: !isWindows,
enableOnFormTags: ['input'],
}
)

Expand Down Expand Up @@ -682,6 +704,7 @@ export default function ClipboardHistoryQuickPastePage() {
setSavingItem={setSavingItem}
isDeleting={false}
isSelected={false}
isWindows={isWindows}
setBrokenImageItem={setBrokenImageItem}
isBrokenImage={brokenImageItems.includes(historyId)}
showTimeAgo={false}
Expand Down Expand Up @@ -855,6 +878,7 @@ export default function ClipboardHistoryQuickPastePage() {
hasGenerateLinkMetaDataInProgress={clipboardHistoryGenerateLinkMetaDataInProgress.includes(
historyId
)}
isWindows={isWindows}
setHistoryFilters={setHistoryFilters}
setAppFilters={setAppFilters}
setSelectHistoryItem={() => {}}
Expand Down

0 comments on commit 44c879b

Please sign in to comment.