Skip to content

Build your personal knowledge base with Trilium Notes

style(ai-assistant): draw the Result/Changes choice as Trilium's button group

Elian Doraneae469aa49e8
diff --git a/apps/client/src/stylesheets/ckeditor-theme.css b/apps/client/src/stylesheets/ckeditor-theme.css
index ec0ff86d4a..da01f9a39f 100644
--- a/apps/client/src/stylesheets/ckeditor-theme.css
+++ b/apps/client/src/stylesheets/ckeditor-theme.css
@@ -118,6 +118,17 @@ body {
div.ck.ck-dialog {
--ck-color-dialog-background: var(--modal-background-color, var(--main-background-color));
+ /* CKEditor rings every :focus and :active with a blue 1px border plus a 3px #cae1fc halo, and
+ the toolbar scopes are the only place Trilium takes it off.
+ `--ck-focus-ring` has to be redefined rather than just `--ck-color-focus-border`: the ring is
+ declared at `:root`, so the colour is substituted into it there and it inherits down already
+ resolved — recolouring further down the tree cannot reach it. The ring is kept at 1px rather
+ than made transparent because `.ck-input:focus` draws its focus border from it. */
+ --ck-focus-ring: 1px solid var(--input-focus-outline-color, var(--main-border-color));
+ --ck-color-focus-border: var(--input-focus-outline-color, var(--main-border-color));
+ --ck-focus-outer-shadow: none;
+ --ck-focus-disabled-outer-shadow: none;
+
border: 1px solid var(--modal-border-color, var(--main-border-color));
border-radius: var(--bs-border-radius-lg);
box-shadow: 0 .5em 3em .5em var(--modal-shadow-color, rgba(0, 0, 0, .2));
@@ -157,3 +168,10 @@ div.ck.ck-dialog .ck.ck-form__header > .ck.ck-button:hover {
div.ck.ck-dialog .ck.ck-form__header > .ck.ck-button:active {
transform: scale(.85);
}
+
+/* The button's own `border: 0` outranks CKEditor's focus ring, so without this the close button
+ has no focus indicator at all. Same outline `.modal .modal-header .btn-close` gets. */
+div.ck.ck-dialog .ck.ck-form__header > .ck.ck-button:focus-visible {
+ outline: 2px solid var(--input-focus-outline-color, var(--main-border-color));
+ outline-offset: 2px;
+}
diff --git a/apps/client/src/stylesheets/theme-next/forms.css b/apps/client/src/stylesheets/theme-next/forms.css
index 7639e3958e..b4e2cdf7e9 100644
--- a/apps/client/src/stylesheets/theme-next/forms.css
+++ b/apps/client/src/stylesheets/theme-next/forms.css
@@ -222,6 +222,48 @@ button.tn-low-profile:hover {
}
}
+/* The AI assistant's Result/Changes choice, drawn as the same track. Its buttons are CKEditor's,
+ so the selected one is `.ck-on` rather than `.active`, and the background has to be taken off
+ `--ck-button-background` instead of `--cmd-button-background-color`. */
+:root .ck.ck-ai-assistant-form .ck-ai-assistant-form__viewmodes {
+ gap: 4px;
+ border-radius: 8px;
+ background: var(--button-group-background-color);
+ padding: 4px;
+
+ button.ck.ck-button {
+ min-width: unset;
+ margin: 0;
+ box-shadow: unset;
+ border-radius: 8px;
+ background: transparent;
+ /* CKEditor rings a button on `:active` as well as on `:focus`, so a held segment would
+ outline itself; the segments a group is normally built from carry no border at all.
+ Only the colour is dropped, keeping the 1px so the geometry stays put. Keyboard focus
+ is covered by the outline below. */
+ border-color: transparent;
+
+ /* The segments a group is normally built from are `.icon-action`s, which hover against
+ `--hover-item-background-color`; a CKEditor button would otherwise bring its own, far
+ heavier `--ck-color-button-default-hover-background`. */
+ &:hover:not(.ck-on) {
+ background: var(--hover-item-background-color);
+ color: var(--hover-item-text-color);
+ }
+
+ &.ck-on, &.ck-on:hover {
+ background: var(--button-group-active-button-background-color);
+ color: var(--button-group-active-button-color);
+
+ box-shadow: 1px 1px 1px var(--button-group-active-button-shadow-color);
+ }
+
+ &:focus-visible {
+ outline: 2px solid var(--input-focus-outline-color);
+ }
+ }
+}
+
/*
* Selectable cards (import/export pickers) — mirror the button-group look: borderless, a recessed
* group background, and a raised "selected" chip with a subtle shadow. The base component styling
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 de7637bc01..2c2f5082d9 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
@@ -52,6 +52,11 @@ describe("AiAssistantFormView", () => {
expect(form.resultToggleView.isVisible).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.
+ expect(form.resultToggleView.element?.parentElement)
+ .toBe(form.changesToggleView.element?.parentElement);
+ expect(form.resultToggleView.element?.closest(".ck-ai-assistant-form__viewmodes")).not.toBeNull();
+
form.resultToggleView.fire("execute");
expect(form.viewMode).toBe("result");
expect(previewHtml()).toBe("<p>new</p>");
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 0f8bfee8b8..ca401b942b 100644
--- a/packages/ckeditor5/src/plugins/ai_assistant/ai_assistant_form.ts
+++ b/packages/ckeditor5/src/plugins/ai_assistant/ai_assistant_form.ts
@@ -112,7 +112,16 @@ export default class AiAssistantFormView extends View {
// pushed to the right. The feature's title belongs to the dialog's header.
tag: "div",
attributes: { class: ["ck", "ck-ai-assistant-form__preview-toolbar"] },
- children: [this.resultToggleView, this.changesToggleView, this.tryAgainButtonView]
+ children: [
+ {
+ // The two modes are one choice, so they share a container the host can
+ // draw as a group — Trilium renders it as its segmented track.
+ tag: "div",
+ attributes: { class: ["ck", "ck-ai-assistant-form__viewmodes"] },
+ children: [this.resultToggleView, this.changesToggleView]
+ },
+ this.tryAgainButtonView
+ ]
},
this.previewView,
{
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 07d6147e82..9e41069387 100644
--- a/packages/ckeditor5/src/plugins/ai_assistant/theme/ai_assistant.css
+++ b/packages/ckeditor5/src/plugins/ai_assistant/theme/ai_assistant.css
@@ -17,6 +17,18 @@
display: none;
}
+.ck.ck-ai-assistant-form .ck-ai-assistant-form__viewmodes {
+ display: flex;
+ align-items: center;
+ gap: var(--ck-spacing-tiny);
+}
+
+/* A review with no diff to offer hides both modes; the container must not stay behind as an
+ empty frame wherever the host gives it a background of its own. */
+.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-button.ck-ai-assistant-form__try-again {
margin-inline-start: auto;
}