Merge pull request #95 from jamesjulich/paste-image
Support pasting images as attachments. Fixes #87.
This commit is contained in:
commit
470fdd62bb
1 changed files with 27 additions and 0 deletions
|
@ -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) {
|
function addEmoji(emoji) {
|
||||||
textAreaRef.current.value += emoji.unicode;
|
textAreaRef.current.value += emoji.unicode;
|
||||||
}
|
}
|
||||||
|
@ -315,6 +341,7 @@ function RoomViewInput({
|
||||||
<TextareaAutosize
|
<TextareaAutosize
|
||||||
ref={textAreaRef}
|
ref={textAreaRef}
|
||||||
onChange={handleMsgTyping}
|
onChange={handleMsgTyping}
|
||||||
|
onPaste={handlePaste}
|
||||||
onResize={() => timelineScroll.autoReachBottom()}
|
onResize={() => timelineScroll.autoReachBottom()}
|
||||||
onKeyDown={handleKeyDown}
|
onKeyDown={handleKeyDown}
|
||||||
placeholder="Send a message..."
|
placeholder="Send a message..."
|
||||||
|
|
Loading…
Reference in a new issue