Skip to content

Commit 8e70789

Browse files
committed
Refactor context switching logic by extracting return_home_and_switch_to_edit_context into a separate handler_
- when accepting 'relevant files' use [Fragment], not [Fragment] - handle [Fragment] in a handler
1 parent e6d18eb commit 8e70789

4 files changed

Lines changed: 38 additions & 5 deletions

File tree

‎apps/editor/src/commands/apply-chat-response-command/response-processor.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ export const process_chat_response = async (
266266

267267
if (was_frf) {
268268
shared_state.switch_context_state(true)
269-
await panel_provider.return_home_and_switch_to_edit_context()
269+
await panel_provider.switch_to_edit_context()
270270
}
271271

272272
panel_provider.send_message({
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { MODE } from '../../types/main-view-mode'
2+
import { PanelProvider } from '../panel-provider'
3+
import { API_MODE_STATE_KEY, WEB_MODE_STATE_KEY } from '@/constants/state-keys'
4+
5+
export const handle_return_home_and_switch_to_edit_context = async (
6+
panel_provider: PanelProvider
7+
) => {
8+
panel_provider.send_message({ command: 'RETURN_HOME' })
9+
if (panel_provider.mode == MODE.WEB) {
10+
panel_provider.web_prompt_type = 'edit-context'
11+
await panel_provider.context.workspaceState.update(
12+
WEB_MODE_STATE_KEY,
13+
'edit-context'
14+
)
15+
panel_provider.send_message({
16+
command: 'WEB_PROMPT_TYPE',
17+
prompt_type: 'edit-context'
18+
})
19+
} else {
20+
panel_provider.api_prompt_type = 'edit-context'
21+
await panel_provider.context.workspaceState.update(
22+
API_MODE_STATE_KEY,
23+
'edit-context'
24+
)
25+
panel_provider.send_message({
26+
command: 'API_PROMPT_TYPE',
27+
prompt_type: 'edit-context'
28+
})
29+
}
30+
panel_provider.update_providers_shrink_mode()
31+
panel_provider.update_providers_context_state()
32+
}

‎apps/editor/src/views/panel/backend/message-handlers/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,4 @@ export * from './handle-delete-configuration'
7474
export * from './handle-get-find-relevant-files-shrink-source-code'
7575
export * from './handle-save-find-relevant-files-shrink-source-code'
7676
export * from './handle-update-last-used-preset-or-group'
77+
export * from './handle-return-home-and-switch-to-edit-context'

‎apps/editor/src/views/panel/backend/panel-provider.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ import {
9595
handle_delete_configuration,
9696
handle_update_last_used_preset_or_group,
9797
handle_get_find_relevant_files_shrink_source_code,
98-
handle_save_find_relevant_files_shrink_source_code
98+
handle_save_find_relevant_files_shrink_source_code,
99+
handle_return_home_and_switch_to_edit_context
99100
} from './message-handlers'
100101
import { SelectionState } from '../types/messages'
101102
import {
@@ -274,8 +275,7 @@ export class PanelProvider implements vscode.WebviewViewProvider {
274275
SharedFileState.get_instance().switch_context_state(is_find_relevant_files)
275276
}
276277

277-
public async return_home_and_switch_to_edit_context() {
278-
this.send_message({ command: 'RETURN_HOME' })
278+
public async switch_to_edit_context() {
279279
if (this.mode == MODE.WEB) {
280280
this.web_prompt_type = 'edit-context'
281281
await this.context.workspaceState.update(
@@ -1007,7 +1007,7 @@ export class PanelProvider implements vscode.WebviewViewProvider {
10071007
} else if (message.command == 'GET_SETUP_PROGRESS') {
10081008
await this.send_setup_progress()
10091009
} else if (message.command == 'REQUEST_RETURN_HOME') {
1010-
await this.return_home_and_switch_to_edit_context()
1010+
await handle_return_home_and_switch_to_edit_context(this)
10111011
} else if (
10121012
message.command == 'GET_FIND_RELEVANT_FILES_SHRINK_SOURCE_CODE'
10131013
) {

0 commit comments

Comments
 (0)