Skip to content

Commit 891d482

Browse files
committed
Add mode switch control to prompt field, use keycap wrapper across various components
- should accept props: on_mode_change, mode:string. render it in place where we previously had 'invocation count' [Commit] - fix prompt field stories - move `apps/editor/src/views/prompt/types/main-view-mode.ts` to `packages/shared/src/types` as mode.ts - `packages/ui/src/components/editor/common/prompts/PromptField/PromptField.tsx` should use `packages/shared/src/types/mode.ts` type - 'mode switch' should use Tooltip, add appropriate translation - rename tooltip 'change mode' to 'mode' - from header, remove keycap over 'back' button, remove changing mode with shortcuts alt+1/alt+2 - show keycap 'esc' over 'mode' in prompt type (when alt is pressed) and handle mode toggling (alt+esc) - the 'esc' keycap should be rendered on top (stacked), not replace the mode (inspire by `packages/ui/src/components/editor/prompt/PromptTypeButton/PromptTypeButton.tsx`) - in prompt field, 'esc' is not properly shown on mode (as stack), but slightly above, move it back down - rename 'shortcut' to keycap - prompt field should use keycap wrapper - prompt field should use keycap wrappers for each prompt type char ├── apps │ └── editor │ └── src │ └── views │ └── prompt │ ├── backend │ │ ├── message-handlers │ │ │ ├── handle-autofill.ts │ │ │ ├── handle-save-edit-format.ts │ │ │ ├── handle-select-edit-format.ts │ │ │ └── handle-template-quick-pick.ts │ │ └── prompt-view-provider.ts │ ├── frontend │ │ ├── Home │ │ │ ├── Home.tsx │ │ │ └── hooks │ │ │ ├── use-has-scrolled-past-mode-button.ts │ │ │ ├── use-keyboard-shortcuts.ts │ │ │ └── use-tasks.ts │ │ ├── Main │ │ │ ├── Main.tsx │ │ │ └── MainView │ │ │ ├── MainView.module.scss │ │ │ ├── MainView.tsx │ │ │ ├── components │ │ │ │ └── Header │ │ │ │ ├── Header.module.scss │ │ │ │ ├── Header.tsx │ │ │ │ ├── hooks │ │ │ │ │ └── use-keyboard-shortcuts.ts │ │ │ │ └── index.ts │ │ │ ├── hooks │ │ │ │ ├── use-invocation-counts.ts │ │ │ │ ├── use-last-choice-tooltip.ts │ │ │ │ └── use-re-render-on-interval.ts │ │ │ ├── index.ts │ │ │ └── prompt-type-labels.ts │ │ ├── Prompt.tsx │ │ ├── hooks │ │ │ └── use-prompt │ │ │ ├── hooks │ │ │ │ └── use-instructions.ts │ │ │ └── use-prompt.ts │ │ └── i18n │ │ └── translations │ │ └── prompt-field.ts │ └── types │ └── messages.ts └── packages ├── shared │ └── src │ └── types │ ├── edit-format.ts │ ├── file-in-preview.ts │ ├── mode.ts │ ├── prompt-types.ts │ ├── response-history-item.ts │ ├── task.ts │ ├── web-configuration.ts │ └── websocket-message.ts └── ui └── src └── components └── editor ├── common │ └── prompts │ ├── PromptField │ │ ├── PromptField.module.scss │ │ ├── PromptField.stories.tsx │ │ ├── PromptField.tsx │ │ ├── components │ │ │ ├── Tooltip.module.scss │ │ │ ├── Tooltip.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 │ └── symbols │ ├── caret.ts │ ├── get-highlighted-text.tsx │ ├── index.ts │ ├── position-mapping.ts │ ├── prompt-symbols.module.scss │ ├── reconstruct-raw-value.ts │ └── use-symbol-deletion.ts └── prompt ├── KeycapWrapper │ ├── KeycapWrapper.module.scss │ ├── KeycapWrapper.stories.tsx │ ├── KeycapWrapper.tsx │ └── index.ts ├── ModeButton │ ├── ModeButton.module.scss │ └── ModeButton.tsx └── PromptTypeButton ├── PromptTypeButton.module.scss ├── PromptTypeButton.stories.tsx ├── PromptTypeButton.tsx └── index.ts
1 parent 0505902 commit 891d482

25 files changed

Lines changed: 338 additions & 291 deletions

File tree

‎apps/editor/src/views/prompt/backend/message-handlers/handle-autofill.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as vscode from 'vscode'
33
import { FilesCollector } from '@/utils/files-collector'
44
import { get_last_used_web_configuration_key } from '@/constants/state-keys'
55
import { ConfigWebConfigurationFormat } from '@/utils/web-configuration-format-converters'
6-
import { MODE } from '@/views/prompt/types/main-view-mode'
6+
import { MODE } from '@shared/types/mode'
77
import { WebPromptType } from '@shared/types/prompt-types'
88
import { CHATBOTS } from '@shared/constants/chatbots'
99
import { dictionary } from '@shared/constants/dictionary'

