Merge branch 'master' into great_line_ending_and_cursor_range_cleanup

pull/376/head
Nathan Vegdahl 3 years ago
commit 43594049dd

@ -95,7 +95,6 @@ fn load_runtime_file(language: &str, filename: &str) -> Result<String, std::io::
#[cfg(feature = "embed_runtime")] #[cfg(feature = "embed_runtime")]
fn load_runtime_file(language: &str, filename: &str) -> Result<String, Box<dyn std::error::Error>> { fn load_runtime_file(language: &str, filename: &str) -> Result<String, Box<dyn std::error::Error>> {
use std::fmt;
use std::path::PathBuf; use std::path::PathBuf;
#[derive(rust_embed::RustEmbed)] #[derive(rust_embed::RustEmbed)]

@ -3,15 +3,7 @@ use libloading::{Library, Symbol};
use tree_sitter::Language; use tree_sitter::Language;
fn replace_dashes_with_underscores(name: &str) -> String { fn replace_dashes_with_underscores(name: &str) -> String {
let mut result = String::with_capacity(name.len()); name.replace('-', "_")
for c in name.chars() {
if c == '-' {
result.push('_');
} else {
result.push(c);
}
}
result
} }
#[cfg(unix)] #[cfg(unix)]
const DYLIB_EXTENSION: &str = "so"; const DYLIB_EXTENSION: &str = "so";

@ -214,6 +214,7 @@ impl Command {
file_picker, file_picker,
buffer_picker, buffer_picker,
symbol_picker, symbol_picker,
last_picker,
prepend_to_line, prepend_to_line,
append_to_line, append_to_line,
open_below, open_below,
@ -2127,6 +2128,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 // I inserts at the first nonwhitespace character of each line with a selection
fn prepend_to_line(cx: &mut Context) { fn prepend_to_line(cx: &mut Context) {
goto_first_nonwhitespace(cx); goto_first_nonwhitespace(cx);
@ -3837,6 +3849,8 @@ macro_rules! mode_info {
mode_info! { mode_info! {
/// space mode /// space mode
space_mode, SPACE_MODE, space_mode, SPACE_MODE,
/// resume last picker
"'" => last_picker,
/// file picker /// file picker
"f" => file_picker, "f" => file_picker,
/// buffer picker /// buffer picker

@ -74,6 +74,8 @@ type Terminal = tui::terminal::Terminal<CrosstermBackend<std::io::Stdout>>;
pub struct Compositor { pub struct Compositor {
layers: Vec<Box<dyn Component>>, layers: Vec<Box<dyn Component>>,
terminal: Terminal, terminal: Terminal,
pub(crate) last_picker: Option<Box<dyn Component>>,
} }
impl Compositor { impl Compositor {
@ -83,6 +85,7 @@ impl Compositor {
Ok(Self { Ok(Self {
layers: Vec::new(), layers: Vec::new(),
terminal, terminal,
last_picker: None,
}) })
} }
@ -103,8 +106,8 @@ impl Compositor {
self.layers.push(layer); self.layers.push(layer);
} }
pub fn pop(&mut self) { pub fn pop(&mut self) -> Option<Box<dyn Component>> {
self.layers.pop(); self.layers.pop()
} }
pub fn handle_event(&mut self, event: Event, cx: &mut Context) -> bool { pub fn handle_event(&mut self, event: Event, cx: &mut Context) -> bool {

@ -90,13 +90,13 @@ impl<T: Item> Menu<T> {
pub fn move_up(&mut self) { pub fn move_up(&mut self) {
// TODO: wrap around to end // 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.cursor = Some(pos);
self.adjust_scroll(); self.adjust_scroll();
} }
pub fn move_down(&mut self) { 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.cursor = Some(pos);
self.adjust_scroll(); self.adjust_scroll();
} }
@ -233,16 +233,16 @@ impl<T: Item + 'static> Component for Menu<T> {
let max_lens = self.options.iter().fold(vec![0; n], |mut acc, option| { let max_lens = self.options.iter().fold(vec![0; n], |mut acc, option| {
let row = option.row(); let row = option.row();
// maintain max for each column // 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(); let width = cell.content.width();
if width > acc[i] { if width > *acc {
acc[i] = width; *acc = width;
} }
} }
acc acc
}); });
let len = (max_lens.iter().sum::<usize>()) + n + 1; // +1: reserve some space for scrollbar let len = max_lens.iter().sum::<usize>() + n + 1; // +1: reserve some space for scrollbar
let width = len.min(viewport.0 as usize); let width = len.min(viewport.0 as usize);
self.widths = max_lens self.widths = max_lens
@ -250,9 +250,7 @@ impl<T: Item + 'static> Component for Menu<T> {
.map(|len| Constraint::Length(len as u16)) .map(|len| Constraint::Length(len as u16))
.collect(); .collect();
const MAX: usize = 10; let height = self.options.len().min(10).min(viewport.1 as usize);
let height = std::cmp::min(self.options.len(), MAX);
let height = std::cmp::min(height, viewport.1 as usize);
self.size = (width as u16, height as u16); self.size = (width as u16, height as u16);

@ -159,7 +159,7 @@ impl<T: 'static> Component for Picker<T> {
let close_fn = EventResult::Consumed(Some(Box::new(|compositor: &mut Compositor| { let close_fn = EventResult::Consumed(Some(Box::new(|compositor: &mut Compositor| {
// remove the layer // remove the layer
compositor.pop(); compositor.last_picker = compositor.pop();
}))); })));
match key_event { match key_event {

@ -463,7 +463,7 @@ impl Component for Prompt {
code: KeyCode::Enter, 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.completion = (self.completion_fn)(&self.line);
self.exit_selection(); self.exit_selection();
} else { } else {

@ -596,6 +596,7 @@ impl Document {
let transaction = helix_core::diff::compare_ropes(self.text(), &rope); let transaction = helix_core::diff::compare_ropes(self.text(), &rope);
self.apply(&transaction, view_id); self.apply(&transaction, view_id);
self.append_changes_to_history(view_id); self.append_changes_to_history(view_id);
self.reset_modified();
// Detect indentation style and line ending. // Detect indentation style and line ending.
self.detect_indent_style(); self.detect_indent_style();

@ -46,10 +46,10 @@
"ui.cursor" = { fg = "cursor", modifiers = ["reversed"] } "ui.cursor" = { fg = "cursor", modifiers = ["reversed"] }
"ui.cursor.primary" = { 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" = { bg = "#3a3d41" }
"ui.selection.primary" = { bg = "#add6ff26" } "ui.selection.primary" = { bg = "#264f78" }
"ui.linenr" = { fg = "#858585" } "ui.linenr" = { fg = "#858585" }
"ui.linenr.selected" = { fg = "#c6c6c6" } "ui.linenr.selected" = { fg = "#c6c6c6" }

Loading…
Cancel
Save