feat(attachments): support local files and video attachments (#6321)

* feat(attachments): support local files and video attachments

Share gateway inspection and send validation for borrowed local paths while preserving binary uploads, original-file ownership, and existing limits.

Related to NAN-284. Native provider video input remains outside this change.

* test: make cross-platform verification fixtures self-contained

* test(webui): align typed fixtures with runtime contracts

* fix(webui): preserve uploaded video playback during history sync

* test(tui): preserve local attachment drafts across resizes

* perf(attachments): preserve upload caches and release video previews

* docs(webui): keep attachment guidance user-focused

* chore: remove redundant dependency comment

* test(providers): make stream idle renewal timing deterministic

* fix(attachments): keep upload byte limits out of local references

Validate common format/count rules separately from upload byte budgets. Keep local inspection and send-time checks metadata-only, and exclude local references from composer and pending-upload totals. Explain upload size rejections with actual size and maximum in all ten locales. Related to NAN-284.

* fix(attachments): retain image references and draft order

* fix(attachments): close local reference UX and authorization gaps

* fix(attachments): preserve focus during asynchronous path confirmation
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-22 18:32:18 +08:00
1 parent 7dfeff9ddf
commit 254f94b068
65 files changed
+1816 -292

No files matched your search

+13 -9
View File
@@ -19,7 +19,7 @@ export function useComposerMentionInput({
}) {
const text = useMemo(() => composerMentionText(segments), [segments]);
const textRef = useRef(text);
const pendingSelection = useRef<{ start: number; end: number } | null>(null);
const pendingSelection = useRef<{ start: number; end: number; preserveFocus?: boolean } | null>(null);
const history = useRef<{ undo: Snapshot[]; redo: Snapshot[] }>({ undo: [], redo: [] });
const lastEdit = useRef({ type: "", at: 0, cursor: -1 });
const composing = useRef(false);
@@ -42,10 +42,10 @@ export function useComposerMentionInput({
return selection;
}, [inputRef]);
const selectRaw = useCallback((start: number, end = start) => {
const selectRaw = useCallback((start: number, end = start, preserveFocus = false) => {
const el = inputRef.current;
// Focus first: removing a queued prompt's edit button can reset a blurred selection.
el?.focus();
// Focus first for user actions; passive attachment confirmation keeps the active control.
if (!preserveFocus) el?.focus();
el?.setSelectionRange(
mentionTextOffset(textRef.current, start, "toDisplay", "start"),
mentionTextOffset(textRef.current, end, "toDisplay", "end"),
@@ -74,13 +74,13 @@ export function useComposerMentionInput({
}
textRef.current = text;
if (!composing.current && pendingSelection.current) {
const { start, end } = pendingSelection.current;
selectRaw(start, end);
const { start, end, preserveFocus } = pendingSelection.current;
selectRaw(start, end, preserveFocus);
pendingSelection.current = null;
}
});
const apply = useCallback((value: string, cursor: number, type = "", selection = rawSelection()) => {
const apply = useCallback((value: string, cursor: number, type = "", selection = rawSelection(), preserveFocus = false) => {
const previous = textRef.current;
if (value !== previous.raw) {
const now = Date.now();
@@ -93,10 +93,14 @@ export function useComposerMentionInput({
history.current.redo = [];
lastEdit.current = { type, at: now, cursor };
}
pendingSelection.current = value === previous.raw ? null : { start: cursor, end: cursor };
pendingSelection.current = value === previous.raw ? null : { start: cursor, end: cursor, preserveFocus };
onEdit(value, cursor);
}, [onEdit, rawSelection]);
const replace = useCallback((value: string, cursor: number, { preserveFocus = false } = {}) => {
apply(value, cursor, "", undefined, preserveFocus);
}, [apply]);
const beforeSelection = useRef<{ start: number; end: number; raw: { start: number; end: number } } | null>(null);
const captureSelection = useCallback(() => {
const el = inputRef.current;
@@ -170,7 +174,7 @@ export function useComposerMentionInput({
),
isComposing: compositionValue !== null,
rawSelection,
replace: apply,
replace,
onChange,
onKeyDown,
onCopy: (event: ClipboardEvent<HTMLTextAreaElement>) => copy(event, false),