Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 21 additions & 22 deletions src/app/actions/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ impl KeyEventAction {
}
FlycompPromptSelection::No => {}
FlycompPromptSelection::DontAsk => {
app.settings.flycomp.add_to_blacklist(command_word);
crate::settings().flycomp.add_to_blacklist(command_word);
}
}
}
Expand Down Expand Up @@ -524,7 +524,7 @@ impl KeyEventAction {
KeyEventAction::RunFlycomp => app.force_start_flycomp(),
KeyEventAction::ToggleMouse => {
if matches!(
app.settings.mouse_mode,
crate::settings().mouse_mode,
MouseMode::Simple | MouseMode::Smart
) {
log::info!("Toggling mouse state due to toggle_mouse action");
Expand All @@ -540,7 +540,7 @@ impl KeyEventAction {
KeyEventAction::Cancel => {
let buf = app.buffer.buffer();
if !buf.trim().is_empty() {
app.settings
crate::settings()
.cancelled_command_history_manager
.push_entry(buf.to_string());
}
Expand All @@ -553,17 +553,17 @@ impl KeyEventAction {
app.try_submit_current_buffer();
}
KeyEventAction::RunFuzzyHistorySearch => {
if app.settings.history_backend == crate::settings::HistoryBackend::Flyline {
app.settings.history_manager.refresh_jsonl_backend();
if crate::settings().history_backend == crate::settings::HistoryBackend::Flyline {
crate::settings().history_manager.refresh_jsonl_backend();
}
app.settings
crate::settings()
.history_manager
.warm_fuzzy_search_cache(app.buffer.buffer(), Some(0));
app.content_mode =
ContentMode::FuzzyHistorySearch(FuzzyHistorySource::PastCommands);
}
KeyEventAction::RunFuzzyCancelledHistorySearch => {
app.settings
crate::settings()
.cancelled_command_history_manager
.warm_fuzzy_search_cache(app.buffer.buffer(), Some(0));
app.content_mode =
Expand Down Expand Up @@ -597,7 +597,7 @@ impl KeyEventAction {
if app.buffer.delete_selection() {
return;
}
if app.settings.auto_close_chars {
if crate::settings().auto_close_chars {
// Backspace: if the char to the right of the cursor is an auto-inserted closing token
// paired with the char about to be deleted, remove it as well.
app.delete_auto_inserted_closing_if_present();
Expand Down Expand Up @@ -670,8 +670,7 @@ impl KeyEventAction {
app.buffer.clear_selection();
app.buffer_before_history_navigation
.get_or_insert_with(|| app.buffer.buffer().to_string());
if let Some(entry) = app
.settings
if let Some(entry) = crate::settings()
.history_manager
.search_in_history(app.buffer.buffer(), HistorySearchDirection::Backward)
{
Expand All @@ -680,8 +679,7 @@ impl KeyEventAction {
}
KeyEventAction::NextHistoryEntry => {
app.buffer.clear_selection();
match app
.settings
match crate::settings()
.history_manager
.search_in_history(app.buffer.buffer(), HistorySearchDirection::Forward)
{
Expand Down Expand Up @@ -716,7 +714,7 @@ impl KeyEventAction {
}
app.buffer.delete_selection();
if let KeyCode::Char(c) = key.code {
if app.settings.auto_close_chars {
if crate::settings().auto_close_chars {
app.handle_char_insertion(c);
} else {
app.buffer.insert_char(c);
Expand Down Expand Up @@ -852,8 +850,7 @@ impl KeyEventAction {
app.buffer.clear_selection();

// Get the last word of the history command we are currently looking at
let last_word_of_current_history_cmd = app
.settings
let last_word_of_current_history_cmd = crate::settings()
.history_manager
.get_last_word_insert_command()
.and_then(|cmd| crate::history::get_last_word(cmd));
Expand All @@ -866,11 +863,14 @@ impl KeyEventAction {
let is_continuation = target_sub.is_some();

if !is_continuation {
app.settings.history_manager.last_word_insert_reset();
crate::settings().history_manager.last_word_insert_reset();
}

// Move to the previous command with non-empty words
if let Some(cmd) = app.settings.history_manager.last_word_insert_move_prev() {
if let Some(cmd) = crate::settings()
.history_manager
.last_word_insert_move_prev()
{
if let Some(w) = crate::history::get_last_word(cmd) {
if let Some(sub) = &target_sub {
let _ = app.buffer.replace_word_under_cursor(&w, sub);
Expand Down Expand Up @@ -3293,12 +3293,12 @@ pub fn print_bindings_table(
}
}

impl<'a> App<'a> {
impl App {
pub fn handle_key_event(&mut self, key: KeyEvent) {
let _timer = crate::perf::PerfTimer::start("handle_key_event");
let initial_leader_time = self.leader_key_active_at;
log::trace!("Key event: {:?}", key);
let key = apply_remappings(key, &self.settings.key_remappings);
let key = apply_remappings(key, &crate::settings().key_remappings);
log::trace!("Key event after remapping: {:?}", key);

// Evaluate every context variable once up front, so each variable's
Expand All @@ -3312,8 +3312,7 @@ impl<'a> App<'a> {
// Find the highest-priority binding whose context is satisfied and
// matches the key event. User bindings take priority over default bindings.
let mut matched: Option<(Vec<KeyEventAction>, String)> = None;
for binding in self
.settings
for binding in crate::settings()
.keybindings
.iter()
.rev()
Expand Down Expand Up @@ -3355,7 +3354,7 @@ impl<'a> App<'a> {
if matched
.as_ref()
.is_some_and(|(actions, _)| !actions.contains(&KeyEventAction::ToggleMouse))
&& self.settings.mouse_mode == MouseMode::Smart
&& crate::settings().mouse_mode == MouseMode::Smart
&& crate::mouse_state::mouse_state(|m| m.is_disabled())
{
log::debug!("Reenabling mouse due to key event");
Expand Down
34 changes: 17 additions & 17 deletions src/app/actions/mouse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ impl super::ContextVar for MouseContextVar {
MouseContextVar::NotOverCellSemantically(pattern) => !pattern.matches(clicked_tag),
MouseContextVar::OverCellDirectly(pattern) => pattern.matches(direct_tag),
MouseContextVar::SmartModeClickAboveViewport => {
app.settings.mouse_mode == MouseMode::Smart
crate::settings().mouse_mode == MouseMode::Smart
&& last_mouse.is_some_and(|m| {
matches!(m.kind, MouseEventKind::Down(_))
&& app.last_contents.as_ref().is_some_and(|c| {
Expand All @@ -241,7 +241,7 @@ impl super::ContextVar for MouseContextVar {
})
}
MouseContextVar::SmartModeScroll => {
app.settings.mouse_mode == MouseMode::Smart
crate::settings().mouse_mode == MouseMode::Smart
&& last_mouse.is_some_and(|m| {
matches!(
m.kind,
Expand Down Expand Up @@ -878,8 +878,8 @@ impl MouseEventAction {
MouseActionOutput::update_now()
}
MouseEventAction::RunTutorial => {
app.settings.run_tutorial = true;
app.settings.tutorial_step = crate::tutorial::TutorialStep::Welcome;
crate::settings().run_tutorial = true;
crate::settings().tutorial_step = crate::tutorial::TutorialStep::Welcome;
use termina::escape::csi::{Csi, Cursor, Edit, EraseInDisplay};
if let Err(e) = crate::flush_stdout!(
"{}{}",
Expand Down Expand Up @@ -1054,7 +1054,7 @@ impl MouseEventAction {
}
MouseEventAction::ClickCommand => {
if let Some(Tag::Command(byte_pos)) = clicked_tag {
if app.settings.select_with_mouse {
if crate::settings().select_with_mouse {
let extend_selection = mouse.modifiers.contains(KeyModifiers::SHIFT);
if extend_selection {
app.buffer.start_selection_if_none();
Expand All @@ -1079,7 +1079,7 @@ impl MouseEventAction {
}
MouseEventAction::ReleaseCommand => MouseActionOutput::update_now(),
MouseEventAction::SelectAll => {
if app.settings.select_with_mouse {
if crate::settings().select_with_mouse {
app.buffer.select_entire_buffer();
MouseActionOutput::update_now()
} else {
Expand All @@ -1088,7 +1088,7 @@ impl MouseEventAction {
}
MouseEventAction::SelectWord => {
if let Some(Tag::Command(byte_pos)) = clicked_tag {
if app.settings.select_with_mouse {
if crate::settings().select_with_mouse {
app.buffer
.try_move_cursor_to_byte_pos(byte_pos, move_past_final);
app.buffer.select_word_using_mouse();
Expand All @@ -1102,7 +1102,7 @@ impl MouseEventAction {
}
MouseEventAction::SelectLine => {
if let Some(Tag::Command(byte_pos)) = clicked_tag {
if app.settings.select_with_mouse {
if crate::settings().select_with_mouse {
app.buffer
.try_move_cursor_to_byte_pos(byte_pos, move_past_final);
app.buffer.select_line_using_mouse();
Expand All @@ -1116,7 +1116,7 @@ impl MouseEventAction {
}
MouseEventAction::DragCommand => {
if let Some(Tag::Command(byte_pos)) = clicked_tag {
if app.settings.select_with_mouse {
if crate::settings().select_with_mouse {
let active_drag_tag = mouse_state(|m| m.drag_start_tag);
if matches!(active_drag_tag, Some(Tag::Command(_))) {
app.buffer.start_selection_if_none();
Expand All @@ -1136,7 +1136,7 @@ impl MouseEventAction {
}
MouseEventAction::DragWord => {
if let Some(Tag::Command(byte_pos)) = clicked_tag {
if app.settings.select_with_mouse {
if crate::settings().select_with_mouse {
let active_drag_tag = mouse_state(|m| m.drag_start_tag);
if matches!(active_drag_tag, Some(Tag::Command(_))) {
if let Some(drag_start_pos) =
Expand Down Expand Up @@ -1168,7 +1168,7 @@ impl MouseEventAction {
}
MouseEventAction::DragLine => {
if let Some(Tag::Command(byte_pos)) = clicked_tag {
if app.settings.select_with_mouse {
if crate::settings().select_with_mouse {
let active_drag_tag = mouse_state(|m| m.drag_start_tag);
if matches!(active_drag_tag, Some(Tag::Command(_))) {
if let Some(drag_start_pos) =
Expand Down Expand Up @@ -1199,26 +1199,26 @@ impl MouseEventAction {
}
}
MouseEventAction::DragAll => {
if app.settings.select_with_mouse {
if crate::settings().select_with_mouse {
app.buffer.select_entire_buffer();
MouseActionOutput::update_soon()
} else {
MouseActionOutput::dont_update()
}
}
MouseEventAction::ClickTutorialPrev => {
app.settings.tutorial_step.prev();
crate::settings().tutorial_step.prev();
log::info!(
"Tutorial navigated to prev: {:?}",
app.settings.tutorial_step
crate::settings().tutorial_step
);
MouseActionOutput::dont_update()
}
MouseEventAction::ClickTutorialNext => {
app.settings.tutorial_step.next();
crate::settings().tutorial_step.next();
log::info!(
"Tutorial navigated to next: {:?}",
app.settings.tutorial_step
crate::settings().tutorial_step
);
MouseActionOutput::dont_update()
}
Expand Down Expand Up @@ -1317,7 +1317,7 @@ impl MouseEventAction {
if matches!(mouse.kind, MouseEventKind::Up(MouseButton::Left)) {
let mode = std::mem::replace(&mut app.content_mode, ContentMode::Normal);
if let ContentMode::TabCompletionAskForFlycomp { command_word, .. } = mode {
app.settings.flycomp.add_to_blacklist(command_word);
crate::settings().flycomp.add_to_blacklist(command_word);
}
MouseActionOutput::update_now()
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/app/auto_close.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub(crate) fn delete_auto_inserted_closing_if_present(
}
}

impl<'a> App<'a> {
impl App {
pub(crate) fn handle_char_insertion(&mut self, c: char) {
handle_char_insertion(&mut self.buffer, &mut self.dparser_tokens_cache, c);
}
Expand Down
Loading