Fevol / obsidian-translate

Translate text and entire notes in Obsidian
MIT License
103 stars 6 forks source link

[feat] select everyting on ctrl-A #21

Closed kometenstaub closed 2 years ago

kometenstaub commented 2 years ago

I would appreciate if I could select all text with Ctrl-A. The reason for this is that I often copy text into it and would like to use that hotkey for selecting all the text that's already inside it.

So that I can Ctrl-A, Ctrl-V for inserting the new text.

Fevol commented 2 years ago

I was not able to reproduce this; is the issue that Ctrl-A does not register at all in the Translation View? If so, I'm not sure what could be going wrong: I'm using standard textarea elements, the only thing that I've changed is that the target language field is read-only

ctrla

kometenstaub commented 2 years ago

This may be user error on my side. I‘ll try it again tomorrow and report back.

kometenstaub commented 2 years ago

It doesn't work for me because I had a hotkey set to it (editorCallback for inserting an admonition). It somehow still steals the event, even when the sidebar pane is focused.

I just removed the hotkey so that it works again. I'm wondering whether this is an Obsidian issue, because the command doesn't show up when the sidebar pane is focused and the hotkey does nothing, but it still isn't let through.

Fevol commented 2 years ago

So I found a potential fix for the problem: overriding the hotkey in the view scope, though this feels like a horrendous bodge. I'll look around if I can find a better solution. https://github.com/Fevol/obsidian-translate/blob/510fc860f41d2bea1a0e58f2d275e4a8c4145ca1/src/ui/translator-components/ViewPage.svelte#L32-L35

Potential fix:

view_scope.register(['Mod'], 'A', (e) => {});

Issues:

kometenstaub commented 2 years ago

Yes, I wouldn't do that. I raised an issue with Obsidian, let's see what happens.

kometenstaub commented 2 years ago

This behaviour is intentional. The hotkeys are global, editorCallbacks just don't get executed because there's no editor.