Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ui/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
"swr": "^2.4.0",
"tailwind-merge": "^3.5.0",
"tailwindcss-animate": "^1.0.7",
"turndown": "^7.2.4",
"tw-animate-css": "^1.4.0",
"unist-util-visit": "^5.1.0",
"uuid": "^13.0.0",
Expand Down Expand Up @@ -132,6 +133,7 @@
"@types/react-dom": "^19.2.3",
"@types/react-syntax-highlighter": "^15.5.13",
"@types/shell-quote": "^1.7.5",
"@types/turndown": "^5.0.6",
"@types/yauzl": "^2.10.3",
"@typescript-eslint/eslint-plugin": "^8.56.1",
"@typescript-eslint/parser": "^8.56.1",
Expand Down
55 changes: 54 additions & 1 deletion ui/desktop/src/components/ChatInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,29 @@ import { UserInput, ImageData } from '../types/message';
import { compressImageDataUrl } from '../utils/conversionUtils';
import { fetchCanonicalModelInfo } from '../utils/canonical';
import { defineMessages, useIntl } from '../i18n';
import TurndownService from 'turndown';

const turndown = new TurndownService({
headingStyle: 'atx',
bulletListMarker: '-',
codeBlockStyle: 'fenced',
});

turndown.addRule('complexLinks', {
filter: (node) => {
return (
node.nodeName === 'A' &&
!!node.getAttribute('href') &&
/\n/.test(node.textContent || '')
);
},
replacement: (content, node) => {
const el = node as HTMLElement;
const href = el.getAttribute('href')!;
const label = content.replace(/\n+/g, ' ').trim();
return `[${label}](${href})`;
Comment on lines +65 to +67

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Escape multiline link URLs before emitting markdown

The complexLinks rule builds markdown links with a raw href ([${label}](${href})), so pasted anchors whose URLs contain markdown-significant characters (for example unmatched ) or whitespace) can produce malformed markdown and broken link destinations. This path is triggered specifically for multiline link text, so rich-text content from sources like docs/wiki pages can be converted into invalid links instead of preserving the original target reliably.

Useful? React with 👍 / 👎.

},
});

interface PastedImage {
id: string;
Expand Down Expand Up @@ -811,10 +834,40 @@ export default function ChatInput({
}, [droppedFiles.length, localDroppedFiles.length, onFilesProcessed, setLocalDroppedFiles]);

const handlePaste = async (evt: React.ClipboardEvent<HTMLTextAreaElement>) => {
if (isRecording) return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Allow image pastes while recording

Returning immediately when isRecording is true exits handlePaste before the image branch runs, so screenshot/image paste is silently disabled during dictation even though attachment flows are still available through the file picker. In environments where paste events still fire on read-only textareas, this is a regression from previous behavior and creates inconsistent attachment UX specifically for paste-based workflows.

Useful? React with 👍 / 👎.


const files = Array.from(evt.clipboardData.files || []);
const imageFiles = files.filter((file) => file.type.startsWith('image/'));

if (imageFiles.length === 0) return;
if (imageFiles.length === 0) {
const html = evt.clipboardData.getData('text/html');
if (html) {
const doc = new DOMParser().parseFromString(html, 'text/html');
const hasLinks = doc.querySelectorAll('a[href]').length > 0;
if (hasLinks) {
const markdown = turndown.turndown(doc.body).trim();
if (markdown) {
evt.preventDefault();
const textarea = textAreaRef.current;
if (textarea) {
const start = textarea.selectionStart;
const end = textarea.selectionEnd;
const newValue =
displayValue.substring(0, start) + markdown + displayValue.substring(end);
const cursorPos = start + markdown.length;
setDisplayValue(newValue);
updateValue(newValue);
setHasUserTyped(true);
checkForMentionOrSlash(newValue, cursorPos, textarea);
requestAnimationFrame(() => {
textarea.selectionStart = textarea.selectionEnd = cursorPos;
});
}
}
}
}
return;
}

// Check if adding these images would exceed the limit
if (pastedImages.length + imageFiles.length > MAX_IMAGES_PER_MESSAGE) {
Expand Down
56 changes: 32 additions & 24 deletions ui/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading