Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(workbench): harden selection toolbar (touch, narrow viewport, draft)

cyh6c227d7d14e3
diff --git a/ui/src/components/workbench/ChatPage.tsx b/ui/src/components/workbench/ChatPage.tsx
index 1a49f0e30..d2c2d5d0e 100644
--- a/ui/src/components/workbench/ChatPage.tsx
+++ b/ui/src/components/workbench/ChatPage.tsx
@@ -5,6 +5,7 @@ import { ArrowLeft, Bell, Bot, ChevronDown, Clock, GitFork, Info, Loader2, Messa
import clsx from 'clsx';
import { useApi } from '../../context/ApiContext';
+import { useToast } from '../../context/ToastContext';
import { useWorkbenchInbox } from '../../context/WorkbenchInboxContext';
import { useRegisterComposerTarget, type ComposerInsertTarget } from '../../context/ComposerBridgeContext';
import type { VibeAgentBrief, WorkbenchMessage, WorkbenchSession } from '../../context/ApiContext';
@@ -94,6 +95,7 @@ export const ChatPage: React.FC = () => {
const { sessionId } = useParams<{ sessionId: string }>();
const { t } = useTranslation();
const navigate = useNavigate();
+ const { showToast } = useToast();
const location = useLocation();
// Deep-link target: the search palette routes to /chat/<session>?msg=<message>
// (P3 contract). When set, the jump effect below scrolls to + briefly
@@ -162,13 +164,20 @@ export const ChatPage: React.FC = () => {
try {
const forked = await api.forkSession(sessionId);
if (!forked?.id) return;
- await api.setSessionDraft(forked.id, quoteText(text));
+ // setSessionDraft returns {ok:false} for a non-OK response (it doesn't
+ // throw), so check it before navigating — don't strand the user in a
+ // fork with an empty composer and a lost selection.
+ const saved = await api.setSessionDraft(forked.id, quoteText(text));
+ if (!saved?.ok) {
+ showToast(t('chat.selection.askFailed'), 'error');
+ return;
+ }
navigate(`/chat/${encodeURIComponent(forked.id)}`);
} catch {
- // forkSession / setSessionDraft surface their own errors via the toast layer.
+ showToast(t('chat.selection.askFailed'), 'error');
}
},
- [sessionId, api, navigate],
+ [sessionId, api, navigate, showToast, t],
);
// Null target hides that sidebar action unless the composer is actually
// mounted + insertable: a chat is open (sessionId), its session has loaded
diff --git a/ui/src/components/workbench/SelectionQuoteToolbar.tsx b/ui/src/components/workbench/SelectionQuoteToolbar.tsx
index d29825ceb..aa589a397 100644
--- a/ui/src/components/workbench/SelectionQuoteToolbar.tsx
+++ b/ui/src/components/workbench/SelectionQuoteToolbar.tsx
@@ -112,7 +112,9 @@ export const SelectionQuoteToolbar: React.FC<{
const above = sel.top > TOOLBAR_H + GAP + EDGE;
const top = above ? sel.top - TOOLBAR_H - GAP : sel.bottom + GAP;
- const half = width / 2;
+ // Clamp by the on-screen (capped) width so a toolbar wider than the viewport
+ // centers + scrolls internally instead of pushing an edge off-screen.
+ const half = Math.min(width, window.innerWidth - 2 * EDGE) / 2;
const left = Math.min(Math.max(sel.left, EDGE + half), window.innerWidth - EDGE - half);
const itemClass = 'h-9 gap-1.5 rounded-none px-3 text-[13px] font-medium';
@@ -121,20 +123,17 @@ export const SelectionQuoteToolbar: React.FC<{
<div
ref={toolbarRef}
role="toolbar"
- // Keep the selection alive when the toolbar is pressed (desktop). On touch
- // the handlers use the captured `sel.text`, so a collapse is harmless too.
- onMouseDown={(e) => e.preventDefault()}
- style={{ position: 'fixed', top, left, transform: 'translateX(-50%)', zIndex: 60 }}
- className="flex items-center overflow-hidden rounded-lg border border-border-strong bg-surface-2 shadow-[0_12px_30px_-8px_rgba(0,0,0,0.7)]"
+ style={{ position: 'fixed', top, left, maxWidth: 'calc(100vw - 16px)', transform: 'translateX(-50%)', zIndex: 60 }}
+ className="flex items-center overflow-x-auto rounded-lg border border-border-strong bg-surface-2 shadow-[0_12px_30px_-8px_rgba(0,0,0,0.7)]"
>
- <Button variant="ghost" className={itemClass} onClick={runQuote}>
+ <Button variant="ghost" className={itemClass} onPointerDown={(e) => { e.preventDefault(); runQuote(); }}>
<TextQuote className="size-3.5 text-muted" />
{t('chat.selection.quote')}
</Button>
{onAskInNew && (
<>
<span className="h-5 w-px bg-border" />
- <Button variant="ghost" className={itemClass} onClick={runAsk}>
+ <Button variant="ghost" className={itemClass} onPointerDown={(e) => { e.preventDefault(); runAsk(); }}>
<GitFork className="size-3.5 text-muted" />
{t('chat.selection.askInNew')}
</Button>
@@ -143,7 +142,7 @@ export const SelectionQuoteToolbar: React.FC<{
{isTouch && (
<>
<span className="h-5 w-px bg-border" />
- <Button variant="ghost" className={itemClass} onClick={runCopy}>
+ <Button variant="ghost" className={itemClass} onPointerDown={(e) => { e.preventDefault(); runCopy(); }}>
{copied ? <Check className="size-3.5 text-mint" /> : <Copy className="size-3.5 text-muted" />}
{t('chat.selection.copy')}
</Button>
diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.json
index 374361bbb..95c07905b 100644
--- a/ui/src/i18n/en.json
+++ b/ui/src/i18n/en.json
@@ -1780,7 +1780,8 @@
"selection": {
"quote": "Quote",
"askInNew": "Ask in a new session",
- "copy": "Copy"
+ "copy": "Copy",
+ "askFailed": "Couldn't start a new session from the selection."
},
"showPage": {
"open": "Visualize",
diff --git a/ui/src/i18n/zh.json b/ui/src/i18n/zh.json
index 10e59efca..e7f809d12 100644
--- a/ui/src/i18n/zh.json
+++ b/ui/src/i18n/zh.json
@@ -1779,7 +1779,8 @@
"selection": {
"quote": "引用",
"askInNew": "在新会话询问",
- "copy": "复制"
+ "copy": "复制",
+ "askFailed": "无法从选中内容新建会话,请重试。"
},
"showPage": {
"open": "可视化",