Skip to content

Commit 5c7ff0c

Browse files
committed
Implement support for rendering text items in ResponsePreview using Markdown and add collapse/expand functionality for long text content
1 parent 414356b commit 5c7ff0c

9 files changed

Lines changed: 133 additions & 28 deletions

File tree

packages/ui/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"dayjs": "^1.11.10",
2828
"react": "^18.2.0",
2929
"react-dom": "^18.2.0",
30+
"react-markdown": "^10.1.0",
3031
"react-sortablejs": "^6.1.4",
3132
"react-textarea-autosize": "^8.5.9",
3233
"simplebar-react": "^3.3.1",

packages/ui/src/components/editor/panel/ResponsePreview/ResponsePreview.module.scss

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,6 @@
4646
.list {
4747
display: block;
4848

49-
&__text {
50-
color: var(--vscode-descriptionForeground);
51-
font-size: var(--font-size-12px);
52-
margin: var(--padding-6px) var(--padding-12px);
53-
background: var(--vscode-list-hoverBackground);
54-
padding: var(--padding-5px) var(--padding-7px);
55-
border-radius: var(--border-radius-8px);
56-
word-wrap: break-word;
57-
}
58-
5949
> div:first-child {
6050
margin-top: 0;
6151
}

packages/ui/src/components/editor/panel/ResponsePreview/ResponsePreview.stories.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ export const WithText = () => (
138138
...base_files,
139139
{
140140
type: 'text',
141-
content: 'Another text item explaining something.'
141+
content:
142+
'Another text item explaining something with **markdown**.\n\n* List item 1\n* List item 2\n\n`some code here`'
142143
},
143144
...files_using_fallbacks
144145
]}

packages/ui/src/components/editor/panel/ResponsePreview/ResponsePreview.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import cn from 'classnames'
44
import styles from './ResponsePreview.module.scss'
55
import { Checkbox } from '../../common/Checkbox'
66
import { IconButton } from '../IconButton/IconButton'
7+
import { TextItem } from './components'
78

89
type Props = {
910
items: ItemInPreview[]
@@ -177,11 +178,7 @@ export const ResponsePreview: FC<Props> = (props) => {
177178
</div>
178179
)
179180
} else {
180-
return (
181-
<div key={index} className={styles.list__text}>
182-
{item.content}
183-
</div>
184-
)
181+
return <TextItem key={index} content={item.content} />
185182
}
186183
})}
187184
</div>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
.text {
2+
color: var(--vscode-descriptionForeground);
3+
font-size: var(--font-size-12px);
4+
margin: var(--padding-6px) var(--padding-12px);
5+
background: var(--vscode-list-hoverBackground);
6+
padding: var(--padding-5px) var(--padding-7px);
7+
border-radius: var(--border-radius-8px);
8+
word-wrap: break-word;
9+
10+
> * {
11+
margin: 0;
12+
}
13+
> * + * {
14+
margin-top: 0.5em;
15+
}
16+
ul,
17+
ol {
18+
padding-left: 20px;
19+
}
20+
code {
21+
background-color: var(--vscode-textCodeBlock-background);
22+
padding: 2px 4px;
23+
border-radius: 3px;
24+
}
25+
26+
&--collapsed {
27+
max-height: 50px;
28+
overflow: hidden;
29+
position: relative;
30+
}
31+
32+
&--overflowing {
33+
cursor: pointer;
34+
&::after {
35+
content: '';
36+
position: absolute;
37+
bottom: 0;
38+
left: 0;
39+
width: 100%;
40+
height: 20px;
41+
background: linear-gradient(
42+
to bottom,
43+
transparent,
44+
var(--vscode-list-hoverBackground)
45+
);
46+
}
47+
}
48+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { FC, useEffect, useRef, useState } from 'react'
2+
import cn from 'classnames'
3+
import ReactMarkdown from 'react-markdown'
4+
import styles from './TextItem.module.scss'
5+
6+
type Props = {
7+
content: string
8+
}
9+
10+
export const TextItem: FC<Props> = ({ content }) => {
11+
const [is_expanded, set_is_expanded] = useState(false)
12+
const ref = useRef<HTMLDivElement>(null)
13+
const [is_overflowing, set_is_overflowing] = useState(false)
14+
15+
useEffect(() => {
16+
if (ref.current && !is_expanded) {
17+
set_is_overflowing(ref.current.scrollHeight > ref.current.clientHeight)
18+
} else {
19+
set_is_overflowing(false)
20+
}
21+
}, [content, is_expanded])
22+
23+
return (
24+
<div
25+
ref={ref}
26+
className={cn(styles.text, {
27+
[styles['text--collapsed']]: !is_expanded,
28+
[styles['text--overflowing']]: !is_expanded && is_overflowing
29+
})}
30+
onClick={is_overflowing ? () => set_is_expanded(true) : undefined}
31+
>
32+
<ReactMarkdown>{content}</ReactMarkdown>
33+
</div>
34+
)
35+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './TextItem'

packages/vscode/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "gemini-coder",
33
"displayName": "Code Web Chat",
44
"description": "Blazing fast AI pair programming for production-grade code. Select context as you go for game-changing accuracy and speed. (CWC)",
5-
"version": "1.503.0",
5+
"version": "1.504.0",
66
"scripts": {
77
"build": "npx vsce package --no-dependencies",
88
"vscode:prepublish": "rimraf out && npm run compile",

pnpm-lock.yaml

Lines changed: 43 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)