on agent setting change
Co-authored-by: Oleksiy Syvokon <oleksiy.syvokon@gmail.com>
This commit is contained in:
parent
dfa7cd431a
commit
f7b946e525
7 changed files with 66 additions and 37 deletions
|
@ -5,6 +5,7 @@ use crate::{
|
|||
use acp_thread::{MentionUri, selection_name};
|
||||
use agent_client_protocol as acp;
|
||||
use agent_servers::AgentServer;
|
||||
use agent_settings::{AgentEditorMode, AgentSettings};
|
||||
use agent2::HistoryStore;
|
||||
use anyhow::{Context as _, Result, anyhow};
|
||||
use assistant_slash_commands::codeblock_fence_for_path;
|
||||
|
@ -113,12 +114,10 @@ impl MessageEditor {
|
|||
});
|
||||
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 {
|
||||
agent_settings::AgentEditorMode::EditorModeOverride(mode) => mode,
|
||||
agent_settings::AgentEditorMode::Inherit => {
|
||||
vim_mode_setting::EditorModeSetting::get_global(cx).0
|
||||
}
|
||||
AgentEditorMode::EditorModeOverride(mode) => mode,
|
||||
AgentEditorMode::Inherit => vim_mode_setting::EditorModeSetting::get_global(cx).0,
|
||||
};
|
||||
|
||||
let editor = cx.new(|cx| {
|
||||
|
@ -129,7 +128,7 @@ impl MessageEditor {
|
|||
editor.set_placeholder_text(placeholder, cx);
|
||||
editor.set_show_indent_guides(false, cx);
|
||||
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_context_menu_options(ContextMenuOptions {
|
||||
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 {
|
||||
editor,
|
||||
project,
|
||||
|
|
|
@ -136,7 +136,7 @@ pub(crate) fn create_editor(
|
|||
editor.set_placeholder_text("Message the agent – @ to include context", cx);
|
||||
editor.set_show_indent_guides(false, cx);
|
||||
editor.set_soft_wrap();
|
||||
editor.set_default_editor_mode(editor_mode);
|
||||
editor.set_editor_mode(editor_mode, cx);
|
||||
editor.set_context_menu_options(ContextMenuOptions {
|
||||
min_entries_visible: 12,
|
||||
max_entries_visible: 12,
|
||||
|
@ -236,6 +236,18 @@ impl MessageEditor {
|
|||
cx.observe(&thread.read(cx).action_log().clone(), |_, _, cx| {
|
||||
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| {
|
||||
|
|
|
@ -75,7 +75,7 @@ impl Console {
|
|||
editor.set_show_wrap_guides(false, cx);
|
||||
editor.set_show_indent_guides(false, 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
|
||||
});
|
||||
|
|
|
@ -201,6 +201,7 @@ use ui::{
|
|||
IconSize, Indicator, Key, Tooltip, h_flex, prelude::*,
|
||||
};
|
||||
use util::{RangeExt, ResultExt, TryFutureExt, maybe, post_inc};
|
||||
use vim_mode_setting::EditorMode;
|
||||
use workspace::{
|
||||
CollaboratorId, Item as WorkspaceItem, ItemId, ItemNavHistory, OpenInTerminal, OpenTerminal,
|
||||
RestoreOnStartupBehavior, SERIALIZATION_THROTTLE_TIME, SplitDirection, TabBarSettings, Toast,
|
||||
|
@ -1179,7 +1180,7 @@ pub struct Editor {
|
|||
next_color_inlay_id: usize,
|
||||
colors: Option<LspColorData>,
|
||||
folding_newlines: Task<()>,
|
||||
default_editor_mode: vim_mode_setting::EditorMode,
|
||||
editor_mode: vim_mode_setting::EditorMode,
|
||||
// editor_mode: EditorMode, <-- while init define which editor,
|
||||
|
||||
// agenty subscribe to agen settings
|
||||
|
@ -2293,7 +2294,7 @@ impl Editor {
|
|||
display_mode: mode,
|
||||
selection_drag_state: SelectionDragState::None,
|
||||
folding_newlines: Task::ready(()),
|
||||
default_editor_mode: vim_mode_setting::EditorMode::default(),
|
||||
editor_mode: vim_mode_setting::EditorMode::default(),
|
||||
};
|
||||
|
||||
if is_minimap {
|
||||
|
@ -3030,12 +3031,19 @@ impl Editor {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn set_default_editor_mode(&mut self, to: vim_mode_setting::EditorMode) {
|
||||
self.default_editor_mode = to;
|
||||
pub fn set_editor_mode(&mut self, to: vim_mode_setting::EditorMode, cx: &mut Context<Self>) {
|
||||
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 {
|
||||
self.default_editor_mode
|
||||
pub fn editor_mode(&self) -> vim_mode_setting::EditorMode {
|
||||
self.editor_mode
|
||||
}
|
||||
|
||||
fn selections_did_change(
|
||||
|
@ -22937,7 +22945,10 @@ pub enum EditorEvent {
|
|||
anchor: Anchor,
|
||||
is_deactivate: bool,
|
||||
},
|
||||
EditorModeChanged,
|
||||
EditorModeChanged {
|
||||
new_mode: EditorMode,
|
||||
old_mode: EditorMode,
|
||||
},
|
||||
}
|
||||
|
||||
impl EventEmitter<EditorEvent> for Editor {}
|
||||
|
|
|
@ -75,7 +75,7 @@ pub fn init(cx: &mut App) {
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -638,7 +638,7 @@ impl RulesLibrary {
|
|||
editor.set_show_gutter(false, cx);
|
||||
editor.set_show_wrap_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_completion_provider(Some(make_completion_provider()));
|
||||
if focus {
|
||||
|
|
|
@ -443,7 +443,7 @@ impl Vim {
|
|||
return;
|
||||
};
|
||||
|
||||
if !editor.default_editor_mode().is_modal() {
|
||||
if !editor.editor_mode().is_modal() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -471,7 +471,7 @@ impl Vim {
|
|||
let vim = Vim::new(window, cx);
|
||||
|
||||
vim.update(cx, |vim, _| {
|
||||
let initial_mode = match editor.default_editor_mode() {
|
||||
let initial_mode = match editor.editor_mode() {
|
||||
EditorMode::Default => return,
|
||||
EditorMode::Vim(modal_mode) => modal_mode,
|
||||
EditorMode::Helix(modal_mode) => modal_mode,
|
||||
|
@ -483,7 +483,7 @@ impl Vim {
|
|||
entity: vim.clone(),
|
||||
});
|
||||
|
||||
let default_editor_mode = editor.default_editor_mode();
|
||||
let default_editor_mode = editor.editor_mode();
|
||||
vim.update(cx, move |_, cx| {
|
||||
Vim::action(
|
||||
editor,
|
||||
|
@ -914,23 +914,19 @@ impl Vim {
|
|||
vim.set_mark(mark, vec![*anchor], editor.buffer(), window, cx);
|
||||
});
|
||||
}
|
||||
EditorEvent::EditorModeChanged => {
|
||||
self.update_editor(cx, |_vim, _editor, _cx| {
|
||||
// TODO
|
||||
// let enabled = editor.default_editor_mode().is_modal();
|
||||
// if was_enabled == enabled {
|
||||
// return;
|
||||
// }
|
||||
// if !enabled {
|
||||
// editor.set_relative_line_number(None, cx);
|
||||
// }
|
||||
// was_enabled = enabled;
|
||||
// if enabled {
|
||||
// Self::activate(editor, window, cx)
|
||||
// } else {
|
||||
// Self::deactivate(editor, cx)
|
||||
// }
|
||||
//
|
||||
EditorEvent::EditorModeChanged { new_mode, old_mode } => {
|
||||
self.update_editor(cx, |_vim, editor, cx| {
|
||||
let enabled = new_mode.is_modal();
|
||||
let was_enabled = old_mode.is_modal();
|
||||
if was_enabled == enabled {
|
||||
return;
|
||||
}
|
||||
if enabled {
|
||||
Self::activate(editor, window, cx)
|
||||
} else {
|
||||
editor.set_relative_line_number(None, cx);
|
||||
Self::deactivate(editor, cx)
|
||||
}
|
||||
});
|
||||
}
|
||||
_ => {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue