Allow drag&drop of link to quote in compose form (#36859)
This commit is contained in:
1 parent
c5eca8ffb2
commit
4ab1d5d724
3 files changed
+34
-14
No files matched your search
@@ -18,6 +18,24 @@ import ComposeForm from '../components/compose_form';
|
||||
|
||||
const urlLikeRegex = /^https?:\/\/[^\s]+\/[^\s]+$/i;
|
||||
|
||||
const processPasteOrDrop = (transfer, e, dispatch) => {
|
||||
if (transfer && transfer.files.length === 1) {
|
||||
dispatch(uploadCompose(transfer.files));
|
||||
e.preventDefault();
|
||||
} else if (transfer && transfer.files.length === 0) {
|
||||
const data = transfer.getData('text/plain');
|
||||
if (!data.match(urlLikeRegex)) return;
|
||||
|
||||
try {
|
||||
const url = new URL(data);
|
||||
dispatch(pasteLinkCompose({ url }));
|
||||
e.preventDefault();
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const mapStateToProps = state => ({
|
||||
text: state.getIn(['compose', 'text']),
|
||||
suggestions: state.getIn(['compose', 'suggestions']),
|
||||
@@ -85,20 +103,11 @@ const mapDispatchToProps = (dispatch, props) => ({
|
||||
},
|
||||
|
||||
onPaste (e) {
|
||||
if (e.clipboardData && e.clipboardData.files.length === 1) {
|
||||
dispatch(uploadCompose(e.clipboardData.files));
|
||||
e.preventDefault();
|
||||
} else if (e.clipboardData && e.clipboardData.files.length === 0) {
|
||||
const data = e.clipboardData.getData('text/plain');
|
||||
if (!data.match(urlLikeRegex)) return;
|
||||
processPasteOrDrop(e.clipboardData, e, dispatch);
|
||||
},
|
||||
|
||||
try {
|
||||
const url = new URL(data);
|
||||
dispatch(pasteLinkCompose({ url }));
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
}
|
||||
onDrop (e) {
|
||||
processPasteOrDrop(e.dataTransfer, e, dispatch);
|
||||
},
|
||||
|
||||
onPickEmoji (position, data, needsSpace) {
|
||||
|
||||
Reference in new issue
Block a user