Skip to content

Commit d70149b

Browse files
committed
Send task content with SAVE_COMPLETED_TASKS and simplify completed task list interactions
- don't auto-close completed tasks when typing instructions - consider latest edits: [Changes], task_text is not necessary, can continue reading instructions - uconsider latest edits: [Changes], 'undo' should restore last task into instructions - completed tasks should not serve as toggler to close them - allow text selection etc. Close only by clicking on the header 'X completed tasks' ├── apps │ └── editor │ └── src │ ├── constants │ │ └── state-keys.ts │ └── views │ └── prompt │ ├── backend │ │ ├── message-handlers │ │ │ ├── handle-clear-completed-tasks.ts │ │ │ ├── handle-get-completed-tasks.ts │ │ │ ├── handle-get-instructions.ts │ │ │ ├── handle-save-completed-tasks.ts │ │ │ ├── handle-save-instructions.ts │ │ │ └── index.ts │ │ └── prompt-view-provider.ts │ ├── frontend │ │ ├── Main │ │ │ ├── Main.tsx │ │ │ └── MainView │ │ │ ├── MainView.tsx │ │ │ └── index.ts │ │ ├── Prompt.tsx │ │ └── hooks │ │ └── use-prompt │ │ ├── hooks │ │ │ └── use-instructions.ts │ │ └── use-prompt.ts │ └── types │ └── messages.ts └── packages └── ui └── src └── components └── editor └── common └── prompts ├── PromptField │ ├── PromptField.module.scss │ ├── PromptField.stories.tsx │ ├── PromptField.tsx │ ├── components │ │ ├── CompletedTasks │ │ │ ├── CompletedTasks.module.scss │ │ │ ├── CompletedTasks.tsx │ │ │ └── index.ts │ │ ├── Footer │ │ │ ├── Footer.module.scss │ │ │ ├── Footer.tsx │ │ │ └── index.ts │ │ └── Tabs │ │ ├── Tabs.module.scss │ │ ├── Tabs.tsx │ │ └── index.ts │ ├── hooks │ │ ├── use-drag-drop.ts │ │ ├── use-dropdown.ts │ │ ├── use-ghost-text.ts │ │ ├── use-handlers │ │ │ ├── handle-copy.ts │ │ │ ├── handle-cut.ts │ │ │ ├── handle-input-change.ts │ │ │ ├── handle-input-click.ts │ │ │ ├── handle-key-down.ts │ │ │ ├── handle-paste.ts │ │ │ ├── handle-submit.ts │ │ │ ├── index.ts │ │ │ ├── types.ts │ │ │ ├── use-handlers.ts │ │ │ └── utils.ts │ │ └── use-keyboard-shortcuts.ts │ └── index.ts ├── Template │ ├── Template.module.scss │ ├── Template.tsx │ └── index.ts └── shared ├── hooks │ └── use-undo-redo.ts └── symbols ├── caret.ts ├── get-highlighted-text.tsx ├── index.ts ├── position-mapping.ts ├── prompt-symbols.module.scss ├── reconstruct-raw-value.ts └── use-symbol-deletion.ts
1 parent 383ef64 commit d70149b

7 files changed

Lines changed: 37 additions & 52 deletions

File tree

‎apps/editor/src/views/prompt/backend/message-handlers/handle-save-completed-tasks.ts‎

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import {
66
} from '@/constants/state-keys'
77
import * as vscode from 'vscode'
88
import { t } from '@/i18n'
9+
import { SaveCompletedTasksMessage } from '@/views/prompt/types/messages'
910

