kristofa / bookmarker_for_pinboard

macOS Safari App Extension that supports adding bookmarks to pinboard.in
Other
37 stars 4 forks source link

Fill in description with selected text #13

Closed kristofa closed 5 years ago

kristofa commented 5 years ago

This implements #7.

When the popup opens we get the selected text from the active page and use it to populate the description field. This is implemented by sending messages between the app extension and a script that's injected in the web page.

kristofa commented 5 years ago

What prevents me from merging this is that the selected text gets deselected once I press the 'bookmarker for pinboard' toolbar button. This means the feature doesn't work.

This doesn't happen with other extensions like for example when I press the 1Password toolbar button. But I don't know why.

The weird thing is that I got it to work when try it out after showing the Javascript console. When the Javascript console is visible and I select text in the active webpage, the text doesn't get deselected when I press the 'bookmarker for pinboard' toolbar button. In that case the selected text appears in the Description field.

We can only merge and release this once we can prevent selected text from getting deselected when pressing the toolbar button. Any help is appreciated.

kristofa commented 5 years ago

An alternative approach would be to try to store the selected text in a variable as soon as it is selected and passing the content of the variable to the extension. However that would be a workaround, not my preferred option.

apas commented 5 years ago

An alternative approach would be to try to store the selected text in a variable as soon as it is selected and passing the content of the variable to the extension. However that would be a workaround, not my preferred option.

Imo I think this is the way to go.

kristofa commented 5 years ago

@apas Yes, I implemented the workaround and got it to work. It wasn't straightforward, details in code comments (script.js) and commit message.