Skip to content

Commit a4c7de0

Browse files
committed
Refactor clear button to render inline with text instead of absolute positioning
1 parent 0ea8fd5 commit a4c7de0

4 files changed

Lines changed: 23 additions & 22 deletions

File tree

‎packages/ui/src/components/editor/panel/PromptField/PromptField.module.scss‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.container {
2-
--padding: 5px 22px 5px 7px;
2+
--padding: 5px 7px;
33
position: relative;
44

55
&__inner {
@@ -112,19 +112,14 @@
112112
}
113113

114114
.clear-button {
115-
position: absolute;
116-
top: 0;
117-
right: 0;
118-
z-index: 2;
115+
float: right;
116+
position: relative;
119117
width: 18px;
120-
display: flex;
121-
align-items: center;
122-
justify-content: center;
123118
cursor: pointer;
124119
color: var(--vscode-icon-foreground);
125120
opacity: var(--dimmed-opacity);
126-
padding-bottom: 6px;
127-
line-height: 0;
121+
transform: translate(5px, -3px);
122+
padding-bottom: 2px;
128123

129124
&::before {
130125
font-size: 13px !important;

‎packages/ui/src/components/editor/panel/PromptField/PromptField.tsx‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -355,17 +355,6 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
355355
/>
356356
)}
357357
<div className={styles['input-wrapper']}>
358-
{props.value && (
359-
<button
360-
className={cn(styles['clear-button'], 'codicon', 'codicon-close')}
361-
onClick={() => {
362-
set_should_show_ghost_text(false)
363-
handle_clear()
364-
input_ref.current?.focus()
365-
}}
366-
title="Clear"
367-
/>
368-
)}
369358
<div
370359
ref={input_ref}
371360
contentEditable={true}

‎packages/ui/src/components/editor/panel/PromptField/hooks/use-handlers.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,7 @@ export const use_handlers = (
662662
const target = e.target as HTMLElement
663663
const icon_element = target.closest('[data-role="symbol-icon"]')
664664
const text_element = target.closest('[data-role="symbol-text"]')
665+
const clear_button = target.closest('[data-role="clear-button"]')
665666

666667
if (icon_element) {
667668
e.preventDefault()
@@ -745,6 +746,13 @@ export const use_handlers = (
745746
}
746747
}
747748

749+
if (input_ref.current) {
750+
input_ref.current.focus()
751+
}
752+
} else if (clear_button) {
753+
e.preventDefault()
754+
e.stopPropagation()
755+
handle_clear()
748756
if (input_ref.current) {
749757
input_ref.current.focus()
750758
}

‎packages/ui/src/components/editor/panel/PromptField/utils/get-highlighted-text.tsx‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export const get_highlighted_text = (params: {
7474
)
7575
const parts = params.text.split(regex)
7676

77-
const result = parts
77+
let result = parts
7878
.map((part) => {
7979
const fragment_match = part.match(
8080
/^<fragment path="([^"]+)"(?: start="([^"]+)")?(?: end="([^"]+)")?>([\s\S]*?)<\/fragment>$/
@@ -265,6 +265,15 @@ export const get_highlighted_text = (params: {
265265
})
266266
.join('')
267267

268+
if (params.text) {
269+
result =
270+
`<span class="${cn(
271+
styles['clear-button'],
272+
'codicon',
273+
'codicon-close'
274+
)}" contenteditable="false" data-role="clear-button"></span>` + result
275+
}
276+
268277
if (params.text.endsWith('\n')) {
269278
return result + '<br data-role="trailing-break">'
270279
}

0 commit comments

Comments
 (0)