Skip to content

Commit e41b505

Browse files
committed
Clear text selection on blur and improve error handling for pasted file references
1 parent dcb6716 commit e41b505

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,10 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
408408
onDragOver={handle_drag_over}
409409
onDragEnd={handle_drag_end}
410410
onFocus={() => set_is_focused(true)}
411-
onBlur={() => set_is_focused(false)}
411+
onBlur={() => {
412+
set_is_focused(false)
413+
window.getSelection()?.removeAllRanges()
414+
}}
412415
className={cn(styles.input, {
413416
[styles['input--empty']]: !props.value
414417
})}

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,20 @@ export const get_highlighted_text = (params: {
9999
}
100100

101101
const line_count = content.split('\n').length
102-
const lines_text = line_count === 1 ? 'line' : 'lines'
102+
const lines_text = line_count == 1 ? 'line' : 'lines'
103+
104+
const is_error = !params.context_file_paths.includes(path)
105+
106+
const title = is_error
107+
? 'File of the selection is not in context'
108+
: content
103109

104110
return `<span class="${cn(
105111
styles['symbol'],
106-
styles['symbol--pasted-lines']
112+
styles['symbol--pasted-lines'],
113+
{ [styles['symbol--error']]: is_error }
107114
)}" data-type="pasted-lines-symbol" title="${escape_html(
108-
content
115+
title
109116
)}" data-path="${escape_html(path)}" data-content="${escape_html(
110117
content
111118
)}"${start ? ` data-start="${escape_html(start)}"` : ''}${
@@ -297,11 +304,12 @@ export const get_highlighted_text = (params: {
297304
const show_clear_button =
298305
!!params.text || (params.tabs_config && params.tabs_config.count > 1)
299306
if (show_clear_button) {
307+
const title = params.text ? 'Clear' : 'Close tab'
300308
header_html += `<span class="${cn(
301309
styles['clear-button'],
302310
'codicon',
303311
'codicon-close'
304-
)}" data-role="clear-button"></span>`
312+
)}" data-role="clear-button" title="${title}"></span>`
305313
}
306314

307315
if (header_html) {

0 commit comments

Comments
 (0)