on master help sign in
Merge branch 'master' into great_line_ending_and_cursor_range_cleanup
commit43594049ddd6b0ec3794807016ab3cd2a6a38834 authorNathan Vegdahl <cessen@cessen.com> dateFri 23 Jul 2021, 17:23 (5 years ago) parent427ae6abda4f5c
10 files changed+32−25
helix-core/src/syntax.rs−1 helix-syntax/src/lib.rs+1−9 helix-term/src/commands.rs+14 helix-term/src/compositor.rs+5−2 helix-term/src/ui/menu.rs+7−9 helix-term/src/ui/picker.rs+1−1 helix-term/src/ui/prompt.rs+1−1 helix-view/src/document.rs+1 runtime/themes/dark_plus.toml+2−2 rustfmt.toml
helix-core/src/syntax.rs−1
@@ -95,7 +95,6 @@ fn load_runtime_file(language: &str, filename: &str) -> Result<String, std::io::
9595
9696#[cfg(feature = "embed_runtime")]
9797fn load_runtime_file(language: &str, filename: &str) -> Result<String, Box<dyn std::error::Error>> {
98− use std::fmt;
9998 use std::path::PathBuf;
10099
101100 #[derive(rust_embed::RustEmbed)]
helix-syntax/src/lib.rs+1−9
@@ -3,15 +3,7 @@ use libloading::{Library, Symbol};
33use tree_sitter::Language;
44
55fn replace_dashes_with_underscores(name: &str) -> String {
6− let mut result = String::with_capacity(name.len());
7− for c in name.chars() {
8− if c == '-' {
9− result.push('_');
10− } else {
11− result.push(c);
12− }
13− }
14− result
6+ name.replace('-', "_")
157}
168#[cfg(unix)]
179const DYLIB_EXTENSION: &str = "so";
helix-term/src/commands.rs+14
@@ -214,6 +214,7 @@ impl Command {
214214 file_picker,
215215 buffer_picker,
216216 symbol_picker,
217+ last_picker,
217218 prepend_to_line,
218219 append_to_line,
219220 open_below,
@@ -2127,6 +2128,17 @@ fn symbol_picker(cx: &mut Context) {
21272128 )
21282129}
21292130
2131+fn last_picker(cx: &mut Context) {
2132+ // TODO: last picker does not seemed to work well with buffer_picker
2133+ cx.callback = Some(Box::new(|compositor: &mut Compositor| {
2134+ if let Some(picker) = compositor.last_picker.take() {
2135+ compositor.push(picker);
2136+ }
2137+ // XXX: figure out how to show error when no last picker lifetime
2138+ // cx.editor.set_error("no last picker".to_owned())
2139+ }));
2140+}
2141+
21302142// I inserts at the first nonwhitespace character of each line with a selection
21312143fn prepend_to_line(cx: &mut Context) {
21322144 goto_first_nonwhitespace(cx);
@@ -3837,6 +3849,8 @@ macro_rules! mode_info {
38373849mode_info! {
38383850 /// space mode
38393851 space_mode, SPACE_MODE,
3852+ /// resume last picker
3853+ "'" => last_picker,
38403854 /// file picker
38413855 "f" => file_picker,
38423856 /// buffer picker
helix-term/src/compositor.rs+5−2
@@ -74,6 +74,8 @@ type Terminal = tui::terminal::Terminal<CrosstermBackend<std::io::Stdout>>;
7474pub struct Compositor {
7575 layers: Vec<Box<dyn Component>>,
7676 terminal: Terminal,
77+
78+ pub(crate) last_picker: Option<Box<dyn Component>>,
7779}
7880
7981impl Compositor {
@@ -83,6 +85,7 @@ impl Compositor {
8385 Ok(Self {
8486 layers: Vec::new(),
8587 terminal,
88+ last_picker: None,
8689 })
8790 }
8891
@@ -103,8 +106,8 @@ impl Compositor {
103106 self.layers.push(layer);
104107 }
105108
106− pub fn pop(&mut self) {
107− self.layers.pop();
109+ pub fn pop(&mut self) -> Option<Box<dyn Component>> {
110+ self.layers.pop()
108111 }
109112
110113 pub fn handle_event(&mut self, event: Event, cx: &mut Context) -> bool {
helix-term/src/ui/menu.rs+7−9
@@ -90,13 +90,13 @@ impl<T: Item> Menu<T> {
9090
9191 pub fn move_up(&mut self) {
9292 // TODO: wrap around to end
93− let pos = self.cursor.map_or(0, |i| i.saturating_sub(1)) % self.options.len();
93+ let pos = self.cursor.map_or(0, |i| i.saturating_sub(1)) % self.matches.len();
9494 self.cursor = Some(pos);
9595 self.adjust_scroll();
9696 }
9797
9898 pub fn move_down(&mut self) {
99− let pos = self.cursor.map_or(0, |i| i + 1) % self.options.len();
99+ let pos = self.cursor.map_or(0, |i| i + 1) % self.matches.len();
100100 self.cursor = Some(pos);
101101 self.adjust_scroll();
102102 }
@@ -233,16 +233,16 @@ impl<T: Item + 'static> Component for Menu<T> {
233233 let max_lens = self.options.iter().fold(vec![0; n], |mut acc, option| {
234234 let row = option.row();
235235 // maintain max for each column
236− for (i, cell) in row.cells.iter().enumerate() {
236+ for (acc, cell) in acc.iter_mut().zip(row.cells.iter()) {
237237 let width = cell.content.width();
238− if width > acc[i] {
239− acc[i] = width;
238+ if width > *acc {
239+ *acc = width;
240240 }
241241 }
242242
243243 acc
244244 });
245− let len = (max_lens.iter().sum::<usize>()) + n + 1; // +1: reserve some space for scrollbar
245+ let len = max_lens.iter().sum::<usize>() + n + 1; // +1: reserve some space for scrollbar
246246 let width = len.min(viewport.0 as usize);
247247
248248 self.widths = max_lens
@@ -250,9 +250,7 @@ impl<T: Item + 'static> Component for Menu<T> {
250250 .map(|len| Constraint::Length(len as u16))
251251 .collect();
252252
253− const MAX: usize = 10;
254− let height = std::cmp::min(self.options.len(), MAX);
255− let height = std::cmp::min(height, viewport.1 as usize);
253+ let height = self.options.len().min(10).min(viewport.1 as usize);
256254
257255 self.size = (width as u16, height as u16);
258256
helix-term/src/ui/picker.rs+1−1
@@ -159,7 +159,7 @@ impl<T: 'static> Component for Picker<T> {
159159
160160 let close_fn = EventResult::Consumed(Some(Box::new(|compositor: &mut Compositor| {
161161 // remove the layer
162− compositor.pop();
162+ compositor.last_picker = compositor.pop();
163163 })));
164164
165165 match key_event {
helix-term/src/ui/prompt.rs+1−1
@@ -463,7 +463,7 @@ impl Component for Prompt {
463463 code: KeyCode::Enter,
464464 ..
465465 } => {
466− if self.line.ends_with('/') {
466+ if self.selection.is_some() && self.line.ends_with('/') {
467467 self.completion = (self.completion_fn)(&self.line);
468468 self.exit_selection();
469469 } else {
helix-view/src/document.rs+1
@@ -596,6 +596,7 @@ impl Document {
596596 let transaction = helix_core::diff::compare_ropes(self.text(), &rope);
597597 self.apply(&transaction, view_id);
598598 self.append_changes_to_history(view_id);
599+ self.reset_modified();
599600
600601 // Detect indentation style and line ending.
601602 self.detect_indent_style();
runtime/themes/dark_plus.toml+2−2
@@ -46,10 +46,10 @@
4646
4747"ui.cursor" = { fg = "cursor", modifiers = ["reversed"] }
4848"ui.cursor.primary" = { fg = "cursor", modifiers = ["reversed"] }
49−"ui.cursor.match" = { fg = "cursor", modifiers = ['underlined'] }
49+"ui.cursor.match" = { bg = "#3a3d41", modifiers = ["underlined"] }
5050
5151"ui.selection" = { bg = "#3a3d41" }
52−"ui.selection.primary" = { bg = "#add6ff26" }
52+"ui.selection.primary" = { bg = "#264f78" }
5353
5454"ui.linenr" = { fg = "#858585" }
5555"ui.linenr.selected" = { fg = "#c6c6c6" }
rustfmt.tomlnew file

No changes to the content.