FIX: Context menu not appearing in Firefox (#154)

This commit is contained in:
Keegan George 2023-08-23 14:20:31 -07:00 committed by GitHub
parent 7d943be7b2
commit 3cf316fb62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 4 deletions

View File

@ -85,12 +85,25 @@ export default class AiHelperContextMenu extends Component {
}
@bind
selectionChanged(event) {
if (!event.target.activeElement.classList.contains("d-editor-input")) {
selectionChanged() {
if (document.activeElement !== this._dEditorInput) {
return;
}
if (window.getSelection().toString().length === 0) {
const canSelect = Boolean(
window.getSelection() &&
document.activeElement &&
document.activeElement.value
);
this.selectedText = canSelect
? document.activeElement.value.substring(
document.activeElement.selectionStart,
document.activeElement.selectionEnd
)
: "";
if (this.selectedText.length === 0) {
if (this.loading) {
// prevent accidentally closing context menu while results loading
return;
@ -100,7 +113,6 @@ export default class AiHelperContextMenu extends Component {
return;
}
this.selectedText = event.target.getSelection().toString();
this._onSelectionChanged();
}