From df0ed80931c358262fd6858306e28806c0523068 Mon Sep 17 00:00:00 2001 From: Kirawi <67773714+kirawi@users.noreply.github.com> Date: Tue, 20 Jul 2021 15:17:15 -0400 Subject: [PATCH 1/9] Update dark_plus.toml Corrects primary selection color and makes matching cursor easier to spot. --- runtime/themes/dark_plus.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/themes/dark_plus.toml b/runtime/themes/dark_plus.toml index 82cc62891..e7584e5f7 100644 --- a/runtime/themes/dark_plus.toml +++ b/runtime/themes/dark_plus.toml @@ -46,10 +46,10 @@ "ui.cursor" = { fg = "cursor", modifiers = ["reversed"] } "ui.cursor.primary" = { fg = "cursor", modifiers = ["reversed"] } -"ui.cursor.match" = { fg = "cursor", modifiers = ['underlined'] } +"ui.cursor.match" = { bg = "#3a3d41", modifiers = ["underlined"] } "ui.selection" = { bg = "#3a3d41" } -"ui.selection.primary" = { bg = "#add6ff26" } +"ui.selection.primary" = { bg = "#264f78" } "ui.linenr" = { fg = "#858585" } "ui.linenr.selected" = { fg = "#c6c6c6" } From eba0bbda2ee10e9ba53f01f1d324d2c4c82229d2 Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Sun, 18 Jul 2021 12:24:07 +0800 Subject: [PATCH 2/9] Resume last picker Inspired by space ' in doom emacs. --- helix-term/src/commands.rs | 14 ++++++++++++++ helix-term/src/compositor.rs | 7 +++++-- helix-term/src/ui/picker.rs | 2 +- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 5fc96cd92..9b72a8e90 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -217,6 +217,7 @@ impl Command { file_picker, buffer_picker, symbol_picker, + last_picker, prepend_to_line, append_to_line, open_below, @@ -2091,6 +2092,17 @@ fn symbol_picker(cx: &mut Context) { ) } +fn last_picker(cx: &mut Context) { + // TODO: last picker does not seemed to work well with buffer_picker + cx.callback = Some(Box::new(|compositor: &mut Compositor| { + if let Some(picker) = compositor.last_picker.take() { + compositor.push(picker); + } + // XXX: figure out how to show error when no last picker lifetime + // cx.editor.set_error("no last picker".to_owned()) + })); +} + // I inserts at the first nonwhitespace character of each line with a selection fn prepend_to_line(cx: &mut Context) { goto_first_nonwhitespace(cx); @@ -3749,6 +3761,8 @@ macro_rules! mode_info { mode_info! { /// space mode space_mode, SPACE_MODE, + /// resume last picker + "'" => last_picker, /// file picker "f" => file_picker, /// buffer picker diff --git a/helix-term/src/compositor.rs b/helix-term/src/compositor.rs index 5fcb552a9..c2cfa3a72 100644 --- a/helix-term/src/compositor.rs +++ b/helix-term/src/compositor.rs @@ -74,6 +74,8 @@ type Terminal = tui::terminal::Terminal>; pub struct Compositor { layers: Vec>, terminal: Terminal, + + pub(crate) last_picker: Option>, } impl Compositor { @@ -83,6 +85,7 @@ impl Compositor { Ok(Self { layers: Vec::new(), terminal, + last_picker: None, }) } @@ -103,8 +106,8 @@ impl Compositor { self.layers.push(layer); } - pub fn pop(&mut self) { - self.layers.pop(); + pub fn pop(&mut self) -> Option> { + self.layers.pop() } pub fn handle_event(&mut self, event: Event, cx: &mut Context) -> bool { diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index d7fc9d866..733be2fc6 100644 --- a/helix-term/src/ui/picker.rs +++ b/helix-term/src/ui/picker.rs @@ -159,7 +159,7 @@ impl Component for Picker { let close_fn = EventResult::Consumed(Some(Box::new(|compositor: &mut Compositor| { // remove the layer - compositor.pop(); + compositor.last_picker = compositor.pop(); }))); match key_event { From d4bd5b37669708361a0a6cd2917464b010e6b7f5 Mon Sep 17 00:00:00 2001 From: fossdd Date: Thu, 22 Jul 2021 12:50:11 +0000 Subject: [PATCH 3/9] The item `fmt` was imported redundantly Fixed warning: ``` warning: the item `fmt` is imported redundantly --> helix-core/src/syntax.rs:98:9 | 16 | fmt, | --- the item `fmt` is already imported here ... 98 | use std::fmt; | ^^^^^^^^ | ``` --- helix-core/src/syntax.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index 9acf3d879..14f36a0ad 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -95,7 +95,6 @@ fn load_runtime_file(language: &str, filename: &str) -> Result Result> { - use std::fmt; use std::path::PathBuf; #[derive(rust_embed::RustEmbed)] From 25103833b2dc5d6edf1beca396fa838294fc114a Mon Sep 17 00:00:00 2001 From: Shafkath Shuhan Date: Thu, 22 Jul 2021 18:24:58 -0400 Subject: [PATCH 4/9] mark reloaded buffers as unchanged --- helix-view/src/document.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 8fdf7d989..c751785d5 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -611,6 +611,7 @@ impl Document { let transaction = helix_core::diff::compare_ropes(self.text(), &rope); self.apply(&transaction, view_id); self.append_changes_to_history(view_id); + self.reset_modified(); // Detect indentation style and set line ending. self.detect_indent_style(); From 58d08d36ae6a2c6efbf175247bb096fae6629eb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Fri, 23 Jul 2021 18:10:17 +0900 Subject: [PATCH 5/9] Simplify ui/menu.rs --- helix-term/src/ui/menu.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/helix-term/src/ui/menu.rs b/helix-term/src/ui/menu.rs index 8681e5b1c..dc3bbf7f0 100644 --- a/helix-term/src/ui/menu.rs +++ b/helix-term/src/ui/menu.rs @@ -233,16 +233,16 @@ impl Component for Menu { let max_lens = self.options.iter().fold(vec![0; n], |mut acc, option| { let row = option.row(); // maintain max for each column - for (i, cell) in row.cells.iter().enumerate() { + for (acc, cell) in acc.iter_mut().zip(row.cells.iter()) { let width = cell.content.width(); - if width > acc[i] { - acc[i] = width; + if width > *acc { + *acc = width; } } acc }); - let len = (max_lens.iter().sum::()) + n + 1; // +1: reserve some space for scrollbar + let len = max_lens.iter().sum::() + n + 1; // +1: reserve some space for scrollbar let width = len.min(viewport.0 as usize); self.widths = max_lens @@ -250,9 +250,7 @@ impl Component for Menu { .map(|len| Constraint::Length(len as u16)) .collect(); - const MAX: usize = 10; - let height = std::cmp::min(self.options.len(), MAX); - let height = std::cmp::min(height, viewport.1 as usize); + let height = self.options.len().min(10).min(viewport.1 as usize); self.size = (width as u16, height as u16); From 817a7e0bd68c2430e5dcb7b6c612043329a62231 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Fri, 23 Jul 2021 18:10:30 +0900 Subject: [PATCH 6/9] fix: Only try expanding directory completion if it makes sense Fixes #487 --- helix-term/src/ui/prompt.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-term/src/ui/prompt.rs b/helix-term/src/ui/prompt.rs index a4cb26f7c..2df1e281f 100644 --- a/helix-term/src/ui/prompt.rs +++ b/helix-term/src/ui/prompt.rs @@ -463,7 +463,7 @@ impl Component for Prompt { code: KeyCode::Enter, .. } => { - if self.line.ends_with('/') { + if self.selection.is_some() && self.line.ends_with('/') { self.completion = (self.completion_fn)(&self.line); self.exit_selection(); } else { From e5d438705b3554c078adbe99cc64323967ff2406 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Fri, 23 Jul 2021 18:11:22 +0900 Subject: [PATCH 7/9] Add rustfmt.toml to force formatting to use rustfmt defaults Closes #480 --- rustfmt.toml | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 rustfmt.toml diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 000000000..e69de29bb From 1789dfabfe68c00dda3b861b828ea7a50860f6e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Fri, 23 Jul 2021 18:12:33 +0900 Subject: [PATCH 8/9] fix: ui/menu: Don't allow scrolling past the end of completion Fixes #472 --- helix-term/src/ui/menu.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/helix-term/src/ui/menu.rs b/helix-term/src/ui/menu.rs index dc3bbf7f0..5a6f6256a 100644 --- a/helix-term/src/ui/menu.rs +++ b/helix-term/src/ui/menu.rs @@ -90,13 +90,13 @@ impl Menu { pub fn move_up(&mut self) { // TODO: wrap around to end - let pos = self.cursor.map_or(0, |i| i.saturating_sub(1)) % self.options.len(); + let pos = self.cursor.map_or(0, |i| i.saturating_sub(1)) % self.matches.len(); self.cursor = Some(pos); self.adjust_scroll(); } pub fn move_down(&mut self) { - let pos = self.cursor.map_or(0, |i| i + 1) % self.options.len(); + let pos = self.cursor.map_or(0, |i| i + 1) % self.matches.len(); self.cursor = Some(pos); self.adjust_scroll(); } From bda4f5c1cdd2f84a06647f7dce45a8f6d06401ae Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Fri, 23 Jul 2021 17:02:42 +0800 Subject: [PATCH 9/9] Simplify replace dashes with underscore --- helix-syntax/src/lib.rs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/helix-syntax/src/lib.rs b/helix-syntax/src/lib.rs index b6c0ecf35..b0ec48d82 100644 --- a/helix-syntax/src/lib.rs +++ b/helix-syntax/src/lib.rs @@ -3,15 +3,7 @@ use libloading::{Library, Symbol}; use tree_sitter::Language; fn replace_dashes_with_underscores(name: &str) -> String { - let mut result = String::with_capacity(name.len()); - for c in name.chars() { - if c == '-' { - result.push('_'); - } else { - result.push(c); - } - } - result + name.replace('-', "_") } #[cfg(unix)] const DYLIB_EXTENSION: &str = "so";