Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add thumbnail to dropzone when pasting images in to comments #20147

Closed
wants to merge 10 commits into from

Conversation

tyroneyeh
Copy link
Contributor

@tyroneyeh tyroneyeh commented Jun 27, 2022

When pasting images into comment with an attached dropzone, add a thumbnail into the dropzone area.

Closes #20130

@codecov-commenter
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (main@97bfabc). Click here to learn what that means.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main   #20147   +/-   ##
=======================================
  Coverage        ?   46.93%           
=======================================
  Files           ?      973           
  Lines           ?   134788           
  Branches        ?        0           
=======================================
  Hits            ?    63265           
  Misses          ?    63772           
  Partials        ?     7751           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 97bfabc...1466001. Read the comment docs.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jun 27, 2022
@Gusted Gusted added this to the 1.18.0 milestone Jun 27, 2022
@zeripath
Copy link
Contributor

zeripath commented Jun 28, 2022

Closes #20130

Doesn't describe what this PR is doing and what it is fixing.

Please update your description to make this clearer.


I've done this for you.

@zeripath zeripath changed the title 20130 add paste image legend Add thumbnail to dropzone when pasting images in to comments Jun 28, 2022
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jun 28, 2022
@tyroneyeh
Copy link
Contributor Author

Closes #20130

Doesn't describe what this PR is doing and what it is fixing.

Please update your description to make this clearer.

I've done this for you.

Thank you very much

Copy link
Contributor

@wxiaoguang wxiaoguang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will take a look at this later (and make some changes). For exmplae:

this.element.parentElement.parentElement.querySelector('textarea')._data_easyMDE;, is not ideal to access the internal member, there was a helper function (getAttachedEasyMDE).

And the duplicate code like dropzone.dropzone.emit could be removed after #19776 .

And there are two different editors, one is EasyMDE, one is textarea, I do not think editor.value(editor.value().replace(oldval, '')); is suitable for both of them (maybe it's suitable, I will confirm later ... 😊)

@wxiaoguang
Copy link
Contributor

I made some changes:

  • Bug fix:
    • the removal doesn't work for simple textarea
    • the removal seems not working for edit on existing comment
  • Refactaor
    • add files to dropzone in uploadFile, only one copy of the code
    • introduce general removeUploadedFileFromEditor
  • Improvment
    • use regexp to remove texts in editor. eg: user may upload with filename "unamed" and get ![unamed](...), then they may change the text to ![MyDocName](...), the new logic can remove such changed text correctly.
  • TODO
    • the logic in initGlobalDropzone is still fragile
    • the fileUuidDict is very suspicious

Although there are still TODOs, I have left comments there. I think this PR has done what it should do.

@wxiaoguang
Copy link
Contributor

Hmm ... still some tricky bugs. I think I have fixed most of them and tested these pages: comment (new/edit), pull-request (new/edit/approve), release edit.

Almost done from my side. If no objection, I could vote a L-G-T-M after several days.

@tyroneyeh
Copy link
Contributor Author

Hmm ... still some tricky bugs. I think I have fixed most of them and tested these pages: comment (new/edit), pull-request (new/edit/approve), release edit.

Almost done from my side. If no objection, I could vote a L-G-T-M after several days.

dz.emit('reload');

Maybe this is the event that triggers the removal of the file. If the pages are all refreshed, is this reload required?

@wxiaoguang
Copy link
Contributor

Some reload events are for AJAX comment edit. For example, you click the Edit in the menu for an existing comment, cancel, and edit it again.

Some trivial logics here are still not 100% correct, but they were there and could be considered as out scope of this PR, so I think this PR is enough at the moment. Feel free to do more tests to see whether everything works.

FYI, the editor related pages are (IIRC):

  • New Issue / View Issue: new comment, edit comment
  • New PR / View PR: new comment, edit comment, approve/reject PR
  • Release: New / Edit

(and every EasyMDE editor has simple textarea mode)

@tyroneyeh
Copy link
Contributor Author

I tried to change it to use the dropzone upload method directly, and at the same time add a drag and drop event in the input window, and attach the demo video and patch

Screen.Recording.2022-06-29.at.23.13.18.mov

ImproveImagePaste.patch.zip

@tyroneyeh
Copy link
Contributor Author

Hi @wxiaoguang any suggestions?

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Jul 5, 2022

I haven't got time to test your new patch. Since the insert code changes again, have you tested it with simple textarea mode?


Update: maybe you can propose a new PR (to replace this one) for supporting dragdrop uploading and use it to replace legacy pasting uploading.

@tyroneyeh
Copy link
Contributor Author

The simple text area mode can be uploaded normally, but the link of the attachment is not pasted to text area, I am researching this problem, thank you

@tyroneyeh
Copy link
Contributor Author

So don't want this PR anymore? close it?

@tyroneyeh
Copy link
Contributor Author

I created a new PR #20263, so close this
Thanks

@tyroneyeh tyroneyeh closed this Jul 6, 2022
@tyroneyeh tyroneyeh deleted the 20130_add_paste_image_legend branch July 17, 2022 14:45
@wxiaoguang
Copy link
Contributor

Maybe we can take this one first, IIRC I might have fixed the bug in this PR:

The new PR (#20263 (comment)) is much more complex and I'm afraid it will be too difficult to maintain in the future, and I haven't got time to test or optimize it.

@lunny lunny removed this from the 1.18.0 milestone Dec 20, 2022
silverwind added a commit that referenced this pull request Apr 20, 2023
Close #24195

Some of the changes are taken from my another fix
f07b0de
in #20147 (although that PR was discarded ....)


The bug is:

1. The old code doesn't handle `removedfile` event correctly
2. The old code doesn't provide attachments for type=CommentTypeReview


This PR doesn't intend to refactor the "upload" code to a perfect state
(to avoid making the review difficult), so some legacy styles are kept.

---------

Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: Giteabot <teabot@gitea.io>
@go-gitea go-gitea locked and limited conversation to collaborators May 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/need 1 This PR needs approval from one additional maintainer to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Copy and paste the images has list legend
7 participants