FIX: Revert AI action not working in Firefox (#418)

* FIX: Revert AI action not working in Firefox

* Make it pretty 💄
This commit is contained in:
Keegan George 2024-01-10 16:43:39 -08:00 committed by GitHub
parent 8fcba12fae
commit 5c9b570562
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 1 deletions

View File

@ -18,6 +18,7 @@ export default class AiHelperContextMenu extends Component {
@service currentUser; @service currentUser;
@service siteSettings; @service siteSettings;
@service modal; @service modal;
@service capabilities;
@tracked helperOptions = []; @tracked helperOptions = [];
@tracked showContextMenu = false; @tracked showContextMenu = false;
@tracked caretCoords; @tracked caretCoords;
@ -34,6 +35,8 @@ export default class AiHelperContextMenu extends Component {
@tracked customPromptValue = ""; @tracked customPromptValue = "";
@tracked initialValue = ""; @tracked initialValue = "";
@tracked thumbnailSuggestions = null; @tracked thumbnailSuggestions = null;
@tracked selectionRange = { x: 0, y: 0 };
@tracked lastSelectionRange = null;
CONTEXT_MENU_STATES = { CONTEXT_MENU_STATES = {
triggers: "TRIGGERS", triggers: "TRIGGERS",
@ -344,7 +347,17 @@ export default class AiHelperContextMenu extends Component {
@action @action
undoAIAction() { undoAIAction() {
if (this.capabilities.isFirefox) {
// execCommand("undo") is no not supported in Firefox so we insert old text at range
this._insertAt(
this.lastSelectionRange.x,
this.lastSelectionRange.y,
this.initialValue
);
} else {
document.execCommand("undo", false, null); document.execCommand("undo", false, null);
}
// context menu is prevented from closing when in review state // context menu is prevented from closing when in review state
// so we change to reset state quickly before closing // so we change to reset state quickly before closing
this.menuState = this.CONTEXT_MENU_STATES.resets; this.menuState = this.CONTEXT_MENU_STATES.resets;
@ -357,6 +370,7 @@ export default class AiHelperContextMenu extends Component {
this.lastUsedOption = option; this.lastUsedOption = option;
this.menuState = this.CONTEXT_MENU_STATES.loading; this.menuState = this.CONTEXT_MENU_STATES.loading;
this.initialValue = this.selectedText; this.initialValue = this.selectedText;
this.lastSelectionRange = this.selectionRange;
this._activeAIRequest = ajax("/discourse-ai/ai-helper/suggest", { this._activeAIRequest = ajax("/discourse-ai/ai-helper/suggest", {
method: "POST", method: "POST",