Chat: Copy response/message/code say Copied or Couldn't copy and fall back to the older copy route (#3731); a pasted screenshot is also read from clipboard items (#3748); the user bubble keeps its line breaks (#3720)
This commit is contained in:
1 parent
014fd6b5db
commit
5faf357b49
6 files changed
+56
-13
No files matched your search
@@ -9,7 +9,14 @@ export const DROP_EVENT = 'strata:drop-files';
|
||||
/** The pictures on the clipboard, named so each one is told apart in the composer (a pasted screenshot arrives as "image.png"). */
|
||||
export function pastedFiles(data: DataTransfer | null | undefined): File[] {
|
||||
const out: File[] = [];
|
||||
for (const file of Array.from(data?.files ?? [])) {
|
||||
// `files` is empty for some screenshot tools (Win+Shift+S in WebView2): the same picture is then only in `items`.
|
||||
const found = Array.from(data?.files ?? []);
|
||||
if (!found.some(f => f.type.startsWith('image/')))
|
||||
for (const item of Array.from(data?.items ?? [])) {
|
||||
const file = item.kind === 'file' && item.type.startsWith('image/') ? item.getAsFile() : null;
|
||||
if (file) found.push(file);
|
||||
}
|
||||
for (const file of found) {
|
||||
if (!file.type.startsWith('image/')) continue;
|
||||
const extension = file.type.split('/')[1]?.replace('jpeg', 'jpg').replace(/[+].*/, '') || 'png';
|
||||
out.push(new File([file], `Pasted picture ${new Date().toLocaleTimeString().replace(/[^0-9]+/g, '-').replace(/-$/, '')}${out.length ? `-${out.length + 1}` : ''}.${extension}`, { type: file.type }));
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { tr } from '../lib/i18n';
|
||||
import { copyAndTell } from '../lib/copy-text';
|
||||
/** Safe, dependency-free rendering of the Markdown structures used in answers. */
|
||||
import { Fragment, type ReactNode } from 'react';
|
||||
import { Btn, IconBtn } from './ui';
|
||||
@@ -69,7 +70,7 @@ export function Markdown({ text, onOpenLink, onPreviewHtml, imageSession }: {
|
||||
while (i < lines.length && !/^\s*```/.test(lines[i]))
|
||||
body.push(lines[i++]);
|
||||
i++;
|
||||
nodes.push(<div className="st-code" key={key}><div className="st-code__head"><span>{language || tr('code')}</span>{tr(/^html$/i.test(language) && onPreviewHtml ? <Btn size="sm" onClick={() => onPreviewHtml(body.join('\n'))}>{tr("Open preview")}</Btn> : null)}<IconBtn name="copy" title={tr("Copy code")} onClick={() => void navigator.clipboard.writeText(body.join('\n'))}/></div><SyntaxCode text={body.join('\n')} language={language}/></div>);
|
||||
nodes.push(<div className="st-code" key={key}><div className="st-code__head"><span>{language || tr('code')}</span>{tr(/^html$/i.test(language) && onPreviewHtml ? <Btn size="sm" onClick={() => onPreviewHtml(body.join('\n'))}>{tr("Open preview")}</Btn> : null)}<IconBtn name="copy" title={tr("Copy code")} onClick={() => void copyAndTell(body.join('\n'), 'Code')}/></div><SyntaxCode text={body.join('\n')} language={language}/></div>);
|
||||
continue;
|
||||
}
|
||||
const block = displayBlock(lines, i);
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import { pushToast } from './store';
|
||||
|
||||
/**
|
||||
* Put text on the clipboard. The browser clipboard call can be refused inside the app window (WebView2 asks no one and says no),
|
||||
* so a hidden text field and the older copy command are the second try. Resolves true when one of them worked.
|
||||
*/
|
||||
export async function copyText(value: string): Promise<boolean> {
|
||||
try {
|
||||
await navigator.clipboard.writeText(value);
|
||||
return true;
|
||||
}
|
||||
catch {
|
||||
// fall through to the older route
|
||||
}
|
||||
try {
|
||||
const field = document.createElement('textarea');
|
||||
field.value = value;
|
||||
field.setAttribute('readonly', '');
|
||||
field.style.cssText = 'position:fixed;left:-9999px;top:0;opacity:0';
|
||||
document.body.appendChild(field);
|
||||
field.select();
|
||||
const ok = document.execCommand('copy');
|
||||
field.remove();
|
||||
return ok;
|
||||
}
|
||||
catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** Copy and say so: "Copied", or "Couldn't copy" with what to do instead. */
|
||||
export async function copyAndTell(value: string, label: string): Promise<void> {
|
||||
if (await copyText(value))
|
||||
pushToast('success', 'Copied', label);
|
||||
else
|
||||
pushToast('warn', 'Couldn’t copy', 'Select the text and copy it manually.');
|
||||
}
|
||||
@@ -41,6 +41,7 @@ import { relTime, cx, duration, tokens, tps } from '../lib/format';
|
||||
import { createSubagentExample, pushToast, setPreviewTabClosed, branchFrom, continueLast, markRead, resolveTool, retryLast, selectSession, rewindTo, sendMessage, stopStreaming, useStore, } from '../lib/store';
|
||||
import { getSlashCommands } from '../lib/commands';
|
||||
import { useLocation } from '../lib/router';
|
||||
import { copyAndTell } from '../lib/copy-text';
|
||||
import { composerSends } from '../lib/shortcut-bindings';
|
||||
import type { ChatMessage, Session, ToolCall } from '../lib/types';
|
||||
export function ChatScreen() {
|
||||
@@ -620,7 +621,7 @@ function Message({ message: m, isLast, onEditPrompt, onPreview, onOpenLink, onOp
|
||||
<div className="st-msg__meta">
|
||||
<time dateTime={m.at} title={tr(new Date(m.at).toLocaleString(localeTag()))}>{tr(sentTime)}</time>
|
||||
<span className="st-msg__actions">
|
||||
<IconBtn name="copy" title={tr("Copy message")} onClick={() => void navigator.clipboard.writeText(m.content)}/>
|
||||
<IconBtn name="copy" title={tr("Copy message")} onClick={() => void copyAndTell(m.content, 'Message')}/>
|
||||
<IconBtn name="refresh" title={tr("Rewind to here")} disabled={streaming} onClick={() => {
|
||||
const prompt = rewindTo(m.id);
|
||||
if (prompt !== null)
|
||||
@@ -659,11 +660,11 @@ function Message({ message: m, isLast, onEditPrompt, onPreview, onOpenLink, onOp
|
||||
{tr(!m.streaming && !m.timeSkipId && (m.content || m.error) ? (<div className="st-msg__meta">
|
||||
<span className="st-msg__actions">
|
||||
{tr(isLast ? <>
|
||||
<IconBtn name="copy" title={tr("Copy response")} onClick={() => void navigator.clipboard.writeText(m.content)}/>
|
||||
<IconBtn name="copy" title={tr("Copy response")} onClick={() => void copyAndTell(m.content, 'Message')}/>
|
||||
<IconBtn name="refresh" title={tr("Ask again")} onClick={() => void retryLast(m.id)}/>
|
||||
</> : null)}
|
||||
<MessageMenu label={tr("More response actions")}>
|
||||
{tr(!isLast ? <><button role="menuitem" className="menu__item" onClick={() => void navigator.clipboard.writeText(m.content)}>{tr("Copy response")}</button><button role="menuitem" className="menu__item" onClick={() => void retryLast(m.id)}>{tr("Ask again")}</button></> : null)}
|
||||
{tr(!isLast ? <><button role="menuitem" className="menu__item" onClick={() => void copyAndTell(m.content, 'Message')}>{tr("Copy response")}</button><button role="menuitem" className="menu__item" onClick={() => void retryLast(m.id)}>{tr("Ask again")}</button></> : null)}
|
||||
{tr(isLast ? <button role="menuitem" className="menu__item" onClick={() => void continueLast()}>{tr("Continue")}</button> : null)}
|
||||
<button role="menuitem" className="menu__item" onClick={() => branchFrom(m.id)}>{tr("Branch from here")}</button>
|
||||
{tr(m.tokens || m.tps || m.durationMs ? <p className="xs muted response-stats">{tr(m.tokens ? `${tokens(m.tokens)} tokens` : '')}{tr(m.tps ? ` · ${tps(m.tps)} tok/s` : '')}{tr(m.durationMs ? ` · ${duration(m.durationMs)}` : '')}{tr(m.demo ? ' · Example' : '')}</p> : null)}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { copyAndTell } from '../lib/copy-text';
|
||||
import { tr } from '../lib/i18n';
|
||||
import { appBaseUrl } from '../lib/connect-urls';
|
||||
import { deviceLabel, instanceLabel } from '../lib/runtime-models';
|
||||
@@ -8,7 +9,7 @@ import { useEffect, useRef, useState } from 'react';
|
||||
import { Btn, Dialog, Empty, Icon, IconBtn, Seg, Select, ErrorNotice } from '../components/ui';
|
||||
import { Screen, SectionHead } from '../components/layout';
|
||||
import { clockTime, duration, tokens } from '../lib/format';
|
||||
import { cancelRequest, setLocalSharing, setServingAccess, useStore, pushToast } from '../lib/store';
|
||||
import { cancelRequest, setLocalSharing, setServingAccess, useStore } from '../lib/store';
|
||||
export function ServingScreen() {
|
||||
const serving = useStore(s => s.serving);
|
||||
const storedRuntime = useStore(s => s.runtime), hardware = useStore(s => s.hardware);
|
||||
@@ -73,13 +74,7 @@ export function ServingScreen() {
|
||||
}
|
||||
}
|
||||
async function copyConnectionValue(value: string, label: string) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(value);
|
||||
pushToast('success', 'Copied', label);
|
||||
}
|
||||
catch {
|
||||
pushToast('warn', 'Couldn’t copy', 'Select the value and copy it manually.');
|
||||
}
|
||||
await copyAndTell(value, label);
|
||||
}
|
||||
const code = `curl ${serving.baseUrl}${protocol === 'responses' ? '/responses' : protocol === 'openai' ? serving.endpoints.openai : serving.endpoints.anthropic} \\\n -H 'Content-Type: application/json'${serving.access.apiKeySet ? " \\\n -H 'Authorization: Bearer YOUR_API_KEY'" : ''} \\\n -d '${JSON.stringify({ model: loaded?.apiModelId ?? 'YOUR_MODEL_ID', ...(protocol === 'responses' ? { input: 'Hello', store: false } : { ...(protocol === 'anthropic' ? { max_tokens: 256 } : {}), messages: [{ role: 'user', content: 'Hello' }] }) }, null, 2)}'`;
|
||||
return <Screen title={tr("Serving")} actions={<><Btn icon="link" onClick={() => setCloudflareOpen(true)}>{tr("Cloudflare tunnel")}</Btn><IconBtn name="info" title={tr("Connection guide")} onClick={() => setGuide(true)}/></>}><div className="stack stack--lg">
|
||||
|
||||
@@ -4083,6 +4083,8 @@ textarea.st-input {
|
||||
.st-msg--user .st-bubble {
|
||||
background: var(--st-accent-surface);
|
||||
color: var(--st-accent-surface-ink);
|
||||
white-space: pre-wrap; /* a typed or pasted message keeps its line breaks (#3720) */
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
/* October 2026 clarity pass. App-specific extensions survive design-kit sync. */
|
||||
|
||||
Reference in new issue
Block a user