1011
export const handle_save_completed_tasks = async (
11-
prompt_view_provider: PromptViewProvider
12+
prompt_view_provider: PromptViewProvider,
13+
message: SaveCompletedTasksMessage
1214
) => {
13-
const instruction = prompt_view_provider.current_instructions.trim()
15+
const instruction = message.task
1416
const prompt_type = prompt_view_provider.prompt_type
1517
if (instruction) {
1618
prompt_view_provider.completed_tasks = [
@@ -26,29 +28,6 @@ export const handle_save_completed_tasks = async (
2628
completed_tasks: prompt_view_provider.completed_tasks
2729
})
2830

29-
const original_instructions = prompt_view_provider.current_instructions
30-
const active_state = prompt_view_provider.active_instructions_state
31-
32-
active_state.instructions[active_state.active_index] = ''
33-
const state_key =
34-
prompt_type === 'ask'
35-
? INSTRUCTIONS_ASK_STATE_KEY
36-
: INSTRUCTIONS_EDIT_FILES_STATE_KEY
37-
38-
await prompt_view_provider.extension_context.workspaceState.update(
39-
state_key,
40-
active_state
41-
)
42-
43-
prompt_view_provider.send_message({
44-
command: 'INSTRUCTIONS',
45-
ask_about_context: prompt_view_provider.ask_about_context_instructions,
46-
edit_files: prompt_view_provider.edit_files_instructions,
47-
caret_position: 0
48-
})
49-
prompt_view_provider.caret_position = 0
50-
prompt_view_provider.send_token_count()
51-
5231
const selection = await vscode.window.showInformationMessage(
5332
t('views.prompt.handlers.handle-save-completed-tasks.task-completed'),
5433
t('common.undo')
@@ -66,8 +45,13 @@ export const handle_save_completed_tasks = async (
6645
completed_tasks: prompt_view_provider.completed_tasks
6746
})
6847

69-
active_state.instructions[active_state.active_index] =
70-
original_instructions
48+
const active_state = prompt_view_provider.active_instructions_state
49+
active_state.instructions[active_state.active_index] = instruction
50+
51+
const state_key =
52+
prompt_type === 'ask'
53+
? INSTRUCTIONS_ASK_STATE_KEY
54+
: INSTRUCTIONS_EDIT_FILES_STATE_KEY
7155

7256
await prompt_view_provider.extension_context.workspaceState.update(
7357
state_key,
@@ -78,9 +62,9 @@ export const handle_save_completed_tasks = async (
7862
command: 'INSTRUCTIONS',
7963
ask_about_context: prompt_view_provider.ask_about_context_instructions,
8064
edit_files: prompt_view_provider.edit_files_instructions,
81-
caret_position: original_instructions.length
65+
caret_position: instruction.length
8266
})
83-
prompt_view_provider.caret_position = original_instructions.length
67+
prompt_view_provider.caret_position = instruction.length
8468
prompt_view_provider.send_token_count()
8569
prompt_view_provider.send_message({
8670
command: 'FOCUS_PROMPT_FIELD'

‎apps/editor/src/views/prompt/backend/prompt-view-provider.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ export class PromptViewProvider implements vscode.WebviewViewProvider {
836836
} else if (message.command === 'GET_COMPLETED_TASKS') {
837837
handlers.handle_get_completed_tasks(this)
838838
} else if (message.command === 'SAVE_COMPLETED_TASKS') {
839-
await handlers.handle_save_completed_tasks(this)
839+
await handlers.handle_save_completed_tasks(this, message)
840840
} else if (message.command === 'CLEAR_COMPLETED_TASKS') {
841841
await handlers.handle_clear_completed_tasks(this)
842842
} else if (message.command === 'UPDATE_EXTENSION') {

‎apps/editor/src/views/prompt/frontend/Main/Main.tsx‎

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -567,18 +567,6 @@ export const Main: React.FC<Props> = (props) => {
567567
})
568568
}
569569

570-
const handle_task_completed = () => {
571-
post_message(props.vscode, {
572-
command: 'SAVE_COMPLETED_TASKS'
573-
})
574-
}
575-
576-
const handle_clear_completed_tasks = () => {
577-
post_message(props.vscode, {
578-
command: 'CLEAR_COMPLETED_TASKS'
579-
})
580-
}
581-
582570
const handle_clear_context = () => {
583571
post_message(props.vscode, {
584572
command: 'EXECUTE_COMMAND',
@@ -597,6 +585,27 @@ export const Main: React.FC<Props> = (props) => {
597585
props.set_instructions(value, current_prompt_type)
598586
}
599587

588+
const handle_task_completed = () => {
589+
const instruction = get_current_instructions().trim()
590+
591+
if (instruction) {
592+
post_message(props.vscode, {
593+
command: 'SAVE_COMPLETED_TASKS',
594+
task: instruction
595+
})
596+
set_completed_tasks((prev) => [...prev, instruction])
597+
set_instructions('')
598+
set_caret_position_to_set(0)
599+
}
600+
}
601+
602+
const handle_clear_completed_tasks = () => {
603+
set_completed_tasks([])
604+
post_message(props.vscode, {
605+
command: 'CLEAR_COMPLETED_TASKS'
606+
})
607+
}
608+
600609
let current_history: string[] | undefined
601610
if (current_prompt_type === 'ask') {
602611
current_history = ask_about_files_history

‎apps/editor/src/views/prompt/types/messages.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@ export interface GetCompletedTasksMessage extends BaseMessage {
641641

642642
export interface SaveCompletedTasksMessage extends BaseMessage {
643643
command: 'SAVE_COMPLETED_TASKS'
644+
task: string
644645
}
645646

646647
export interface ClearCompletedTasksMessage extends BaseMessage {

‎packages/ui/src/components/editor/common/prompts/PromptField/PromptField.tsx‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,6 @@ export const PromptField: React.FC<PromptField.Props> = (props) => {
413413
onInput={(e) => {
414414
set_should_show_ghost_text(true)
415415
handle_input_change(e)
416-
set_is_completed_tasks_expanded(false)
417416
}}
418417
onKeyDown={(e) => {
419418
if (

‎packages/ui/src/components/editor/common/prompts/PromptField/components/CompletedTasks/CompletedTasks.module.scss‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@
5050
}
5151
}
5252

53-
.tasks-list {
54-
cursor: pointer;
55-
}
56-
5753
.completed-task {
5854
padding: 2px 7px;
5955
opacity: var(--dimmed-opacity);
@@ -67,6 +63,5 @@
6763

6864
&__text {
6965
display: inline;
70-
pointer-events: none;
7166
}
7267
}

‎packages/ui/src/components/editor/common/prompts/PromptField/components/CompletedTasks/CompletedTasks.tsx‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,7 @@ export const CompletedTasks: React.FC<Props> = ({
102102
)}
103103
</div>
104104
{is_expanded && (
105-
<div
106-
className={styles['tasks-list']}
107-
onClick={() => set_is_expanded(false)}
108-
>
105+
<div>
109106
{[...tasks].reverse().map((task, idx) => (
110107
<CompletedTask
111108
key={idx}

0 commit comments

Comments
 (0)