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 @bind
selectionChanged(event) { selectionChanged() {
if (!event.target.activeElement.classList.contains("d-editor-input")) { if (document.activeElement !== this._dEditorInput) {
return; 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) { if (this.loading) {
// prevent accidentally closing context menu while results loading // prevent accidentally closing context menu while results loading
return; return;
@ -100,7 +113,6 @@ export default class AiHelperContextMenu extends Component {
return; return;
} }
this.selectedText = event.target.getSelection().toString();
this._onSelectionChanged(); this._onSelectionChanged();
} }