diff options
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r-- | helix-term/src/commands.rs | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index c7489810..0b624f25 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -842,6 +842,7 @@ fn align_selections(cx: &mut Context) { fn goto_window(cx: &mut Context, align: Align) { let count = cx.count() - 1; + let config = cx.editor.config(); let (view, doc) = current!(cx.editor); let height = view.inner_area().height as usize; @@ -850,7 +851,7 @@ fn goto_window(cx: &mut Context, align: Align) { // - 1 so we have at least one gap in the middle. // a height of 6 with padding of 3 on each side will keep shifting the view back and forth // as we type - let scrolloff = cx.editor.config.scrolloff.min(height.saturating_sub(1) / 2); + let scrolloff = config.scrolloff.min(height.saturating_sub(1) / 2); let last_line = view.last_line(doc); @@ -1274,6 +1275,7 @@ fn switch_to_lowercase(cx: &mut Context) { pub fn scroll(cx: &mut Context, offset: usize, direction: Direction) { use Direction::*; + let config = cx.editor.config(); let (view, doc) = current!(cx.editor); let range = doc.selection(view.id).primary(); @@ -1292,7 +1294,7 @@ pub fn scroll(cx: &mut Context, offset: usize, direction: Direction) { let height = view.inner_area().height; - let scrolloff = cx.editor.config.scrolloff.min(height as usize / 2); + let scrolloff = config.scrolloff.min(height as usize / 2); view.offset.row = match direction { Forward => view.offset.row + offset, @@ -1585,8 +1587,9 @@ fn rsearch(cx: &mut Context) { fn searcher(cx: &mut Context, direction: Direction) { let reg = cx.register.unwrap_or('/'); - let scrolloff = cx.editor.config.scrolloff; - let wrap_around = cx.editor.config.search.wrap_around; + let config = cx.editor.config(); + let scrolloff = config.scrolloff; + let wrap_around = config.search.wrap_around; let doc = doc!(cx.editor); @@ -1629,13 +1632,14 @@ fn searcher(cx: &mut Context, direction: Direction) { } fn search_next_or_prev_impl(cx: &mut Context, movement: Movement, direction: Direction) { - let scrolloff = cx.editor.config.scrolloff; + let config = cx.editor.config(); + let scrolloff = config.scrolloff; let (view, doc) = current!(cx.editor); let registers = &cx.editor.registers; if let Some(query) = registers.read('/') { let query = query.last().unwrap(); let contents = doc.text().slice(..).to_string(); - let search_config = &cx.editor.config.search; + let search_config = &config.search; let case_insensitive = if search_config.smart_case { !query.chars().any(char::is_uppercase) } else { @@ -1695,8 +1699,9 @@ fn search_selection(cx: &mut Context) { fn global_search(cx: &mut Context) { let (all_matches_sx, all_matches_rx) = tokio::sync::mpsc::unbounded_channel::<(usize, PathBuf)>(); - let smart_case = cx.editor.config.search.smart_case; - let file_picker_config = cx.editor.config.file_picker.clone(); + let config = cx.editor.config(); + let smart_case = config.search.smart_case; + let file_picker_config = config.file_picker.clone(); let completions = search_completions(cx, None); let prompt = ui::regex_prompt( @@ -2028,7 +2033,7 @@ fn append_mode(cx: &mut Context) { fn file_picker(cx: &mut Context) { // We don't specify language markers, root will be the root of the current git repo let root = find_root(None, &[]).unwrap_or_else(|| PathBuf::from("./")); - let picker = ui::file_picker(root, &cx.editor.config); + let picker = ui::file_picker(root, &cx.editor.config()); cx.push_layer(Box::new(overlayed(picker))); } @@ -2105,7 +2110,7 @@ pub fn command_palette(cx: &mut Context) { move |compositor: &mut Compositor, cx: &mut compositor::Context| { let doc = doc_mut!(cx.editor); let keymap = - compositor.find::<ui::EditorView>().unwrap().keymaps.map[&doc.mode].reverse_map(); + compositor.find::<ui::EditorView>().unwrap().keymaps.map()[&doc.mode].reverse_map(); let mut commands: Vec<MappableCommand> = MappableCommand::STATIC_COMMAND_LIST.into(); commands.extend(typed::TYPABLE_COMMAND_LIST.iter().map(|cmd| { @@ -2571,6 +2576,7 @@ pub mod insert { // It trigger completion when idle timer reaches deadline // Only trigger completion if the word under cursor is longer than n characters pub fn idle_completion(cx: &mut Context) { + let config = cx.editor.config(); let (view, doc) = current!(cx.editor); let text = doc.text().slice(..); let cursor = doc.selection(view.id).primary().cursor(text); @@ -2578,7 +2584,7 @@ pub mod insert { use helix_core::chars::char_is_word; let mut iter = text.chars_at(cursor); iter.reverse(); - for _ in 0..cx.editor.config.completion_trigger_len { + for _ in 0..config.completion_trigger_len { match iter.next() { Some(c) if char_is_word(c) => {} _ => return, @@ -4154,7 +4160,7 @@ fn shell_keep_pipe(cx: &mut Context) { Some('|'), ui::completers::none, move |cx: &mut compositor::Context, input: &str, event: PromptEvent| { - let shell = &cx.editor.config.shell; + let shell = &cx.editor.config().shell; if event != PromptEvent::Validate { return; } @@ -4250,7 +4256,8 @@ fn shell(cx: &mut Context, prompt: Cow<'static, str>, behavior: ShellBehavior) { Some('|'), ui::completers::none, move |cx: &mut compositor::Context, input: &str, event: PromptEvent| { - let shell = &cx.editor.config.shell; + let config = cx.editor.config(); + let shell = &config.shell; if event != PromptEvent::Validate { return; } @@ -4295,7 +4302,7 @@ fn shell(cx: &mut Context, prompt: Cow<'static, str>, behavior: ShellBehavior) { // after replace cursor may be out of bounds, do this to // make sure cursor is in view and update scroll as well - view.ensure_cursor_in_view(doc, cx.editor.config.scrolloff); + view.ensure_cursor_in_view(doc, config.scrolloff); }, ); |