From 144d2912c7b2eb8dc11c850569ffe9498095cd58 Mon Sep 17 00:00:00 2001 From: Max Girkens Date: Sun, 25 Feb 2024 13:12:38 +0100 Subject: [PATCH] paste from clipboard --- README.md | 7 +++++-- src/App.js | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 64c01ec..a5308cc 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,11 @@ courtesy of https://github.com/rewtnull/amigafonts/ 🖤 V: paste buffer to cursor position ESC: clear selected block -Z: undo last action -CMD + C: copy everything to clipboard +Z: undo last action + +CMD + C: copy everything to clipboard (export) +CMD + V: paste everything from clipboard (import) + ## CHANGE CHARSET (optional): diff --git a/src/App.js b/src/App.js index 82a9f50..88c3a58 100644 --- a/src/App.js +++ b/src/App.js @@ -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': @@ -307,6 +326,12 @@ function App () { copyAllToClipboard() }) + Mousetrap.bind('command+v', e => { + e.preventDefault() + pasteAllFromClipboard() + updateState({}) + }) + Mousetrap.bind('c', e => { e.preventDefault() copySelectionToBuffer()