‎apps/editor/src/views/prompt/backend/message-handlers/handle-save-edit-format.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as vscode from 'vscode'
22
import { get_edit_format_state_key } from '@/constants/state-keys'
33
import { PromptViewProvider } from '@/views/prompt/backend/prompt-view-provider'
44
import { SaveEditFormatMessage } from '@/views/prompt/types/messages'
5-
import { MODE } from '@/views/prompt/types/main-view-mode'
5+
import { MODE } from '@shared/types/mode'
66

77
export const handle_save_edit_format = async (
88
prompt_view_provider: PromptViewProvider,

‎apps/editor/src/views/prompt/backend/message-handlers/handle-select-edit-format.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { PromptViewProvider } from '@/views/prompt/backend/prompt-view-provider'
44
import { SelectEditFormatMessage } from '@/views/prompt/types/messages'
55
import { EditFormat } from '@shared/types/edit-format'
66
import { t } from '@/i18n'
7-
import { MODE } from '@/views/prompt/types/main-view-mode'
7+
import { MODE } from '@shared/types/mode'
88

99
export const handle_select_edit_format = async (
1010
prompt_view_provider: PromptViewProvider,

‎apps/editor/src/views/prompt/backend/message-handlers/handle-template-quick-pick.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from 'vscode'
22
import { PromptViewProvider } from '@/views/prompt/backend/prompt-view-provider'
3-
import { MODE } from '@/views/prompt/types/main-view-mode'
3+
import { MODE } from '@shared/types/mode'
44
import { get_last_used_template_key } from '@/constants/state-keys'
55
import { ApiPromptType, WebPromptType } from '@shared/types/prompt-types'
66
import { t } from '@/i18n'

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ import {
104104
ConfigWebConfigurationFormat
105105
} from '@/utils/web-configuration-format-converters'
106106
import { CHATBOTS } from '@shared/constants/chatbots'
107-
import { MODE, Mode } from '../types/main-view-mode'
107+
import { MODE, Mode } from '@shared/types/mode'
108108
import { ApiPromptType, WebPromptType } from '@shared/types/prompt-types'
109109
import { Logger } from '@shared/utils/logger'
110110
import { ResponseHistoryItem } from '@shared/types/response-history-item'

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { Tasks as UiTasks } from '@ui/components/editor/prompt/Tasks'
1717
import { use_tasks } from './hooks/use-tasks'
1818
import { use_has_scrolled_past_mode_button } from './hooks/use-has-scrolled-past-mode-button'
1919
import { use_compacting } from '@shared/hooks'
20-
import { MODE } from '@/views/prompt/types/main-view-mode'
20+
import { MODE } from '@shared/types/mode'
2121
import { use_keyboard_shortcuts } from './hooks/use-keyboard-shortcuts'
2222

2323
type Props = {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useEffect, useState } from 'react'
22
import { MainView } from './MainView'
33
import { WebConfiguration } from '@shared/types/web-configuration'
44
import { EditFormat } from '@shared/types/edit-format'
5-
import { MODE, Mode } from '@/views/prompt/types/main-view-mode'
5+
import { MODE, Mode } from '@shared/types/mode'
66
import { ApiPromptType, WebPromptType } from '@shared/types/prompt-types'
77
import {
88
BackendMessage,

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { WebConfiguration } from '@shared/types/web-configuration'
66
import { Responses as UiResponses } from '@ui/components/editor/prompt/Responses'
77
import { ResponseHistoryItem } from '@shared/types/response-history-item'
88
import { EditFormat } from '@shared/types/edit-format'
9-
import { MODE, Mode } from '@/views/prompt/types/main-view-mode'
9+
import { MODE, Mode } from '@shared/types/mode'
1010
import { ApiPromptType, WebPromptType } from '@shared/types/prompt-types'
1111
import { Scrollable as UiScrollable } from '@ui/components/editor/common/Scrollable'
1212
import { BrowserExtensionMessage as UiBrowserExtensionMessage } from '@ui/components/editor/prompt/BrowserExtensionMessage'
@@ -235,7 +235,6 @@ export const MainView: React.FC<Props> = (props) => {
235235
<>
236236
<Header
237237
mode={props.mode}
238-
on_mode_change={props.on_mode_change}
239238
on_show_home={props.on_show_home}
240239
web_prompt_type={props.web_prompt_type}
241240
on_web_prompt_type_change={props.on_web_prompt_type_change}
@@ -310,6 +309,8 @@ export const MainView: React.FC<Props> = (props) => {
310309
on_pasted_lines_click={props.on_pasted_lines_click}
311310
on_open_url={props.on_open_url}
312311
on_open_website={props.on_open_website}
312+
mode={props.mode}
313+
on_mode_change={(mode) => props.on_mode_change(mode)}
313314
on_paste_image={props.on_paste_image}
314315
on_open_image={props.on_open_image}
315316
on_paste_long_text={props.on_paste_long_text}
@@ -351,7 +352,8 @@ export const MainView: React.FC<Props> = (props) => {
351352
copy_prompt: t('prompt-field.action.copy-prompt'),
352353
more_actions: t('prompt-field.action.more-actions'),
353354
send: t('prompt-field.action.send'),
354-
tokens_in_context: t('prompt-field.tokens-in-context')
355+
tokens_in_context: t('prompt-field.tokens-in-context'),
356+
mode: t('prompt-field.mode')
355357
}}
356358
/>
357359
</div>

‎apps/editor/src/views/prompt/frontend/Main/MainView/components/Header/Header.tsx‎

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MODE, Mode } from '@/views/prompt/types/main-view-mode'
1+
import { MODE, Mode } from '@shared/types/mode'
22
import { use_compacting } from '@shared/hooks'
33
import { ApiPromptType, WebPromptType } from '@shared/types/prompt-types'
44
import { PromptTypeButton as UiPromptTypeButton } from '@ui/components/editor/prompt/PromptTypeButton'
@@ -14,7 +14,6 @@ import { use_translation } from '@/views/prompt/frontend/i18n/use-translation'
1414

1515
type Props = {
1616
mode: Mode
17-
on_mode_change: (mode: Mode) => void
1817
on_show_home: () => void
1918
web_prompt_type: WebPromptType
2019
api_prompt_type: ApiPromptType
@@ -29,7 +28,6 @@ export const Header: React.FC<Props> = (props) => {
2928

3029
const { is_alt_pressed } = use_keyboard_shortcuts({
3130
mode: props.mode,
32-
on_mode_change: props.on_mode_change,
3331
on_web_prompt_type_change: props.on_web_prompt_type_change,
3432
on_api_prompt_type_change: props.on_api_prompt_type_change,
3533
on_show_home: props.on_show_home,
@@ -39,17 +37,11 @@ export const Header: React.FC<Props> = (props) => {
3937
return (
4038
<div className={styles.header} ref={container_ref}>
4139
<div className={styles.header__left}>
42-
<UiKeycapWrapper
43-
char={
44-
is_alt_pressed ? (props.mode == MODE.API ? '1' : '2') : undefined
45-
}
46-
>
47-
<UiIconButton
48-
codicon_icon="chevron-left"
49-
on_click={props.on_show_home}
50-
title={`${t('header.return')} (Esc)`}
51-
/>
52-
</UiKeycapWrapper>
40+
<UiIconButton
41+
codicon_icon="chevron-left"
42+
on_click={props.on_show_home}
43+
title={`${t('header.return')} (Esc)`}
44+
/>
5345
{props.mode == MODE.WEB && (
5446
<>
5547
<UiKeycapWrapper char={is_alt_pressed ? 'E' : undefined}>

‎apps/editor/src/views/prompt/frontend/Main/MainView/components/Header/hooks/use-keyboard-shortcuts.ts‎

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { useEffect, useState, useRef } from 'react'
2-
import { MODE, Mode } from '@/views/prompt/types/main-view-mode'
2+
import { MODE, Mode } from '@shared/types/mode'
33
import { ApiPromptType, WebPromptType } from '@shared/types/prompt-types'
44

55
export const use_keyboard_shortcuts = (params: {
66
mode: Mode
7-
on_mode_change: (mode: Mode) => void
87
on_web_prompt_type_change: (prompt_type: WebPromptType) => void
98
on_api_prompt_type_change: (prompt_type: ApiPromptType) => void
109
on_show_home: () => void
@@ -116,16 +115,6 @@ export const use_keyboard_shortcuts = (params: {
116115
params.on_web_prompt_type_change('ask-about-files')
117116
return
118117
}
119-
120-
if (event.code == 'Digit1' && params.mode == MODE.API) {
121-
event.preventDefault()
122-
params.on_mode_change(MODE.WEB)
123-
}
124-
125-
if (event.code == 'Digit2' && params.mode == MODE.WEB) {
126-
event.preventDefault()
127-
params.on_mode_change(MODE.API)
128-
}
129118
}
130119

131120
window.addEventListener('keydown', handle_key_down)
@@ -135,7 +124,6 @@ export const use_keyboard_shortcuts = (params: {
135124
}
136125
}, [
137126
params.mode,
138-
params.on_mode_change,
139127
params.on_web_prompt_type_change,
140128
params.on_api_prompt_type_change,
141129
params.is_disabled

0 commit comments

Comments
 (0)