From f1a2638d2912581542898218003491d4a7a4f17b Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Fri, 16 Aug 2024 17:22:47 +0300 Subject: [PATCH] Do not enable copilot for always read-only editors (#16356) Release Notes: - N/A --- crates/assistant/src/inline_assistant.rs | 1 + crates/assistant/src/prompt_library.rs | 10 ++++++++-- crates/assistant/src/workflow/step_view.rs | 1 + crates/editor/src/hunk_diff.rs | 21 ++++++++++----------- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/crates/assistant/src/inline_assistant.rs b/crates/assistant/src/inline_assistant.rs index 516a3574f2..533107c1d5 100644 --- a/crates/assistant/src/inline_assistant.rs +++ b/crates/assistant/src/inline_assistant.rs @@ -1109,6 +1109,7 @@ impl InlineAssistant { editor.set_show_gutter(false, cx); editor.scroll_manager.set_forbid_vertical_scroll(true); editor.set_read_only(true); + editor.set_show_inline_completions(false); editor.highlight_rows::( Anchor::min()..=Anchor::max(), Some(cx.theme().status().deleted_background), diff --git a/crates/assistant/src/prompt_library.rs b/crates/assistant/src/prompt_library.rs index 08ae0b3fdf..ff9af6b7e8 100644 --- a/crates/assistant/src/prompt_library.rs +++ b/crates/assistant/src/prompt_library.rs @@ -494,7 +494,10 @@ impl PromptLibrary { let mut editor = Editor::auto_width(cx); editor.set_placeholder_text("Untitled", cx); editor.set_text(prompt_metadata.title.unwrap_or_default(), cx); - editor.set_read_only(prompt_id.is_built_in()); + if prompt_id.is_built_in() { + editor.set_read_only(true); + editor.set_show_inline_completions(false); + } editor }); let body_editor = cx.new_view(|cx| { @@ -506,7 +509,10 @@ impl PromptLibrary { }); let mut editor = Editor::for_buffer(buffer, None, cx); - editor.set_read_only(prompt_id.is_built_in()); + if prompt_id.is_built_in() { + editor.set_read_only(true); + editor.set_show_inline_completions(false); + } editor.set_soft_wrap_mode(SoftWrap::EditorWidth, cx); editor.set_show_gutter(false, cx); editor.set_show_wrap_guides(false, cx); diff --git a/crates/assistant/src/workflow/step_view.rs b/crates/assistant/src/workflow/step_view.rs index 8c07526fd4..5e75669fc1 100644 --- a/crates/assistant/src/workflow/step_view.rs +++ b/crates/assistant/src/workflow/step_view.rs @@ -78,6 +78,7 @@ impl WorkflowStepView { editor.set_show_wrap_guides(false, cx); editor.set_show_indent_guides(false, cx); editor.set_read_only(true); + editor.set_show_inline_completions(false); editor.insert_blocks( [ BlockProperties { diff --git a/crates/editor/src/hunk_diff.rs b/crates/editor/src/hunk_diff.rs index 11f1da68e9..ca5ac5d588 100644 --- a/crates/editor/src/hunk_diff.rs +++ b/crates/editor/src/hunk_diff.rs @@ -777,19 +777,18 @@ fn editor_with_deleted_text( }); let mut editor = Editor::for_multibuffer(multi_buffer, None, true, cx); - editor.soft_wrap_mode_override = Some(language::language_settings::SoftWrap::None); - editor.show_wrap_guides = Some(false); - editor.show_gutter = false; + editor.set_soft_wrap_mode(language::language_settings::SoftWrap::None, cx); + editor.set_show_wrap_guides(false, cx); + editor.set_show_gutter(false, cx); editor.scroll_manager.set_forbid_vertical_scroll(true); editor.set_read_only(true); - - let editor_snapshot = editor.snapshot(cx); - let start = editor_snapshot.buffer_snapshot.anchor_before(0); - let end = editor_snapshot - .buffer_snapshot - .anchor_after(editor.buffer.read(cx).len(cx)); - - editor.highlight_rows::(start..=end, Some(deleted_color), false, cx); + editor.set_show_inline_completions(false); + editor.highlight_rows::( + Anchor::min()..=Anchor::max(), + Some(deleted_color), + false, + cx, + ); let subscription_editor = parent_editor.clone(); editor._subscriptions.extend([