on agent setting change

Co-authored-by: Oleksiy Syvokon <oleksiy.syvokon@gmail.com>
This commit is contained in:
Smit Barmase 2025-08-22 16:09:45 +05:30
parent dfa7cd431a
commit f7b946e525
No known key found for this signature in database
7 changed files with 66 additions and 37 deletions

View file

@ -5,6 +5,7 @@ use crate::{
use acp_thread::{MentionUri, selection_name}; use acp_thread::{MentionUri, selection_name};
use agent_client_protocol as acp; use agent_client_protocol as acp;
use agent_servers::AgentServer; use agent_servers::AgentServer;
use agent_settings::{AgentEditorMode, AgentSettings};
use agent2::HistoryStore; use agent2::HistoryStore;
use anyhow::{Context as _, Result, anyhow}; use anyhow::{Context as _, Result, anyhow};
use assistant_slash_commands::codeblock_fence_for_path; use assistant_slash_commands::codeblock_fence_for_path;
@ -113,12 +114,10 @@ impl MessageEditor {
}); });
let mention_set = MentionSet::default(); let mention_set = MentionSet::default();
let settings = agent_settings::AgentSettings::get_global(cx); let settings = AgentSettings::get_global(cx);
let editor_mode = match settings.editor_mode { let editor_mode = match settings.editor_mode {
agent_settings::AgentEditorMode::EditorModeOverride(mode) => mode, AgentEditorMode::EditorModeOverride(mode) => mode,
agent_settings::AgentEditorMode::Inherit => { AgentEditorMode::Inherit => vim_mode_setting::EditorModeSetting::get_global(cx).0,
vim_mode_setting::EditorModeSetting::get_global(cx).0
}
}; };
let editor = cx.new(|cx| { let editor = cx.new(|cx| {
@ -129,7 +128,7 @@ impl MessageEditor {
editor.set_placeholder_text(placeholder, cx); editor.set_placeholder_text(placeholder, cx);
editor.set_show_indent_guides(false, cx); editor.set_show_indent_guides(false, cx);
editor.set_soft_wrap(); editor.set_soft_wrap();
editor.set_default_editor_mode(editor_mode); editor.set_editor_mode(editor_mode, cx);
editor.set_completion_provider(Some(Rc::new(completion_provider))); editor.set_completion_provider(Some(Rc::new(completion_provider)));
editor.set_context_menu_options(ContextMenuOptions { editor.set_context_menu_options(ContextMenuOptions {
min_entries_visible: 12, min_entries_visible: 12,
@ -168,6 +167,17 @@ impl MessageEditor {
} }
})); }));
subscriptions.push(cx.observe_global::<AgentSettings>(move |this, cx| {
let settings = AgentSettings::get_global(cx);
let editor_mode = match settings.editor_mode {
AgentEditorMode::EditorModeOverride(mode) => mode,
AgentEditorMode::Inherit => vim_mode_setting::EditorModeSetting::get_global(cx).0,
};
this.editor.update(cx, |editor, cx| {
editor.set_editor_mode(editor_mode, cx);
});
}));
Self { Self {
editor, editor,
project, project,

View file

@ -136,7 +136,7 @@ pub(crate) fn create_editor(
editor.set_placeholder_text("Message the agent @ to include context", cx); editor.set_placeholder_text("Message the agent @ to include context", cx);
editor.set_show_indent_guides(false, cx); editor.set_show_indent_guides(false, cx);
editor.set_soft_wrap(); editor.set_soft_wrap();
editor.set_default_editor_mode(editor_mode); editor.set_editor_mode(editor_mode, cx);
editor.set_context_menu_options(ContextMenuOptions { editor.set_context_menu_options(ContextMenuOptions {
min_entries_visible: 12, min_entries_visible: 12,
max_entries_visible: 12, max_entries_visible: 12,
@ -236,6 +236,18 @@ impl MessageEditor {
cx.observe(&thread.read(cx).action_log().clone(), |_, _, cx| { cx.observe(&thread.read(cx).action_log().clone(), |_, _, cx| {
cx.notify() cx.notify()
}), }),
cx.observe_global::<AgentSettings>(move |this, cx| {
let settings = agent_settings::AgentSettings::get_global(cx);
let editor_mode = match settings.editor_mode {
agent_settings::AgentEditorMode::EditorModeOverride(mode) => mode,
agent_settings::AgentEditorMode::Inherit => {
vim_mode_setting::EditorModeSetting::get_global(cx).0
}
};
this.editor.update(cx, |editor, cx| {
editor.set_editor_mode(editor_mode, cx);
});
}),
]; ];
let model_selector = cx.new(|cx| { let model_selector = cx.new(|cx| {

View file

@ -75,7 +75,7 @@ impl Console {
editor.set_show_wrap_guides(false, cx); editor.set_show_wrap_guides(false, cx);
editor.set_show_indent_guides(false, cx); editor.set_show_indent_guides(false, cx);
editor.set_show_edit_predictions(Some(false), window, cx); editor.set_show_edit_predictions(Some(false), window, cx);
editor.set_default_editor_mode(EditorMode::Default); editor.set_editor_mode(EditorMode::Default, cx);
editor.set_soft_wrap_mode(language::language_settings::SoftWrap::EditorWidth, cx); editor.set_soft_wrap_mode(language::language_settings::SoftWrap::EditorWidth, cx);
editor editor
}); });

View file

@ -201,6 +201,7 @@ use ui::{
IconSize, Indicator, Key, Tooltip, h_flex, prelude::*, IconSize, Indicator, Key, Tooltip, h_flex, prelude::*,
}; };
use util::{RangeExt, ResultExt, TryFutureExt, maybe, post_inc}; use util::{RangeExt, ResultExt, TryFutureExt, maybe, post_inc};
use vim_mode_setting::EditorMode;
use workspace::{ use workspace::{
CollaboratorId, Item as WorkspaceItem, ItemId, ItemNavHistory, OpenInTerminal, OpenTerminal, CollaboratorId, Item as WorkspaceItem, ItemId, ItemNavHistory, OpenInTerminal, OpenTerminal,
RestoreOnStartupBehavior, SERIALIZATION_THROTTLE_TIME, SplitDirection, TabBarSettings, Toast, RestoreOnStartupBehavior, SERIALIZATION_THROTTLE_TIME, SplitDirection, TabBarSettings, Toast,
@ -1179,7 +1180,7 @@ pub struct Editor {
next_color_inlay_id: usize, next_color_inlay_id: usize,
colors: Option<LspColorData>, colors: Option<LspColorData>,
folding_newlines: Task<()>, folding_newlines: Task<()>,
default_editor_mode: vim_mode_setting::EditorMode, editor_mode: vim_mode_setting::EditorMode,
// editor_mode: EditorMode, <-- while init define which editor, // editor_mode: EditorMode, <-- while init define which editor,
// agenty subscribe to agen settings // agenty subscribe to agen settings
@ -2293,7 +2294,7 @@ impl Editor {
display_mode: mode, display_mode: mode,
selection_drag_state: SelectionDragState::None, selection_drag_state: SelectionDragState::None,
folding_newlines: Task::ready(()), folding_newlines: Task::ready(()),
default_editor_mode: vim_mode_setting::EditorMode::default(), editor_mode: vim_mode_setting::EditorMode::default(),
}; };
if is_minimap { if is_minimap {
@ -3030,12 +3031,19 @@ impl Editor {
}) })
} }
pub fn set_default_editor_mode(&mut self, to: vim_mode_setting::EditorMode) { pub fn set_editor_mode(&mut self, to: vim_mode_setting::EditorMode, cx: &mut Context<Self>) {
self.default_editor_mode = to; let from = self.editor_mode;
if from != to {
self.editor_mode = to;
cx.emit(EditorEvent::EditorModeChanged {
old_mode: from,
new_mode: to,
});
}
} }
pub fn default_editor_mode(&self) -> vim_mode_setting::EditorMode { pub fn editor_mode(&self) -> vim_mode_setting::EditorMode {
self.default_editor_mode self.editor_mode
} }
fn selections_did_change( fn selections_did_change(
@ -22937,7 +22945,10 @@ pub enum EditorEvent {
anchor: Anchor, anchor: Anchor,
is_deactivate: bool, is_deactivate: bool,
}, },
EditorModeChanged, EditorModeChanged {
new_mode: EditorMode,
old_mode: EditorMode,
},
} }
impl EventEmitter<EditorEvent> for Editor {} impl EventEmitter<EditorEvent> for Editor {}

View file

@ -75,7 +75,7 @@ pub fn init(cx: &mut App) {
return; return;
}; };
if !editor.default_editor_mode().is_modal() || !editor.buffer().read(cx).is_singleton() if !editor.editor_mode().is_modal() || !editor.buffer().read(cx).is_singleton()
{ {
return; return;
} }

View file

@ -638,7 +638,7 @@ impl RulesLibrary {
editor.set_show_gutter(false, cx); editor.set_show_gutter(false, cx);
editor.set_show_wrap_guides(false, cx); editor.set_show_wrap_guides(false, cx);
editor.set_show_indent_guides(false, cx); editor.set_show_indent_guides(false, cx);
editor.set_default_editor_mode(EditorMode::Default); editor.set_editor_mode(EditorMode::Default, cx);
editor.set_current_line_highlight(Some(CurrentLineHighlight::None)); editor.set_current_line_highlight(Some(CurrentLineHighlight::None));
editor.set_completion_provider(Some(make_completion_provider())); editor.set_completion_provider(Some(make_completion_provider()));
if focus { if focus {

View file

@ -443,7 +443,7 @@ impl Vim {
return; return;
}; };
if !editor.default_editor_mode().is_modal() { if !editor.editor_mode().is_modal() {
return; return;
} }
@ -471,7 +471,7 @@ impl Vim {
let vim = Vim::new(window, cx); let vim = Vim::new(window, cx);
vim.update(cx, |vim, _| { vim.update(cx, |vim, _| {
let initial_mode = match editor.default_editor_mode() { let initial_mode = match editor.editor_mode() {
EditorMode::Default => return, EditorMode::Default => return,
EditorMode::Vim(modal_mode) => modal_mode, EditorMode::Vim(modal_mode) => modal_mode,
EditorMode::Helix(modal_mode) => modal_mode, EditorMode::Helix(modal_mode) => modal_mode,
@ -483,7 +483,7 @@ impl Vim {
entity: vim.clone(), entity: vim.clone(),
}); });
let default_editor_mode = editor.default_editor_mode(); let default_editor_mode = editor.editor_mode();
vim.update(cx, move |_, cx| { vim.update(cx, move |_, cx| {
Vim::action( Vim::action(
editor, editor,
@ -914,23 +914,19 @@ impl Vim {
vim.set_mark(mark, vec![*anchor], editor.buffer(), window, cx); vim.set_mark(mark, vec![*anchor], editor.buffer(), window, cx);
}); });
} }
EditorEvent::EditorModeChanged => { EditorEvent::EditorModeChanged { new_mode, old_mode } => {
self.update_editor(cx, |_vim, _editor, _cx| { self.update_editor(cx, |_vim, editor, cx| {
// TODO let enabled = new_mode.is_modal();
// let enabled = editor.default_editor_mode().is_modal(); let was_enabled = old_mode.is_modal();
// if was_enabled == enabled { if was_enabled == enabled {
// return; return;
// } }
// if !enabled { if enabled {
// editor.set_relative_line_number(None, cx); Self::activate(editor, window, cx)
// } } else {
// was_enabled = enabled; editor.set_relative_line_number(None, cx);
// if enabled { Self::deactivate(editor, cx)
// Self::activate(editor, window, cx) }
// } else {
// Self::deactivate(editor, cx)
// }
//
}); });
} }
_ => {} _ => {}