aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src
diff options
context:
space:
mode:
Diffstat (limited to 'helix-term/src')
-rw-r--r--helix-term/src/application.rs2
-rw-r--r--helix-term/src/commands.rs17
-rw-r--r--helix-term/src/main.rs2
-rw-r--r--helix-term/src/ui/editor.rs6
-rw-r--r--helix-term/src/ui/menu.rs4
-rw-r--r--helix-term/src/ui/mod.rs5
-rw-r--r--helix-term/src/ui/prompt.rs9
7 files changed, 18 insertions, 27 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs
index 2a813081..53fd086b 100644
--- a/helix-term/src/application.rs
+++ b/helix-term/src/application.rs
@@ -122,7 +122,7 @@ impl Application {
pub fn handle_terminal_events(&mut self, event: Option<Result<Event, crossterm::ErrorKind>>) {
let mut cx = crate::compositor::Context {
editor: &mut self.editor,
- executor: &self.executor,
+ executor: self.executor,
callbacks: &mut self.callbacks,
scroll: None,
};
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 844cb429..9da65813 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -14,6 +14,7 @@ use crate::{
ui::{self, Completion, Picker, Popup, Prompt, PromptEvent},
};
+use std::borrow::Cow;
use std::path::{Path, PathBuf};
use helix_view::{
@@ -333,7 +334,7 @@ where
let text = doc.text().slice(..);
let selection = doc.selection(view_id).transform(|mut range| {
- if let Some(pos) = search::find_nth_next(text, ch, range.head, count, inclusive) {
+ search::find_nth_next(text, ch, range.head, count, inclusive).map_or(range, |pos| {
if extend {
Range::new(range.anchor, pos)
} else {
@@ -341,9 +342,7 @@ where
Range::new(range.head, pos)
}
// or (pos, pos) to move to found val
- } else {
- range
- }
+ })
});
doc.set_selection(view_id, selection);
@@ -642,7 +641,7 @@ fn _search(doc: &mut Document, view_id: ViewId, contents: &str, regex: &Regex) {
let start = doc.selection(view_id).cursor();
// TODO: use find_at to find the next match after the cursor, loop around the end
- if let Some(mat) = regex.find_at(&contents, start) {
+ if let Some(mat) = regex.find_at(contents, start) {
let start = text.byte_to_char(mat.start());
let end = text.byte_to_char(mat.end());
let selection = Selection::single(start, end - 1);
@@ -859,15 +858,15 @@ pub fn command_mode(cx: &mut Context) {
let parts = input.split_ascii_whitespace().collect::<Vec<&str>>();
match *parts.as_slice() {
- ["q"] | ["quit"] => {
+ ["q" | "quit"] => {
editor.close(editor.view().id);
// editor.should_close = true,
}
- ["o", path] | ["open", path] => {
+ ["o" | "open", path] => {
use helix_view::editor::Action;
editor.open(path.into(), Action::Replace);
}
- ["w"] | ["write"] => {
+ ["w" | "write"] => {
// TODO: non-blocking via save() command
let id = editor.view().doc;
let doc = &mut editor.documents[id];
@@ -1487,7 +1486,7 @@ pub fn yank(cx: &mut Context) {
let values: Vec<String> = doc
.selection(view_id)
.fragments(doc.text().slice(..))
- .map(|cow| cow.into_owned())
+ .map(Cow::into_owned)
.collect();
// TODO: allow specifying reg
diff --git a/helix-term/src/main.rs b/helix-term/src/main.rs
index dc6f31f4..33792947 100644
--- a/helix-term/src/main.rs
+++ b/helix-term/src/main.rs
@@ -77,7 +77,7 @@ fn main() {
use helix_core::syntax::{Loader, LOADER};
let toml = include_str!("../../languages.toml");
LOADER.get_or_init(|| {
- let config = toml::from_str(&toml).expect("Could not parse languages.toml");
+ let config = toml::from_str(toml).expect("Could not parse languages.toml");
Loader::new(config)
});
diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs
index 7ceeb6ca..d0822500 100644
--- a/helix-term/src/ui/editor.rs
+++ b/helix-term/src/ui/editor.rs
@@ -58,13 +58,13 @@ impl EditorView {
viewport.width - OFFSET,
viewport.height.saturating_sub(1),
); // - 1 for statusline
- self.render_buffer(&doc, view, area, surface, theme, is_focused);
+ self.render_buffer(doc, view, area, surface, theme, is_focused);
// clear with background color
// TODO: this seems to prevent setting style later
// surface.set_style(viewport, theme.get("ui.background"));
- self.render_diagnostics(&doc, view, area, surface, theme, is_focused);
+ self.render_diagnostics(doc, view, area, surface, theme, is_focused);
let area = Rect::new(
viewport.x,
@@ -72,7 +72,7 @@ impl EditorView {
viewport.width,
1,
);
- self.render_statusline(&doc, area, surface, theme, is_focused);
+ self.render_statusline(doc, area, surface, theme, is_focused);
// render status
if let Some(status_msg) = &self.status_msg {
diff --git a/helix-term/src/ui/menu.rs b/helix-term/src/ui/menu.rs
index 5c3ff654..fbd25a6d 100644
--- a/helix-term/src/ui/menu.rs
+++ b/helix-term/src/ui/menu.rs
@@ -90,13 +90,13 @@ impl<T> Menu<T> {
pub fn move_up(&mut self) {
// TODO: wrap around to end
- let pos = self.cursor.map(|i| i.saturating_sub(1)).unwrap_or(0) % self.options.len();
+ let pos = self.cursor.map_or(0, |i| i.saturating_sub(1)) % self.options.len();
self.cursor = Some(pos);
self.adjust_scroll();
}
pub fn move_down(&mut self) {
- let pos = self.cursor.map(|i| i + 1).unwrap_or(0) % self.options.len();
+ let pos = self.cursor.map_or(0, |i| i + 1) % self.options.len();
self.cursor = Some(pos);
self.adjust_scroll();
}
diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs
index 341a30e0..479e684a 100644
--- a/helix-term/src/ui/mod.rs
+++ b/helix-term/src/ui/mod.rs
@@ -149,10 +149,7 @@ pub mod completers {
.build()
.filter_map(|file| {
file.ok().map(|entry| {
- let is_dir = entry
- .file_type()
- .map(|entry| entry.is_dir())
- .unwrap_or(false);
+ let is_dir = entry.file_type().map_or(false, |entry| entry.is_dir());
let mut path = entry.path().strip_prefix(&dir).unwrap().to_path_buf();
diff --git a/helix-term/src/ui/prompt.rs b/helix-term/src/ui/prompt.rs
index c61f0bd1..3588853e 100644
--- a/helix-term/src/ui/prompt.rs
+++ b/helix-term/src/ui/prompt.rs
@@ -81,8 +81,7 @@ impl Prompt {
if self.completion.is_empty() {
return;
}
- let index =
- self.completion_selection_index.map(|i| i + 1).unwrap_or(0) % self.completion.len();
+ let index = self.completion_selection_index.map_or(0, |i| i + 1) % self.completion.len();
self.completion_selection_index = Some(index);
let (range, item) = &self.completion[index];
@@ -183,11 +182,7 @@ impl Component for Prompt {
// char or shift char
KeyEvent {
code: KeyCode::Char(c),
- modifiers: KeyModifiers::NONE,
- }
- | KeyEvent {
- code: KeyCode::Char(c),
- modifiers: KeyModifiers::SHIFT,
+ modifiers: KeyModifiers::NONE | KeyModifiers::SHIFT,
} => {
self.insert_char(c);
(self.callback_fn)(cx.editor, &self.line, PromptEvent::Update);