fix(core): ask ai loses user selected context (#11767)

Close [AI-72](https://linear.app/affine-design/issue/AI-72)
This commit is contained in:
akumatus
2025-04-17 09:05:44 +00:00
parent d6287fd7b0
commit e577bb7aa9
4 changed files with 76 additions and 17 deletions

View File

@@ -281,12 +281,9 @@ export class AIChatInput extends SignalWatcher(WithDisposable(LitElement)) {
({ input, context, host }) => {
if (this.host === host) {
context && this.updateContext(context);
const { updateComplete, send } = this;
updateComplete
.then(() => {
return send(input);
})
.catch(console.error);
setTimeout(() => {
this.send(input).catch(console.error);
}, 0);
}
}
)

View File

@@ -84,11 +84,11 @@ export class AIPanelInput extends SignalWatcher(WithDisposable(LitElement)) {
}
}
.arrow[data-active] {
.arrow[data-active='true'] {
background: ${unsafeCSSVarV2('icon/activated')};
}
.arrow[data-active]:hover {
.arrow[data-active='true']:hover {
cursor: pointer;
}
@@ -140,7 +140,7 @@ export class AIPanelInput extends SignalWatcher(WithDisposable(LitElement)) {
)};
}
.arrow[data-active] {
.arrow[data-active='true'] {
background: ${unsafeCSS(
lightCssVariablesV2['--affine-v2-icon-activated']
)};
@@ -178,7 +178,7 @@ export class AIPanelInput extends SignalWatcher(WithDisposable(LitElement)) {
)};
}
.arrow[data-active] {
.arrow[data-active='true'] {
background: ${unsafeCSS(
darkCssVariablesV2['--affine-v2-icon-activated']
)};
@@ -196,13 +196,8 @@ export class AIPanelInput extends SignalWatcher(WithDisposable(LitElement)) {
this.onInput?.(this.textarea.value);
const value = this.textarea.value.trim();
if (value.length > 0) {
this._arrow.dataset.active = '';
this._hasContent = true;
} else {
delete this._arrow.dataset.active;
this._hasContent = false;
}
this._hasContent = value.length > 0;
this._arrow.dataset.active = String(this._hasContent);
};
private readonly _onKeyDown = (e: KeyboardEvent) => {
@@ -264,6 +259,7 @@ export class AIPanelInput extends SignalWatcher(WithDisposable(LitElement)) {
: nothing}
<div
class="arrow"
data-testid="ai-panel-input-send"
@click=${this._sendToAI}
@pointerdown=${stopPropagation}
>