Selecting some text within a text field and trying to translate it using keyboard shortcuts restults in an empty translation. The issue lies in Firefox bug (https://bugzilla.mozilla.org/show_bug.cgi?id=1527627) where getSelection() returns no text if inside a textbox.
Right-clicking it and sending it to DeepL from context menu works, however, because different code is used.
Repro steps
Open a webpage with a text input
Write some text
Select text
Press your defined keyboard shortcut to send to DeepL
Expected result
Selected text should be translated
Actual result
No text is translated
Fix
In the mentioned FF bug, the following workaround is suggested: document.activeElement?.value?.substring(document.activeElement.selectionStart,document.activeElement.selectionEnd)
Although it works fine for single selection, it only returns the last selection if you select multiple parts of the text (while holding down Ctrl key). Nevertheless, I think this is still acceptable for most cases.
Selecting some text within a text field and trying to translate it using keyboard shortcuts restults in an empty translation. The issue lies in Firefox bug (https://bugzilla.mozilla.org/show_bug.cgi?id=1527627) where
getSelection()
returns no text if inside a textbox.Right-clicking it and sending it to DeepL from context menu works, however, because different code is used.
Repro steps
Expected result
Selected text should be translated
Actual result
No text is translated
Fix
In the mentioned FF bug, the following workaround is suggested:
document.activeElement?.value?.substring(document.activeElement.selectionStart,document.activeElement.selectionEnd)
Although it works fine for single selection, it only returns the last selection if you select multiple parts of the text (while holding downCtrl
key). Nevertheless, I think this is still acceptable for most cases.I'll sumbit a PR soon.