Skip to content

Commit ed41e1f

Browse files
committed
Preserve tab state using display toggles and normalize newline handling in Textarea
- when editing web configuration - typing something into previously empty system instructions and removing it, should not mark the form as dirty. And placeholder should re-appear. - on home, should not re-render tasks/notes when switching between them, also for notes, use larger divider between them and tabs: 10px, not 4 ├── apps │ └── editor │ └── src │ ├── types │ │ └── web-configuration.ts │ ├── utils │ │ └── web-configuration-format-converters.ts │ └── views │ ├── prompt │ │ ├── backend │ │ │ └── message-handlers │ │ │ └── configurations │ │ │ └── handle-update-web-configuration.ts │ │ └── frontend │ │ ├── Home │ │ │ ├── Home.module.scss │ │ │ ├── Home.tsx │ │ │ └── hooks │ │ │ ├── use-notes.ts │ │ │ └── use-tasks.ts │ │ ├── Prompt.tsx │ │ └── hooks │ │ └── use-web-configuration-editing.ts │ ├── settings │ │ ├── backend │ │ │ └── message-handlers │ │ │ └── handle-update-web-configuration.ts │ │ └── frontend │ │ ├── Settings.tsx │ │ └── hooks │ │ └── use-web-configuration-editing.ts │ └── shared │ ├── actions │ │ └── web │ │ └── update.ts │ ├── forms │ │ └── EditWebConfigurationForm │ │ └── EditWebConfigurationForm.tsx │ └── i18n │ └── translations │ └── edit-web-configuration-form.ts └── packages └── ui └── src └── components └── editor ├── common │ └── Textarea │ ├── Textarea.module.scss │ └── Textarea.tsx └── prompt-view ├── Spacer │ └── Spacer.tsx ├── Tabs │ ├── Tabs.module.scss │ └── Tabs.tsx └── Tasks ├── Tasks.module.scss └── Tasks.tsx
1 parent 9464517 commit ed41e1f

2 files changed

Lines changed: 24 additions & 11 deletions

File tree

  • apps/editor/src/views/prompt/frontend/Home
  • packages/ui/src/components/editor/common/Textarea

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ export const Home: React.FC<Props> = (props) => {
257257
value={notes_for_root}
258258
on_change={(v) => handle_note_change(active_root, v)}
259259
placeholder={t('home.notes.placeholder')}
260-
min_rows={10}
260+
min_rows={4}
261261
blur_on_enter={false}
262262
/>
263263
</div>
@@ -308,9 +308,8 @@ export const Home: React.FC<Props> = (props) => {
308308
}
309309
/>
310310

311-
<UiSpacer height={4} />
312-
313-
{active_tab === 'tasks' && (
311+
<div style={{ display: active_tab === 'tasks' ? 'block' : 'none' }}>
312+
<UiSpacer height={4} />
314313
<div className={styles.inner__tasks}>
315314
<UiTasks
316315
tasks={tasks[active_root] || []}
@@ -338,9 +337,12 @@ export const Home: React.FC<Props> = (props) => {
338337
}}
339338
/>
340339
</div>
341-
)}
340+
</div>
342341

343-
{active_tab === 'notes' && notes_section}
342+
<div style={{ display: active_tab === 'notes' ? 'block' : 'none' }}>
343+
<UiSpacer height={10} />
344+
{notes_section}
345+
</div>
344346
</>
345347
)
346348

‎packages/ui/src/components/editor/common/Textarea/Textarea.tsx‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,12 @@ export const Textarea = React.forwardRef<HTMLDivElement, Props>(
6363
)
6464

6565
React.useEffect(() => {
66+
if (!internal_ref.current) return
67+
68+
const current_inner_text = internal_ref.current.innerText || ''
6669
if (
67-
internal_ref.current &&
68-
internal_ref.current.innerText !== props.value
70+
current_inner_text !== props.value &&
71+
!(current_inner_text === '\n' && !props.value)
6972
) {
7073
internal_ref.current.innerText = props.value || ''
7174
}
@@ -94,7 +97,11 @@ export const Textarea = React.forwardRef<HTMLDivElement, Props>(
9497
}
9598

9699
const handle_input = (e: React.FormEvent<HTMLDivElement>) => {
97-
update_value(e.currentTarget.innerText || '')
100+
let new_value = e.currentTarget.innerText || ''
101+
if (new_value === '\n') {
102+
new_value = ''
103+
}
104+
update_value(new_value)
98105
}
99106

100107
const handle_key_down = (e: React.KeyboardEvent<HTMLDivElement>) => {
@@ -168,7 +175,9 @@ export const Textarea = React.forwardRef<HTMLDivElement, Props>(
168175
range.collapse(false)
169176
selection.removeAllRanges()
170177
selection.addRange(range)
171-
update_value(e.currentTarget.innerText || '')
178+
let new_value = e.currentTarget.innerText || ''
179+
if (new_value === '\n') new_value = ''
180+
update_value(new_value)
172181
}
173182
}
174183
}
@@ -188,7 +197,9 @@ export const Textarea = React.forwardRef<HTMLDivElement, Props>(
188197
range.collapse(false)
189198
selection.removeAllRanges()
190199
selection.addRange(range)
191-
update_value(e.currentTarget.innerText || '')
200+
let new_value = e.currentTarget.innerText || ''
201+
if (new_value === '\n') new_value = ''
202+
update_value(new_value)
192203
}
193204
}
194205
}

0 commit comments

Comments
 (0)