Revert "feat: AI entry button at the cell's bottom-right + clear input after success"

This reverts commit fd30e53e25.
This commit is contained in:
tao.chen
2026-07-23 19:34:38 +08:00
parent fd30e53e25
commit c0bcbda77f
4 changed files with 40 additions and 110 deletions
+11 -37
View File
@@ -50,22 +50,11 @@ export class OpenCodeCellActions extends Widget {
private _context: CellContext | null = null;
private _status: Status = 'idle';
private _prompt: OpenCodeInlinePrompt | null = null;
// Floating "AI" entry button that lives at the cell's bottom-right
// corner (overlaid on the cell, absolutely positioned). The widget's
// own node stays inside the native cell toolbar (as a hidden lifecycle
// holder) and is NOT where the user-visible button renders.
private _floatingBtn: HTMLButtonElement | null = null;
constructor(cell: CodeCell) {
super();
this._cell = cell;
this.addClass('opencode-cell-actions');
// Hide the widget's own node inside the native cell toolbar — the
// actual UI is the floating button below.
this.node.style.display = 'none';
// Anchor the absolutely-positioned floating button to the cell.
this._cell.node.style.position = 'relative';
this._createFloatingButton();
this._cell.model.contentChanged.connect(this._onModelChange, this);
this._cell.model.stateChanged.connect(this._onModelChange, this);
this._render();
@@ -79,26 +68,9 @@ export class OpenCodeCellActions extends Widget {
this._cell.model.contentChanged.disconnect(this._onModelChange, this);
this._cell.model.stateChanged.disconnect(this._onModelChange, this);
this._hidePrompt();
if (this._floatingBtn && this._floatingBtn.parentNode) {
this._floatingBtn.parentNode.removeChild(this._floatingBtn);
}
this._floatingBtn = null;
super.dispose();
}
private _createFloatingButton(): void {
const btn = document.createElement('button');
btn.className = 'opencode-cell-ai-btn';
btn.type = 'button';
btn.textContent = 'AI';
btn.title = '让 AI 修改这个 cell 的代码';
btn.addEventListener('click', () => {
this._togglePrompt();
});
this._cell.node.appendChild(btn);
this._floatingBtn = btn;
}
private _onModelChange(): void {
this._context = extractCellContextFromCell(this._cell);
if (this._prompt) {
@@ -109,18 +81,22 @@ export class OpenCodeCellActions extends Widget {
}
private _render(): void {
// The widget's own node no longer hosts the button (it lives at the
// cell's bottom-right). Just update the floating button's label and
// disabled state.
const btn = this._floatingBtn;
if (!btn) {
return;
}
const node = this.node;
node.textContent = '';
const baseDisabled = !this._context || this._status === 'loading';
const btn = document.createElement('button');
btn.className = 'opencode-btn opencode-btn-ai';
btn.textContent = 'AI';
btn.disabled = baseDisabled;
btn.title = baseDisabled
? 'OpenCode: 等待 cell 上下文…'
: '让 AI 修改这个 cell 的代码';
btn.addEventListener('click', () => {
this._togglePrompt();
});
node.appendChild(btn);
}
private _togglePrompt(): void {
@@ -228,8 +204,6 @@ export class OpenCodeCellActions extends Widget {
if (notebookPath) {
void this._refreshHistory(notebookPath);
}
// Clear the input so the user can type a follow-up message.
this._prompt?.clearInput();
Notification.info(
`OpenCode 完成 (${resp.markdown.length} chars). Session: ${resp.sessionId.slice(0, 8)}`
);