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 option to automatically copy to clipboard #348

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

heyimjonas
Copy link
Contributor

@heyimjonas heyimjonas commented Jan 29, 2025

Add option to automatically copy generated content to clipboard

This pull request introduces a new feature to automatically copy clipped content to the clipboard and includes several changes to integrate this feature across the codebase. The most important changes include adding the autoCopyToClipboard setting, updating the settings management functions, and modifying the relevant UI components.

New Feature: Auto Copy to Clipboard

  • src/background.ts: Added a new command listener for copy_to_clipboard to send a message to the content script.
  • src/core/popup.ts: Integrated the auto-copy feature into the handleClip function to copy content to the clipboard if the setting is enabled.
  • src/managers/general-settings.ts: Added the initialization and saving logic for the new autoCopyToClipboard setting. [1] [2] [3] [4]
  • src/settings.html: Updated the settings UI to include a toggle for the autoCopyToClipboard feature.
  • src/types/types.ts: Updated the Settings interface to include the autoCopyToClipboard property.

Settings Management

Clipboard Integration

Add option to automatically copy generated content to clipboard

* Add a new setting in `src/core/popup.ts` to enable automatic copying to the clipboard
* Implement the automatic copy to clipboard functionality in `src/core/popup.ts`
* Update the `handleClip` function in `src/core/popup.ts` to check the new setting
* Add a new keyboard hotkey for copying to the clipboard in `src/background.ts`
* Implement the functionality to handle the new hotkey in `src/background.ts`
* Add a new setting in the popup interface in `src/popup.html` to enable automatic copying to the clipboard
* Add a new property to the `Settings` interface in `src/types/types.ts` for the automatic copy to clipboard setting
@heyimjonas heyimjonas closed this Jan 29, 2025
@heyimjonas heyimjonas reopened this Jan 29, 2025
@heyimjonas
Copy link
Contributor Author

this pr addresses #327

Copy link
Collaborator

@kepano kepano left a comment

Choose a reason for hiding this comment

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

Thanks. Testing this out, the UX doesn't match what I expected it to do based on the description.

The setting toggle is named Auto-copy to clipboard which made me think that the contents would be automatically copied as soon as the extension is opened — i.e. without requiring a click on the Add to Obsidian button. And when I click the Add to Obsidian button it doesn't actually add to Obsidian, it only copies to the clipboard. The add to clipboard functionality already exists in the secondary actions for the main button, so this is confusing.

I think we need to change the behavior in one of two ways — either:

  1. The toggle should remain, but we automatically copy to clipboard when the popup is opened, and anytime there is an update to the content, e.g. via Interpreter. This still allows the "Add to Obsidian" button to function as before.

OR

  1. Change the setting toggle to a dropdown that allows users to swap the primary action with one of the secondary actions. The setting would be called something like Save behavior with a dropdown that has three options:
  • Add to Obsidian (default)
  • Copy to clipboard
  • Save file...

When the user choses to make Copy to clipboard the primary action we swap actions and put the Add to Obsidian action into the secondary menu. That way the UI copy will match the behavior.

I am guessing that option 2 is more in line with what you and the user have in mind?


Also note that when adding new settings you need to at minimum add the new strings to the messages.json in the English locale.

@heyimjonas
Copy link
Contributor Author

Thank your for your feedback, i probably should have explained more what i had in mind and thought about the whole UX !

I think your proposed option 2 with the dropdown on saving behaviour is probably the most intuitive way.

So basically we have a dropdown which determines which is the main action in the popout and then swap them with the secondary ones. It would also enable more workflows imo.

@heyimjonas heyimjonas requested a review from kepano January 30, 2025 23:14
@heyimjonas
Copy link
Contributor Author

I made the change from the 2nd proposed solution.

Basically how it is now is that you select the main function in the settings (default is add to obsidian).
The secondary actions will get swapped depending on the main action.
When you have the main function Copy or save as file it won't open obsidian nor add to obsidian.

I tested it with every action as main and secondary action, with and without interpreter (gemini), and haven't got any issues on chrome.

UI and UX should allign now.

I added the english text to messages.json and if you approve this i can generate translations for other languages utilising deepl.

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.

2 participants