Merge "Move the binding of AccountCache outside AccountCacheImpl"
diff --git a/Documentation/user-suggest-edits.txt b/Documentation/user-suggest-edits.txt
index 3b2c83a..55181a2 100644
--- a/Documentation/user-suggest-edits.txt
+++ b/Documentation/user-suggest-edits.txt
@@ -1,7 +1,7 @@
-= Gerrit Code Review - User suggested edits (Experiment)
+= Gerrit Code Review - User suggested edits
 
 Easy and fast way for reviewers to suggest code changes that can be easily applied
-by change owner.
+by the change owner.
 
 == Reviewer workflow
 
@@ -26,15 +26,16 @@
 
 == Author workflow
 
-You can apply one or more suggested fixes. When suggested fix is applied - it creates
-a change edit that you can modify in gerrit. link:user-inline-edit.html#editing-change[More about editing mode.]
+You can apply one or more suggested edits. When a suggested edit is applied it
+creates a change edit that you can further modify in Gerrit. You can read more
+about all the features of link:user-inline-edit.html#editing-change[change edit mode].
 
-FYI: Publishing a new patchset in gerrit will make gerrit change out of sync with
-your local git. You can checkout latest gerrit by using commands from download drop-down panel.
-link:user-review-ui.html#download[More about download drop-down panel]
+FYI: Publishing a new patchset in Gerrit will make your Gerrit change out of
+sync with your local git commit. You can checkout the latest Gerrit patchset
+by using the commands from the link:user-review-ui.html#download[download drop-down panel].
 
-You can use copy to clipboard button to copy suggestion to clipboard and then you can paste it
-in your editor.
+Alternatively, you can use the copy to clipboard button to copy a suggested
+edit to your clipboard and then you can paste it into your editor.
 
 == Generate Suggestion
 
diff --git a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
index baba0635..899f860 100644
--- a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
+++ b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
@@ -997,7 +997,7 @@
   }
 
   private renderFixSuggestionPreview() {
-    if (!this.comment?.fix_suggestions) return nothing;
+    if (!this.comment?.fix_suggestions || isDraft(this.comment)) return nothing;
     return html`<gr-suggestion-diff-preview
       .fixReplacementInfos=${this.comment?.fix_suggestions?.[0].replacements}
     ></gr-suggestion-diff-preview>`;
@@ -1028,6 +1028,7 @@
   private renderGeneratedSuggestionPreview() {
     if (!this.showGeneratedSuggestion() || !this.generateSuggestion)
       return nothing;
+    if (!isDraft(this.comment)) return nothing;
 
     if (this.generatedFixSuggestion) {
       return html`<gr-suggestion-diff-preview
@@ -1065,6 +1066,15 @@
               );
               if (this.generateSuggestion) {
                 this.generateSuggestionTrigger$.next();
+              } else {
+                if (
+                  this.flagsService.isEnabled(
+                    KnownExperimentId.ML_SUGGESTED_EDIT_V2
+                  )
+                ) {
+                  this.generatedFixSuggestion = undefined;
+                  this.autoSaveTrigger$.next();
+                }
               }
               this.reporting.reportInteraction(
                 this.generateSuggestion
@@ -1101,7 +1111,7 @@
     if (!this.generateSuggestion) {
       return '';
     }
-    if (this.generatedSuggestion) {
+    if (this.generatedSuggestion || this.generatedFixSuggestion) {
       return '(1)';
     } else {
       return '(0)';
@@ -1224,6 +1234,7 @@
     const suggestion = suggestionResponse.fix_suggestions?.[0];
     if (!suggestion) return;
     this.generatedFixSuggestion = suggestion;
+    this.autoSaveTrigger$.next();
   }
 
   private renderRobotActions() {
@@ -1570,7 +1581,7 @@
     assert(isDraft(this.comment), 'only drafts are editable');
     const messageToSave = this.messageText.trimEnd();
     if (messageToSave === '') return;
-    if (messageToSave === this.comment.message) return;
+    if (!this.somethingToSave()) return;
 
     try {
       this.autoSaving = this.rawSave({showToast: false});
@@ -1634,7 +1645,8 @@
     return (
       isError(this.comment) ||
       this.messageText.trimEnd() !== this.comment?.message ||
-      this.unresolved !== this.comment.unresolved
+      this.unresolved !== this.comment.unresolved ||
+      this.comment?.fix_suggestions !== this.getFixSuggestions()
     );
   }
 
@@ -1647,11 +1659,20 @@
         ...this.comment,
         message: this.messageText.trimEnd(),
         unresolved: this.unresolved,
+        fix_suggestions: this.getFixSuggestions(),
       },
       options.showToast
     );
   }
 
+  getFixSuggestions(): FixSuggestionInfo[] | undefined {
+    if (!this.flagsService.isEnabled(KnownExperimentId.ML_SUGGESTED_EDIT_V2))
+      return undefined;
+    if (!this.generateSuggestion) return undefined;
+    if (!this.generatedFixSuggestion) return undefined;
+    return [this.generatedFixSuggestion];
+  }
+
   private handleToggleResolved() {
     this.unresolved = !this.unresolved;
     if (!this.editing) {