Skip to content

Commit

Permalink
paste from clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
gherkins committed Feb 25, 2024
1 parent 11505d9 commit 144d291
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ courtesy of https://github.com/rewtnull/amigafonts/ 🖤
<kbd>V</kbd>: paste buffer to cursor position
<kbd>ESC</kbd>: clear selected block

<kbd>Z</kbd>: undo last action
<kbd>CMD + C</kbd>: copy everything to clipboard
<kbd>Z</kbd>: undo last action

<kbd>CMD + C</kbd>: copy everything to clipboard (export)
<kbd>CMD + V</kbd>: paste everything from clipboard (import)


## CHANGE CHARSET (optional):

Expand Down
25 changes: 25 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,25 @@ function App () {
navigator.clipboard.writeText(text)
}

const pasteAllFromClipboard = async () => {
try {
const text = await navigator.clipboard.readText()
const newContents = text.split('\n').map(row => row.split(''))
for (let row = 0; row < rows; row++) {
for (let col = 0; col < cols; col++) {
if (newContents[row] && newContents[row][col]) {
contents[row][col] = newContents[row][col]
} else {
contents[row][col] = ' '
}
}
}
updateState({})
} catch (e) {
console.error(e)
}
}

const handleCursorMovement = async key => {
switch (key) {
case 'ArrowUp':
Expand Down Expand Up @@ -307,6 +326,12 @@ function App () {
copyAllToClipboard()
})

Mousetrap.bind('command+v', e => {
e.preventDefault()
pasteAllFromClipboard()
updateState({})
})

Mousetrap.bind('c', e => {
e.preventDefault()
copySelectionToBuffer()
Expand Down

0 comments on commit 144d291

Please sign in to comment.