Skip to content

Commit c5d5a1e

Browse files
committed
Normalize comparison operators across the repository and refine ghost text behavior in the prompt field
1 parent 8d1f97f commit c5d5a1e

51 files changed

Lines changed: 177 additions & 137 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎packages/browser/src/background/message-handler.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ const handle_get_tab_data = async (
156156
let html = ''
157157

158158
// (Firefox uses browserAction, Chrome uses action)
159-
const is_firefox = typeof browser.browserAction !== 'undefined'
159+
const is_firefox = typeof browser.browserAction != 'undefined'
160160

161161
if (is_firefox && tab.id) {
162162
// Firefox: Use the older tabs.executeScript API (MV2 style)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Message } from '@/types/messages'
22

33
export function is_message(obj: any): obj is Message {
4-
return obj && typeof obj.action === 'string'
4+
return obj && typeof obj.action == 'string'
55
}

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

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,23 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
344344
handle_input_change(e)
345345
}}
346346
onKeyDown={(e) => {
347-
set_should_show_ghost_text(true)
347+
if (e.key == 'ArrowRight') {
348+
set_should_show_ghost_text(false)
349+
const ghost_text_node = input_ref.current?.querySelector(
350+
'span[data-type="ghost-text"]'
351+
)
352+
if (ghost_text_node && !e.ctrlKey && !e.altKey && !e.metaKey) {
353+
ghost_text_node.remove()
354+
e.preventDefault()
355+
const selection = window.getSelection()
356+
if (selection) {
357+
const type = e.shiftKey ? 'extend' : 'move'
358+
selection.modify(type, 'forward', 'character')
359+
}
360+
}
361+
} else {
362+
set_should_show_ghost_text(true)
363+
}
348364
handle_key_down(e)
349365
}}
350366
onCopy={handle_copy}
@@ -432,10 +448,10 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
432448
{(['whole', 'truncated', 'before-after', 'diff'] as const).map(
433449
(format, index) => {
434450
const is_compact =
435-
(format === 'before-after' && compact_step >= 1) ||
436-
(format === 'truncated' && compact_step >= 2) ||
437-
(format === 'whole' && compact_step >= 3) ||
438-
(format === 'diff' && compact_step >= 4)
451+
(format == 'before-after' && compact_step >= 1) ||
452+
(format == 'truncated' && compact_step >= 2) ||
453+
(format == 'whole' && compact_step >= 3) ||
454+
(format == 'diff' && compact_step >= 4)
439455

440456
const button_text = is_compact
441457
? format == 'before-after'
@@ -449,10 +465,10 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
449465
const should_underline = is_alt_pressed && !is_selected
450466

451467
let ref = null
452-
if (format === 'whole') ref = format_whole_ref
453-
if (format === 'truncated') ref = format_truncated_ref
454-
if (format === 'before-after') ref = format_before_after_ref
455-
if (format === 'diff') ref = format_diff_ref
468+
if (format == 'whole') ref = format_whole_ref
469+
if (format == 'truncated') ref = format_truncated_ref
470+
if (format == 'before-after') ref = format_before_after_ref
471+
if (format == 'diff') ref = format_diff_ref
456472

457473
return (
458474
<button

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

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export const use_ghost_text = ({
6969
post_caret_range.setStart(range.endContainer, range.endOffset)
7070
const text_after_cursor = post_caret_range.toString()
7171

72-
if (text_after_cursor === '' || /^\s/.test(text_after_cursor)) {
72+
if (text_after_cursor == '' || /^\s/.test(text_after_cursor)) {
7373
const pre_caret_range = range.cloneRange()
7474
pre_caret_range.selectNodeContents(input_ref.current)
7575
pre_caret_range.setEnd(range.startContainer, range.startOffset)
@@ -164,15 +164,41 @@ export const use_ghost_text = ({
164164
)
165165
if (ghost_node) {
166166
const text_node = document.createTextNode(ghost_node.textContent || '')
167-
ghost_node.parentNode?.replaceChild(text_node, ghost_node)
167+
const parent_node = ghost_node.parentNode
168+
169+
if (parent_node) {
170+
parent_node.replaceChild(text_node, ghost_node)
171+
172+
let next_sibling = text_node.nextSibling
173+
let space_added = false
174+
175+
if (
176+
!next_sibling ||
177+
next_sibling.nodeType !== Node.TEXT_NODE ||
178+
!next_sibling.textContent?.startsWith(' ')
179+
) {
180+
const space_node = document.createTextNode(' ')
181+
if (next_sibling) {
182+
parent_node.insertBefore(space_node, next_sibling)
183+
} else {
184+
parent_node.appendChild(space_node)
185+
}
186+
next_sibling = space_node
187+
space_added = true
188+
}
168189

169-
const selection = window.getSelection()
170-
if (selection) {
171-
const range = document.createRange()
172-
range.setStartAfter(text_node)
173-
range.collapse(true)
174-
selection.removeAllRanges()
175-
selection.addRange(range)
190+
const selection = window.getSelection()
191+
if (selection) {
192+
const range = document.createRange()
193+
if (space_added) {
194+
range.setStartAfter(next_sibling!)
195+
} else {
196+
range.setStart(next_sibling!, 1)
197+
}
198+
range.collapse(true)
199+
selection.removeAllRanges()
200+
selection.addRange(range)
201+
}
176202
}
177203

178204
input_ref.current.dispatchEvent(

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,13 @@ export const use_handlers = (
222222

223223
const new_value = leading_part + trailing_part
224224
const new_raw_cursor_pos = leading_part.length
225-
has_modified_current_entry_ref.current = new_value !== ''
225+
has_modified_current_entry_ref.current = new_value != ''
226226
update_value(new_value, new_raw_cursor_pos)
227227
}
228228

229229
const handle_keyword_deletion_by_click = (keyword_element: HTMLElement) => {
230230
const keyword_type = keyword_element.dataset.type
231-
if (keyword_type === 'file-keyword') {
231+
if (keyword_type == 'file-keyword') {
232232
const file_path = keyword_element.dataset.path
233233
if (!file_path || !props.context_file_paths?.includes(file_path)) return
234234

@@ -238,7 +238,7 @@ export const use_handlers = (
238238
if (start_index !== -1) {
239239
apply_keyword_deletion(start_index, start_index + search_pattern.length)
240240
}
241-
} else if (keyword_type === 'changes-keyword') {
241+
} else if (keyword_type == 'changes-keyword') {
242242
const branch_name = keyword_element.dataset.branchName
243243
if (!branch_name) return
244244

@@ -248,7 +248,7 @@ export const use_handlers = (
248248
if (start_index !== -1) {
249249
apply_keyword_deletion(start_index, start_index + search_pattern.length)
250250
}
251-
} else if (keyword_type === 'saved-context-keyword') {
251+
} else if (keyword_type == 'saved-context-keyword') {
252252
const context_type = keyword_element.dataset.contextType
253253
const context_name = keyword_element.dataset.contextName
254254
if (!context_type || !context_name) return
@@ -259,14 +259,14 @@ export const use_handlers = (
259259
if (start_index !== -1) {
260260
apply_keyword_deletion(start_index, start_index + search_pattern.length)
261261
}
262-
} else if (keyword_type === 'selection-keyword') {
262+
} else if (keyword_type == 'selection-keyword') {
263263
const search_pattern = '#Selection'
264264
const start_index = props.value.indexOf(search_pattern)
265265

266266
if (start_index !== -1) {
267267
apply_keyword_deletion(start_index, start_index + search_pattern.length)
268268
}
269-
} else if (keyword_type === 'commit-keyword') {
269+
} else if (keyword_type == 'commit-keyword') {
270270
const repo_name = keyword_element.dataset.repoName
271271
const commit_hash = keyword_element.dataset.commitHash
272272
const commit_message = keyword_element.dataset.commitMessage
@@ -278,7 +278,7 @@ export const use_handlers = (
278278
if (start_index !== -1) {
279279
apply_keyword_deletion(start_index, start_index + search_pattern.length)
280280
}
281-
} else if (keyword_type === 'contextatcommit-keyword') {
281+
} else if (keyword_type == 'contextatcommit-keyword') {
282282
const repo_name = keyword_element.dataset.repoName
283283
const commit_hash = keyword_element.dataset.commitHash
284284
const commit_message = keyword_element.dataset.commitMessage
@@ -378,7 +378,7 @@ export const use_handlers = (
378378
const caret_position = get_caret_position_from_div(currentTarget)
379379
const char_before_caret = new_display_value.charAt(caret_position - 1)
380380

381-
has_modified_current_entry_ref.current = new_raw_value !== ''
381+
has_modified_current_entry_ref.current = new_raw_value != ''
382382
update_value(new_raw_value)
383383

384384
if (char_before_caret == '@') {
@@ -430,7 +430,7 @@ export const use_handlers = (
430430
let start_of_path = -1
431431
const end_of_path = raw_pos - 1
432432

433-
if (end_of_path >= 0 && props.value[end_of_path] === '`') {
433+
if (end_of_path >= 0 && props.value[end_of_path] == '`') {
434434
const text_before = props.value.substring(0, end_of_path)
435435
start_of_path = text_before.lastIndexOf('`')
436436
}
@@ -657,13 +657,13 @@ export const use_handlers = (
657657
update_value(value, value.length)
658658
}
659659

660-
if (e.key === 'ArrowUp') {
660+
if (e.key == 'ArrowUp') {
661661
if (history_index < active_history.length - 1) {
662662
const new_index = history_index + 1
663663
set_history_index(new_index)
664664
update_and_set_caret(active_history[new_index])
665665
}
666-
} else if (e.key === 'ArrowDown') {
666+
} else if (e.key == 'ArrowDown') {
667667
if (history_index > 0) {
668668
const new_index = history_index - 1
669669
set_history_index(new_index)
@@ -869,7 +869,7 @@ export const use_handlers = (
869869
const new_start_pos = i + 1
870870
const new_value =
871871
value.substring(0, new_start_pos) + value.substring(raw_pos)
872-
has_modified_current_entry_ref.current = new_value !== ''
872+
has_modified_current_entry_ref.current = new_value != ''
873873
update_value(new_value, new_start_pos)
874874
return
875875
}

‎packages/ui/src/components/editor/panel/ResponsePreview/components/FileItem/FileItem.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ export const FileItem: FC<Props> = ({
9696
[styles['file--warning']]:
9797
file.diff_application_method == 'search_and_replace' &&
9898
!file.fixed_with_intelligent_update,
99-
[styles['file--deleted']]: file.file_state === 'deleted'
99+
[styles['file--deleted']]: file.file_state == 'deleted'
100100
})}
101-
onClick={file.file_state === 'deleted' ? undefined : on_click}
101+
onClick={file.file_state == 'deleted' ? undefined : on_click}
102102
role="button"
103103
title={file.file_path}
104104
>

‎packages/ui/src/components/editor/panel/Tasks/hooks/use-auto-focus-new-task.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const use_auto_focus_new_task = (
3333

3434
if (added_ids.length == 1) {
3535
const new_task = id_to_task.get(added_ids[0])
36-
if (new_task && new_task.text === '') {
36+
if (new_task && new_task.text == '') {
3737
set_editing_timestamp(added_ids[0])
3838
}
3939
}

‎packages/ui/src/components/editor/settings/ModelProviders/ModelProviders.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const ModelProviders: React.FC<ModelProviders.Props> = (props) => {
4242
<div className={styles['col-base-url']}>{provider.baseUrl}</div>
4343
</div>
4444
<div className={styles['col-actions']}>
45-
{provider.type === 'custom' && (
45+
{provider.type == 'custom' && (
4646
<IconButton
4747
codicon_icon="edit"
4848
on_click={() => props.on_edit_provider(provider.name)}

‎packages/vscode/src/commands/apply-chat-response-command/handlers/intelligent-update-handler.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ export const handle_intelligent_update = async (params: {
435435
data: error
436436
})
437437

438-
if (error.message !== 'Operation cancelled' && !axios.isCancel(error)) {
438+
if (error.message != 'Operation cancelled' && !axios.isCancel(error)) {
439439
vscode.window.showErrorMessage(
440440
dictionary.error_message.ERROR_DURING_PROCESSING(error.message)
441441
)

‎packages/vscode/src/commands/apply-chat-response-command/handlers/truncated-handler.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ function process_truncated_content(
156156
for (let i = 0; i < blocks.length; i++) {
157157
const block = blocks[i]
158158

159-
if (block.type === 'code') {
159+
if (block.type == 'code') {
160160
output_lines.push(...block.lines)
161161

162162
// Try to sync with original to handle replacements (context consumption)
@@ -198,7 +198,7 @@ function process_truncated_content(
198198

199199
if (i + 1 < blocks.length) {
200200
const next_block = blocks[i + 1]
201-
if (next_block.type === 'code') {
201+
if (next_block.type == 'code') {
202202
// Find where the next block starts in original
203203
const prefix_lines = next_block.lines.slice(0, 10)
204204
let found_next = false

0 commit comments

Comments
 (0)