Skip to content

Build your personal knowledge base with Trilium Notes

fix(ai-assistant): keep the preview's strip in place instead of revealing it

Elian Doran27569644dbd1
diff --git a/packages/ckeditor5/src/plugins/ai_assistant/ai_assistant_form.spec.ts b/packages/ckeditor5/src/plugins/ai_assistant/ai_assistant_form.spec.ts
index 5d44a6f73e..d913b337d1 100644
--- a/packages/ckeditor5/src/plugins/ai_assistant/ai_assistant_form.spec.ts
+++ b/packages/ckeditor5/src/plugins/ai_assistant/ai_assistant_form.spec.ts
@@ -20,11 +20,16 @@ afterEach(() => {
});
describe("AiAssistantFormView", () => {
- it("starts in the prompt phase with the view-mode toggle hidden", () => {
+ it("starts in the prompt phase with the strip on show but inert", () => {
const form = makeForm();
expect(form.phase).toBe("prompt");
- expect(form.resultToggleView.isVisible).toBe(false);
- expect(form.changesToggleView.isVisible).toBe(false);
+
+ // The strip holds its place from the start — appearing with the response would shift
+ // every row beneath it — so nothing in it is hidden, only disabled.
+ for (const view of [form.resultToggleView, form.changesToggleView, form.tryAgainButtonView]) {
+ expect(view.isVisible).toBe(true);
+ expect(view.isEnabled).toBe(false);
+ }
// Without the reset exemption, the body wrapper's `.ck-reset_all` nowraps every paragraph.
expect(form.previewView.element?.classList.contains("ck-reset_all-excluded")).toBe(true);
});
@@ -49,7 +54,7 @@ describe("AiAssistantFormView", () => {
expect(form.hasDiff).toBe(true);
expect(form.viewMode).toBe("changes");
expect(previewHtml()).toContain("diffins");
- expect(form.resultToggleView.isVisible).toBe(true);
+ expect(form.resultToggleView.isEnabled).toBe(true);
expect(form.changesToggleView.isOn).toBe(true);
// The two modes are one choice, and share a container so the host can draw them as a group.
@@ -76,10 +81,9 @@ describe("AiAssistantFormView", () => {
expect(form.hasDiff).toBe(false);
expect(form.viewMode).toBe("result");
expect(previewHtml()).toBe("<p>generated</p>");
- expect(form.changesToggleView.isVisible).toBe(false);
-
- // "Try again" is the one thing left in the preview's strip, so the strip still shows.
- expect(form.tryAgainButtonView.isVisible).toBe(true);
+ // Nothing to diff against, so the choice stays inert while re-running does not.
+ expect(form.changesToggleView.isEnabled).toBe(false);
+ expect(form.tryAgainButtonView.isEnabled).toBe(true);
});
it("takes the prompt through a placeholder rather than a label, and sends with an icon", () => {
@@ -110,7 +114,7 @@ describe("AiAssistantFormView", () => {
const form = makeForm();
const button = form.tryAgainButtonView;
- expect(button.isVisible).toBe(false);
+ expect(button.isEnabled).toBe(false);
expect(button.withText).toBe(false);
expect(button.icon).toContain("<svg");
// Icon-only: the label has to survive as the tooltip and the accessible name.
@@ -123,7 +127,7 @@ describe("AiAssistantFormView", () => {
form.beginStreaming();
form.setPreview("<p>new</p>");
form.enterReview(true, null, "");
- expect(button.isVisible).toBe(true);
+ expect(button.isEnabled).toBe(true);
});
it("shows the usage line only for a review that has one, and clears it on the next run", () => {
diff --git a/packages/ckeditor5/src/plugins/ai_assistant/ai_assistant_form.ts b/packages/ckeditor5/src/plugins/ai_assistant/ai_assistant_form.ts
index f3545bacf3..392cd305b2 100644
--- a/packages/ckeditor5/src/plugins/ai_assistant/ai_assistant_form.ts
+++ b/packages/ckeditor5/src/plugins/ai_assistant/ai_assistant_form.ts
@@ -92,9 +92,17 @@ export default class AiAssistantFormView extends View {
this.insertBelowButtonView = this._createActionButton(locale, t("Insert below"), "review", "insertBelow");
// Icon-only, and sitting over the preview rather than among the commit actions: re-running
// is about the response on screen, not about what to do with it.
- this.tryAgainButtonView = this._createActionButton(locale, t("Try again"), "review", "tryAgain");
- this.tryAgainButtonView.set({ icon: IconRefresh, withText: false, tooltip: true });
- this.tryAgainButtonView.class = "ck-ai-assistant-form__icon-action";
+ this.tryAgainButtonView = new ButtonView(locale);
+ this.tryAgainButtonView.set({
+ label: t("Try again"),
+ icon: IconRefresh,
+ tooltip: true,
+ class: "ck-ai-assistant-form__icon-action"
+ });
+ // On show throughout, for the same reason the view modes are: the strip has to hold its
+ // place so a finished run does not move the rows beneath it.
+ this.tryAgainButtonView.bind("isEnabled").to(this, "phase", (phase) => phase === "review");
+ this.tryAgainButtonView.on("execute", () => this.fire("tryAgain"));
const bind = this.bindTemplate;
@@ -281,7 +289,9 @@ export default class AiAssistantFormView extends View {
const button = new ButtonView(locale);
button.set({ label, withText: true, isToggleable: true, class: "ck-ai-assistant-form__viewmode" });
button.bind("isOn").to(this, "viewMode", (viewMode) => viewMode === mode);
- button.bind("isVisible").to(
+ // Enabled rather than shown: a strip that only appears once a run finishes would shift
+ // everything under it at the moment the response lands.
+ button.bind("isEnabled").to(
this, "phase",
this, "hasDiff",
(phase, hasDiff) => phase === "review" && hasDiff
diff --git a/packages/ckeditor5/src/plugins/ai_assistant/theme/ai_assistant.css b/packages/ckeditor5/src/plugins/ai_assistant/theme/ai_assistant.css
index 44a2c612ee..47c54c3f84 100644
--- a/packages/ckeditor5/src/plugins/ai_assistant/theme/ai_assistant.css
+++ b/packages/ckeditor5/src/plugins/ai_assistant/theme/ai_assistant.css
@@ -13,21 +13,12 @@
gap: var(--ck-spacing-medium);
}
-/* Outside a review every button in the strip is hidden; it should not reserve a gap of its own. */
-.ck.ck-ai-assistant-form .ck-ai-assistant-form__preview-toolbar:not(:has(.ck-button:not(.ck-hidden))) {
- display: none;
-}
-
.ck.ck-ai-assistant-form .ck-ai-assistant-form__viewmodes {
display: flex;
align-items: center;
gap: var(--ck-spacing-tiny);
}
-.ck.ck-ai-assistant-form .ck-ai-assistant-form__viewmodes:not(:has(.ck-button:not(.ck-hidden))) {
- display: none;
-}
-
.ck.ck-ai-assistant-form .ck-ai-assistant-form__preview-toolbar-end {
display: flex;
align-items: center;