Skip to content

Commit d3697e4

Browse files
committed
Restrict fragment pasting to files included in the context
1 parent 2617f8e commit d3697e4

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

  • packages/ui/src/components/editor/panel/prompts/PromptField/hooks/use-handlers

packages/ui/src/components/editor/panel/prompts/PromptField/hooks/use-handlers/handle-paste.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,16 @@ export const create_perform_paste =
3434
let text_to_insert = text
3535
let caret_offset_adjustment = 0
3636

37+
const is_file_in_context =
38+
props.currently_open_file_path !== undefined &&
39+
(props.context_file_paths ?? []).includes(props.currently_open_file_path)
40+
3741
if (
3842
!refs.is_shift_pressed_ref.current &&
3943
props.current_selection &&
4044
text == props.current_selection.text &&
41-
props.currently_open_file_path
45+
props.currently_open_file_path &&
46+
is_file_in_context
4247
) {
4348
const { start_line, start_col, end_line, end_col } =
4449
props.current_selection
@@ -97,10 +102,15 @@ export const create_handle_paste =
97102
return
98103
}
99104

105+
const is_file_in_context =
106+
props.currently_open_file_path !== undefined &&
107+
(props.context_file_paths ?? []).includes(props.currently_open_file_path)
108+
100109
const is_fragment_paste =
101110
props.current_selection &&
102111
text == props.current_selection.text &&
103-
props.currently_open_file_path
112+
props.currently_open_file_path &&
113+
is_file_in_context
104114

105115
const has_symbols =
106116
get_symbol_ranges({

0 commit comments

Comments
 (0)