Skip to content

Commit

Permalink
Merge pull request #95 from jamesjulich/paste-image
Browse files Browse the repository at this point in the history
Support pasting images as attachments. Fixes #87.
  • Loading branch information
ajbura authored Sep 14, 2021
2 parents 2ed4fc9 + 6434d10 commit 470fdd6
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/app/organisms/room/RoomViewInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,32 @@ function RoomViewInput({
}
}

function handlePaste(e) {
if (e.clipboardData === false) {
return;
}

if (e.clipboardData.items === undefined) {
return;
}

for (let i = 0; i < e.clipboardData.items.length; i += 1) {
const item = e.clipboardData.items[i];
if (item.type.indexOf('image') !== -1) {
const image = item.getAsFile();
if (attachment === null) {
setAttachment(image);
if (image !== null) {
roomsInput.setAttachment(roomId, image);
return;
}
} else {
return;
}
}
}
}

function addEmoji(emoji) {
textAreaRef.current.value += emoji.unicode;
}
Expand Down Expand Up @@ -315,6 +341,7 @@ function RoomViewInput({
<TextareaAutosize
ref={textAreaRef}
onChange={handleMsgTyping}
onPaste={handlePaste}
onResize={() => timelineScroll.autoReachBottom()}
onKeyDown={handleKeyDown}
placeholder="Send a message..."
Expand Down

0 comments on commit 470fdd6

Please sign in to comment.