Skip to content

Commit ac09242

Browse files
committed
Add Tasks component implementation and improve markdown parsing in clipboard parser
1 parent 126b112 commit ac09242

10 files changed

Lines changed: 328 additions & 2 deletions

File tree

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
.tasks {
2+
display: flex;
3+
flex-direction: column;
4+
}
5+
6+
.item {
7+
display: flex;
8+
padding: 8px 12px;
9+
gap: 10px;
10+
border-bottom: 1px solid var(--cwc-border-color-dimmed);
11+
position: relative;
12+
13+
&:hover {
14+
background-color: var(--vscode-list-hoverBackground);
15+
}
16+
17+
&__left {
18+
display: flex;
19+
flex-direction: column;
20+
align-items: center;
21+
gap: 8px;
22+
width: 20px;
23+
flex-shrink: 0;
24+
padding-top: 2px;
25+
}
26+
27+
&__drag_handle {
28+
display: flex;
29+
align-items: center;
30+
justify-content: center;
31+
cursor: grab;
32+
opacity: 0.5;
33+
width: 20px;
34+
height: 20px;
35+
36+
&:active {
37+
cursor: grabbing;
38+
}
39+
40+
&:hover {
41+
opacity: 1;
42+
}
43+
}
44+
45+
&__right {
46+
display: flex;
47+
flex-direction: column;
48+
flex-grow: 1;
49+
min-width: 0;
50+
gap: 2px;
51+
}
52+
53+
&__header {
54+
display: flex;
55+
justify-content: space-between;
56+
align-items: center;
57+
font-size: 11px;
58+
color: var(--cwc-text-color-dimmed);
59+
margin-bottom: 2px;
60+
}
61+
62+
&__star {
63+
cursor: pointer;
64+
&:hover {
65+
color: var(--vscode-icon-foreground);
66+
}
67+
&--active {
68+
color: var(--vscode-button-background);
69+
}
70+
}
71+
72+
&__text {
73+
white-space: pre-wrap;
74+
word-break: break-word;
75+
cursor: text;
76+
min-height: 18px;
77+
78+
&--checked {
79+
text-decoration: line-through;
80+
opacity: 0.7;
81+
}
82+
83+
&--placeholder {
84+
font-style: italic;
85+
opacity: 0.5;
86+
}
87+
}
88+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { useState } from 'react'
2+
import { Task, Tasks } from './Tasks'
3+
4+
export default {
5+
component: Tasks
6+
}
7+
8+
const initialTasks: Task[] = [
9+
{
10+
id: '1',
11+
text: 'Refactor the authentication middleware',
12+
is_checked: false,
13+
is_starred: true,
14+
created_at: Date.now() - 1000 * 60 * 5 // 5 mins ago
15+
},
16+
{
17+
id: '2',
18+
text: 'Fix bug in user profile update',
19+
is_checked: true,
20+
is_starred: false,
21+
created_at: Date.now() - 1000 * 60 * 60 * 2 // 2 hours ago
22+
},
23+
{
24+
id: '3',
25+
text: '',
26+
is_checked: false,
27+
is_starred: false,
28+
created_at: Date.now() - 1000 * 60 * 60 * 24 // 1 day ago
29+
}
30+
]
31+
32+
export const Default = () => {
33+
const [tasks, set_tasks] = useState(initialTasks)
34+
35+
const handle_change = (updated_task: Task) => {
36+
set_tasks((prev) =>
37+
prev.map((t) => (t.id === updated_task.id ? updated_task : t))
38+
)
39+
}
40+
41+
const handle_reorder = (new_tasks: Task[]) => {
42+
set_tasks(new_tasks)
43+
}
44+
45+
return (
46+
<div
47+
style={{
48+
backgroundColor: 'var(--vscode-sideBar-background)',
49+
padding: '20px'
50+
}}
51+
>
52+
<Tasks
53+
tasks={tasks}
54+
on_change={handle_change}
55+
on_reorder={handle_reorder}
56+
/>
57+
</div>
58+
)
59+
}
60+
61+
export const NoReorder = () => {
62+
const [tasks, set_tasks] = useState(initialTasks)
63+
64+
const handle_change = (updated_task: Task) => {
65+
set_tasks((prev) =>
66+
prev.map((t) => (t.id === updated_task.id ? updated_task : t))
67+
)
68+
}
69+
70+
return (
71+
<div
72+
style={{
73+
backgroundColor: 'var(--vscode-sideBar-background)',
74+
padding: '20px'
75+
}}
76+
>
77+
<Tasks tasks={tasks} on_change={handle_change} />
78+
</div>
79+
)
80+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import styles from './Tasks.module.scss'
2+
import React, { useState } from 'react'
3+
import { ReactSortable } from 'react-sortablejs'
4+
import dayjs from 'dayjs'
5+
import relativeTime from 'dayjs/plugin/relativeTime'
6+
import { Checkbox } from '../../common/Checkbox'
7+
import { Textarea } from '../../common/Textarea'
8+
import { use_periodic_re_render } from '../../../../hooks/use-periodic-re-render'
9+
import cn from 'classnames'
10+
11+
dayjs.extend(relativeTime)
12+
13+
export type Task = {
14+
id: string
15+
text: string
16+
is_checked: boolean
17+
is_starred: boolean
18+
created_at: number
19+
}
20+
21+
type Props = {
22+
tasks: Task[]
23+
on_reorder?: (tasks: Task[]) => void
24+
on_change?: (task: Task) => void
25+
}
26+
27+
export const Tasks: React.FC<Props> = ({ tasks, on_reorder, on_change }) => {
28+
use_periodic_re_render(60 * 1000)
29+
const [editing_id, set_editing_id] = useState<string | null>(null)
30+
31+
const handle_check_change = (task: Task, checked: boolean) => {
32+
on_change?.({ ...task, is_checked: checked })
33+
}
34+
35+
const handle_star_toggle = (task: Task) => {
36+
on_change?.({ ...task, is_starred: !task.is_starred })
37+
}
38+
39+
const render_item = (task: Task) => {
40+
const is_editing = editing_id === task.id
41+
42+
return (
43+
<div key={task.id} className={styles.item}>
44+
<div className={styles.item__left}>
45+
<Checkbox
46+
checked={task.is_checked}
47+
on_change={(checked) => handle_check_change(task, checked)}
48+
/>
49+
<div className={styles.item__drag_handle}>
50+
<span className="codicon codicon-gripper" />
51+
</div>
52+
</div>
53+
<div className={styles.item__right}>
54+
<div className={styles.item__header}>
55+
<span>{dayjs(task.created_at).fromNow()}</span>
56+
<span
57+
className={cn(
58+
'codicon',
59+
task.is_starred ? 'codicon-star-full' : 'codicon-star-empty',
60+
styles.item__star,
61+
{
62+
[styles['item__star--active']]: task.is_starred
63+
}
64+
)}
65+
onClick={() => handle_star_toggle(task)}
66+
title={task.is_starred ? 'Unstar' : 'Star'}
67+
/>
68+
</div>
69+
{is_editing ? (
70+
<Textarea
71+
value={task.text}
72+
on_change={(value) => on_change?.({ ...task, text: value })}
73+
autofocus
74+
on_blur={() => set_editing_id(null)}
75+
on_key_down={(e) => {
76+
if (e.key === 'Enter' && !e.shiftKey) {
77+
e.preventDefault()
78+
set_editing_id(null)
79+
}
80+
}}
81+
/>
82+
) : (
83+
<div
84+
className={cn(styles.item__text, {
85+
[styles['item__text--checked']]: task.is_checked,
86+
[styles['item__text--placeholder']]: !task.text
87+
})}
88+
onDoubleClick={() => set_editing_id(task.id)}
89+
>
90+
{task.text || 'Double click to add text...'}
91+
</div>
92+
)}
93+
</div>
94+
</div>
95+
)
96+
}
97+
98+
if (on_reorder) {
99+
return (
100+
<ReactSortable
101+
list={tasks}
102+
setList={on_reorder}
103+
handle={`.${styles.item__drag_handle}`}
104+
className={styles.tasks}
105+
animation={150}
106+
>
107+
{tasks.map(render_item)}
108+
</ReactSortable>
109+
)
110+
}
111+
112+
return <div className={styles.tasks}>{tasks.map(render_item)}</div>
113+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './Tasks'

‎packages/vscode/src/commands/apply-chat-response-command/utils/clipboard-parser/clipboard-parser.spec.ts‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,31 @@ describe('clipboard-parser', () => {
764764
})
765765
})
766766

767+
it('parses multiple markdowns', () => {
768+
const test_case = 'multiple-markdowns'
769+
const text = load_test_case_file(
770+
'standard',
771+
test_case,
772+
`${test_case}.txt`
773+
)
774+
const result = parse_response({
775+
response: text,
776+
is_single_root_folder_workspace: true
777+
})
778+
779+
expect(result).toHaveLength(2)
780+
expect(result[0]).toMatchObject({
781+
type: 'file',
782+
file_path: 'src/hello.md',
783+
content: load_test_case_file('standard', test_case, '1-file.txt')
784+
})
785+
expect(result[1]).toMatchObject({
786+
type: 'file',
787+
file_path: 'src/world.md',
788+
content: load_test_case_file('standard', test_case, '2-file.txt')
789+
})
790+
})
791+
767792
it('parses file path when it is included immediately after the opening code block backticks', () => {
768793
const test_case = 'markdown-backticks-file-path-in-one-line'
769794
const text = load_test_case_file(
@@ -987,7 +1012,11 @@ describe('clipboard-parser', () => {
9871012
describe('parse_response fallback to single file without blocks', () => {
9881013
it('parses file content when there are no markdown code blocks', () => {
9891014
const test_case = 'file-content-only'
990-
const text = load_test_case_file('standard', test_case, `${test_case}.txt`)
1015+
const text = load_test_case_file(
1016+
'standard',
1017+
test_case,
1018+
`${test_case}.txt`
1019+
)
9911020
const result = parse_response({
9921021
response: text,
9931022
is_single_root_folder_workspace: true

‎packages/vscode/src/commands/apply-chat-response-command/utils/clipboard-parser/parsers/multiple-files-parser.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,7 @@ export const parse_multiple_files = (params: {
695695
trimmed_line === '```' &&
696696
backtick_nesting_level === 1 &&
697697
(current_language === 'markdown' || current_language === 'md') &&
698+
!last_seen_file_path_was_header &&
698699
((current_content.trim() === '' &&
699700
i > 0 &&
700701
lines[i - 1].trim() !== '') ||
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
## Complexity Tracking
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("World")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
### New file: `src/hello.md`
2+
3+
```markdown
4+
## Complexity Tracking
5+
6+
```
7+
8+
### New file: `src/world.md`
9+
10+
```markdown
11+
console.log("World")
12+
```

‎packages/vscode/src/views/panel/backend/message-handlers/handle-send-prompt.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ export const handle_send_prompt = async (params: {
261261

262262
params.panel_provider.send_message({
263263
command: 'SHOW_AUTO_CLOSING_MODAL',
264-
title: 'Initialized in the connected browser'
264+
title: 'Opened in the connected browser'
265265
})
266266
}
267267

0 commit comments

Comments
 (0)