From 4affa690840ddad4e738b4adff192864cfe5d3a7 Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Fri, 6 Dec 2024 17:16:58 +0000 Subject: [PATCH 01/21] feat: add invert method for Color --- helix-view/src/graphics.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/helix-view/src/graphics.rs b/helix-view/src/graphics.rs index a26823b97c03..edbe1bc9e68f 100644 --- a/helix-view/src/graphics.rs +++ b/helix-view/src/graphics.rs @@ -508,6 +508,23 @@ impl Style { self } + /// Inverts the background and foreground + /// + /// ## Examples + /// + /// ```rust + /// # use helix_view::graphics::{Color, Style}; + /// let style = Style::default().bg(Color::Blue).fg(Color::Red); + /// let inverted = Style::default().bg(Color::Red).fg(Color::Blue); + /// assert_eq!(style.invert(), inverted); + /// ``` + pub const fn invert(mut self) -> Style { + let bg = self.bg; + self.bg = self.fg; + self.fg = bg; + self + } + /// Changes the underline color. /// /// ## Examples From 13d53e8e0a2d474b57d9e1ead5f00e944e3e9c52 Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Fri, 6 Dec 2024 17:26:46 +0000 Subject: [PATCH 02/21] fix: use None for Style temporarily --- helix-term/src/commands.rs | 2 +- helix-term/src/commands/typed.rs | 6 +++--- helix-term/src/ui/mod.rs | 18 +++++++++--------- helix-term/src/ui/prompt.rs | 16 +++++++++------- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index d08148362e25..6331a254bd34 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -2164,7 +2164,7 @@ fn searcher(cx: &mut Context, direction: Direction) { completions .iter() .filter(|comp| comp.starts_with(input)) - .map(|comp| (0.., std::borrow::Cow::Owned(comp.clone()))) + .map(|comp| (0.., std::borrow::Cow::Owned(comp.clone()), None)) .collect() }, move |cx, regex, event| { diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 49864abb683e..5e34aeedbf93 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -3178,7 +3178,7 @@ pub(super) fn command_mode(cx: &mut Context) { false, ) .into_iter() - .map(|(name, _)| (0.., name.into())) + .map(|(name, _)| (0.., name.into(), None)) .collect() } else { // Otherwise, use the command's completer and the last shellword @@ -3197,13 +3197,13 @@ pub(super) fn command_mode(cx: &mut Context) { { completer(editor, word) .into_iter() - .map(|(range, file)| { + .map(|(range, file, style)| { let file = shellwords::escape(file); // offset ranges to input let offset = input.len() - word_len; let range = (range.start + offset)..; - (range, file) + (range, file, style) }) .collect() } else { diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index ab9b5392bace..f400a1dc4a7e 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -290,7 +290,7 @@ pub mod completers { fuzzy_match(input, names, true) .into_iter() - .map(|(name, _)| ((0..), name)) + .map(|(name, _)| ((0..), name, None)) .collect() } @@ -306,7 +306,7 @@ pub mod completers { fuzzy_match(input, names, false) .into_iter() - .map(|(name, _)| ((0..), name.into())) + .map(|(name, _)| ((0..), name.into(), None)) .collect() } @@ -336,7 +336,7 @@ pub mod completers { fuzzy_match(input, &*KEYS, false) .into_iter() - .map(|(name, _)| ((0..), name.into())) + .map(|(name, _)| ((0..), name.into(), None)) .collect() } @@ -371,7 +371,7 @@ pub mod completers { fuzzy_match(input, language_ids, false) .into_iter() - .map(|(name, _)| ((0..), name.to_owned().into())) + .map(|(name, _)| ((0..), name.to_owned().into(), None)) .collect() } @@ -387,7 +387,7 @@ pub mod completers { fuzzy_match(input, commands, false) .into_iter() - .map(|(name, _)| ((0..), name.to_owned().into())) + .map(|(name, _)| ((0..), name.to_owned().into(), None)) .collect() } @@ -511,13 +511,13 @@ pub mod completers { let range = (input.len().saturating_sub(file_name.len()))..; fuzzy_match(&file_name, files, true) .into_iter() - .map(|(name, _)| (range.clone(), name)) + .map(|(name, _)| (range.clone(), name, None)) .collect() // TODO: complete to longest common match } else { - let mut files: Vec<_> = files.map(|file| (end.clone(), file)).collect(); - files.sort_unstable_by(|(_, path1), (_, path2)| path1.cmp(path2)); + let mut files: Vec<_> = files.map(|file| (end.clone(), file, None)).collect(); + files.sort_unstable_by(|(_, path1, _), (_, path2, _)| path1.cmp(path2)); files } } @@ -532,7 +532,7 @@ pub mod completers { fuzzy_match(input, iter, false) .into_iter() - .map(|(name, _)| ((0..), name.into())) + .map(|(name, _)| ((0..), name.into(), None)) .collect() } } diff --git a/helix-term/src/ui/prompt.rs b/helix-term/src/ui/prompt.rs index 1e443ce7ff0e..5cb7063e5837 100644 --- a/helix-term/src/ui/prompt.rs +++ b/helix-term/src/ui/prompt.rs @@ -5,6 +5,7 @@ use helix_core::syntax; use helix_view::document::Mode; use helix_view::input::KeyEvent; use helix_view::keyboard::KeyCode; +use helix_view::theme::Style; use std::sync::Arc; use std::{borrow::Cow, ops::RangeFrom}; use tui::buffer::Buffer as Surface; @@ -19,7 +20,8 @@ use helix_view::{ }; type PromptCharHandler = Box; -pub type Completion = (RangeFrom, Cow<'static, str>); + +pub type Completion = (RangeFrom, Cow<'static, str>, Option