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

[IMP] Clipboard: support images in the clipboard #5098

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

rrahir
Copy link
Collaborator

@rrahir rrahir commented Oct 15, 2024

Description:

This commit adds the support of images in the clipboard. Namely,

  • Pasting an image from the OS clipboard will automatically upload it to
    the filestore and dispatch a CREATE_IMAGE accordingly.
  • Copying a chart or an image from the spreadsheet will add it to the
    oOS clipboard. It can then be pasted somewhere else, like a discuss
    app, a text editor maybe?.

TODO

  • support multi type of images (not just png) It technically works
    because we never check agains the actual type of the file we upload
    but it's wrong. Maybe use a generic image/* mimetype instead of using
    png. We still need to purge out dangerous mimetypes like image/svg(+xml)
  • Currently uploads the image from the clipboard THEN only checks if the
    we are copy pasting from the same spreadsheet clipboard (potential
    useless upload)
  • Not supported by some apps like Office 365 online (word & powerpoint tested). Supposedly because our
    clipboard has some text/* types along the image/* so it ignores the
    later. for a fully integrated feature, we should probably decorrelate it
    from the standard copy paste and make a menu "copy image to os
    clipboard" ? tbd
  • works on discord at least
  • No test whatsoever
    Task: 4235104

review checklist

  • feature is organized in plugin, or UI components
  • support of duplicate sheet (deep copy)
  • in model/core: ranges are Range object, and can be adapted (adaptRanges)
  • in model/UI: ranges are strings (to show the user)
  • undo-able commands (uses this.history.update)
  • multiuser-able commands (has inverse commands and transformations where needed)
  • new/updated/removed commands are documented
  • exportable in excel
  • translations (_t("qmsdf %s", abc))
  • unit tested
  • clean commented code
  • track breaking changes
  • doc is rebuild (npm run doc)
  • status is correct in Odoo

@robodoo
Copy link
Collaborator

robodoo commented Oct 15, 2024

Pull request status dashboard

@rrahir rrahir changed the title Master handle images in clipboard rar [FIX] clipboard: Fix clipboard cross-browser coverage Oct 15, 2024
@rrahir rrahir changed the title [FIX] clipboard: Fix clipboard cross-browser coverage [IMP] Clipboard: support images in the clipboard Oct 15, 2024
@rrahir rrahir force-pushed the master-handle-images-in-clipboard-rar branch 11 times, most recently from 9695adc to ad869b0 Compare November 26, 2024 09:15
@rrahir rrahir force-pushed the master-handle-images-in-clipboard-rar branch 5 times, most recently from 13e3841 to 405eb7c Compare November 27, 2024 14:59
Copy link
Contributor

@hokolomopo hokolomopo left a comment

Choose a reason for hiding this comment

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

boup boup

src/actions/menu_items_actions.ts Outdated Show resolved Hide resolved
src/actions/menu_items_actions.ts Outdated Show resolved Hide resolved
src/helpers/clipboard/clipboard_helpers.ts Outdated Show resolved Hide resolved
src/plugins/ui_stateful/clipboard.ts Show resolved Hide resolved
src/plugins/ui_stateful/clipboard.ts Outdated Show resolved Hide resolved
src/plugins/ui_stateful/clipboard.ts Outdated Show resolved Hide resolved
src/registries/figure_registry.ts Outdated Show resolved Hide resolved
@rrahir rrahir force-pushed the master-handle-images-in-clipboard-rar branch from 405eb7c to 4a8361d Compare December 5, 2024 11:16
Copy link
Collaborator

@LucasLefevre LucasLefevre left a comment

Choose a reason for hiding this comment

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

I'm submitting my pending un-finished review now because apparently, I'm off this afternoon and I didn't know.

I must admit I was originally skeptical on the usefulness/cost ratio of this feature. But having tried it, I now find it really cool 😊

src/components/helpers/dom_helpers.ts Outdated Show resolved Hide resolved
src/components/helpers/dom_helpers.ts Outdated Show resolved Hide resolved
const file = await this.getImageFromUser();
const file = await this.userImageUpload();
if (file.size > MAX_FILE_SIZE) {
throw new ImageImportError(_t("The file you are trying to upload is too large (> 5 mB)"));
Copy link
Collaborator

Choose a reason for hiding this comment

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

To be honest, IMO this kind of limitation is the worst possible user experience. Whenever I'm faced with this I rage-quit half of the time, rather than finding a shitty tool to reduce the image size.
I prefer if it works but it's slow rather than not working at all.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yup, it might not be useful at upload. The filestore implementation might reject files too big but it can be taken care of at that moment.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

=> removed the upload limitation

src/plugins/ui_stateful/clipboard.ts Outdated Show resolved Hide resolved
src/plugins/ui_stateful/clipboard.ts Outdated Show resolved Hide resolved
src/registries/figure_registry.ts Outdated Show resolved Hide resolved
src/actions/menu_items_actions.ts Outdated Show resolved Hide resolved
src/actions/menu_items_actions.ts Outdated Show resolved Hide resolved
src/plugins/ui_stateful/clipboard.ts Outdated Show resolved Hide resolved
src/plugins/ui_stateful/clipboard.ts Outdated Show resolved Hide resolved
src/helpers/clipboard/clipboard_helpers.ts Outdated Show resolved Hide resolved
Comment on lines 94 to 192
image.src = imageUrl;
image.addEventListener("load", () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

probably doesn't matter in practice, but should the event listener be attached before setting src ? If somehow image.src = imageUrl; is instant and synchronous, the event handler would never be called

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I just couldn't make it work without that, i might have missed something...

src/components/helpers/dom_helpers.ts Outdated Show resolved Hide resolved
src/registries/figure_registry.ts Show resolved Hide resolved
src/components/icons/icons.xml Outdated Show resolved Hide resolved
src/components/icons/icons.xml Show resolved Hide resolved
@rrahir rrahir force-pushed the master-handle-images-in-clipboard-rar branch 3 times, most recently from f3e07a4 to 22ca025 Compare January 9, 2025 17:57
@rrahir rrahir force-pushed the master-handle-images-in-clipboard-rar branch 4 times, most recently from d53c87b to 2c70940 Compare January 29, 2025 09:01
This commit adds the support of images in the clipboard.
This allows the user to insert images from their OS faster than going
through the "insert" menu and also to extract charts/images from the
spreadsheet to use it in other applications (word, powerpoint, discuss
apps, ...).

Features:
- Png images will be pasted to the clipboard instantly on "copy"
- Charts can be added to the clipboard via a menu button "copy as image"
- Pasting an image from the OS will add it to the spreadsheet as an
  image and place it in the current sheet.
- Both images and charts can be downloaded as images by the user via the
  figure menu

Limitations:
- Charts will not be added to the clipboard directly as it can mislead
  users when using cross-sheet copy/paste. Namely, it would add the
  chart as an image on paste and not as a chart.
- non-png images need to be converted as png to be added in the
  clipboard and this operation can be quite slow. We add a limit of 5mb
  image. Past that point, the image is not copied to the clipboard in
  order to avoid slowing down the user experience.

Task: 4235104
@rrahir rrahir force-pushed the master-handle-images-in-clipboard-rar branch 3 times, most recently from 8cd390d to b377210 Compare February 5, 2025 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants