Merge "Add support for Vue code highlighting"
diff --git a/polygerrit-ui/app/elements/change-list/gr-change-list-section/gr-change-list-section.ts b/polygerrit-ui/app/elements/change-list/gr-change-list-section/gr-change-list-section.ts
index 91770ca..0799e03 100644
--- a/polygerrit-ui/app/elements/change-list/gr-change-list-section/gr-change-list-section.ts
+++ b/polygerrit-ui/app/elements/change-list/gr-change-list-section/gr-change-list-section.ts
@@ -172,7 +172,7 @@
   }
 
   override willUpdate(changedProperties: PropertyValues) {
-    if (changedProperties.has('changeSection')) {
+    if (changedProperties.has('changeSection') && this.isLoggedIn) {
       // In case the list of changes is updated due to auto reloading, we want
       // to ensure the model removes any stale change that is not a part of the
       // new section changes.
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 d238881..b55c9fd 100644
--- a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
+++ b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
@@ -91,7 +91,7 @@
 import {storageServiceToken} from '../../../services/storage/gr-storage_impl';
 import {deepEqual} from '../../../utils/deep-util';
 import {GrSuggestionDiffPreview} from '../gr-suggestion-diff-preview/gr-suggestion-diff-preview';
-import {waitUntil} from '../../../utils/async-util';
+import {noAwait, waitUntil} from '../../../utils/async-util';
 import {
   AutocompleteCache,
   AutocompletionContext,
@@ -254,6 +254,10 @@
     this.comment?.fix_suggestions?.[0];
 
   @state()
+  previewedGeneratedFixSuggestion: FixSuggestionInfo | undefined =
+    this.comment?.fix_suggestions?.[0];
+
+  @state()
   generatedSuggestionId?: string;
 
   @state()
@@ -1184,6 +1188,18 @@
     }
   }
 
+  // visible for testing
+  async waitPreviewForGeneratedSuggestion() {
+    const generatedFixSuggestion = this.generatedFixSuggestion;
+    if (!generatedFixSuggestion) return;
+    await waitUntil(
+      () =>
+        !!this.suggestionDiffPreview?.previewed &&
+        this.suggestionDiffPreview?.previewLoadedFor === generatedFixSuggestion
+    );
+    this.previewedGeneratedFixSuggestion = generatedFixSuggestion;
+  }
+
   private renderGenerateSuggestEditButton() {
     if (!this.showGeneratedSuggestion()) {
       return nothing;
@@ -1322,6 +1338,7 @@
       return;
     }
     this.generatedFixSuggestion = suggestion;
+    noAwait(this.waitPreviewForGeneratedSuggestion());
 
     try {
       await waitUntil(() => this.getFixSuggestions() !== undefined);
@@ -1558,6 +1575,9 @@
     assert(isDraft(this.comment), 'only drafts are editable');
     if (this.editing) return;
     this.editing = true;
+    // For quickly opening and closing the comment, the suggestion diff preview
+    // might not have time to load and preview.
+    noAwait(this.waitPreviewForGeneratedSuggestion());
   }
 
   // TODO: Move this out of gr-comment. gr-comment should not have a comments
@@ -1841,13 +1861,9 @@
     // Disable fix suggestions when the comment already has a user suggestion
     if (this.comment && hasUserSuggestion(this.comment)) return undefined;
     // we ignore fixSuggestions until they are previewed.
-    if (
-      this.suggestionDiffPreview &&
-      !this.suggestionDiffPreview?.previewed &&
-      !this.suggestionLoading
-    )
-      return undefined;
-    return [this.generatedFixSuggestion];
+    if (this.previewedGeneratedFixSuggestion)
+      return [this.previewedGeneratedFixSuggestion];
+    return undefined;
   }
 
   private handleToggleResolved() {
diff --git a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment_test.ts b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment_test.ts
index 5273439..7292c64 100644
--- a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment_test.ts
+++ b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment_test.ts
@@ -1158,6 +1158,9 @@
           '#suggestionDiffPreview'
         );
         suggestionDiffPreview.previewed = true;
+        suggestionDiffPreview.previewLoadedFor = generatedFixSuggestion;
+        await element.updateComplete;
+        await element.waitPreviewForGeneratedSuggestion();
         await element.updateComplete;
         element.save();
         await element.updateComplete;
diff --git a/polygerrit-ui/app/elements/shared/gr-suggestion-diff-preview/gr-suggestion-diff-preview.ts b/polygerrit-ui/app/elements/shared/gr-suggestion-diff-preview/gr-suggestion-diff-preview.ts
index 504ee63..87c81c0 100644
--- a/polygerrit-ui/app/elements/shared/gr-suggestion-diff-preview/gr-suggestion-diff-preview.ts
+++ b/polygerrit-ui/app/elements/shared/gr-suggestion-diff-preview/gr-suggestion-diff-preview.ts
@@ -285,6 +285,7 @@
     });
     if (currentPreviews.length > 0) {
       this.preview = currentPreviews[0];
+      this.previewed = true;
       this.previewLoadedFor = this.fixSuggestionInfo;
     }
 
diff --git a/polygerrit-ui/app/models/checks/checks-util.ts b/polygerrit-ui/app/models/checks/checks-util.ts
index 51bfcd9..85a7be4 100644
--- a/polygerrit-ui/app/models/checks/checks-util.ts
+++ b/polygerrit-ui/app/models/checks/checks-util.ts
@@ -54,6 +54,8 @@
       return {name: 'code'};
     case LinkIcon.FILE_PRESENT:
       return {name: 'file_present'};
+    case LinkIcon.VIEW_TIMELINE:
+      return {name: 'view_timeline'};
     default:
       // We don't throw an assertion error here, because plugins don't have to
       // be written in TypeScript, so we may encounter arbitrary strings for