From 26c22de1d07cd77183526fac6c661262f4fcf70b Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+nikitarevenco@users.noreply.github.com> Date: Thu, 7 Nov 2024 14:46:30 +0000 Subject: [PATCH] style: format files --- helix-term/src/commands.rs | 14 ++++++++++--- helix-term/src/commands/typed.rs | 2 +- helix-term/src/ui/editor.rs | 25 ++++++++++++++++++++--- helix-term/src/ui/mod.rs | 6 +++++- helix-term/src/ui/statusline.rs | 9 +++++++-- helix-view/src/editor.rs | 7 ++++++- helix-view/src/view.rs | 34 +++++++++++++++++++++++++------- 7 files changed, 79 insertions(+), 18 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index db227eff1..f39c2a451 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -679,7 +679,7 @@ fn move_impl(cx: &mut Context, move_fn: MoveFn, dir: Direction, behaviour: Movem let config = cx.editor.config(); let (view, doc) = current!(cx.editor); let unobtrusive_statusline = config.statusline.unobtrusive; - + let text = doc.text().slice(..); let text_fmt = doc.text_format(view.inner_area(doc, unobtrusive_statusline).width, None); let mut annotations = view.text_annotations(doc, None); @@ -3106,7 +3106,11 @@ fn jumplist_picker(cx: &mut Context) { let (view, doc) = (view_mut!(cx.editor), doc_mut!(cx.editor, &meta.id)); doc.set_selection(view.id, meta.selection.clone()); if action.align_view(view, doc.id()) { - view.ensure_cursor_in_view_center(doc, config.scrolloff, config.statusline.unobtrusive); + view.ensure_cursor_in_view_center( + doc, + config.scrolloff, + config.statusline.unobtrusive, + ); } }, ) @@ -3282,7 +3286,11 @@ pub fn command_palette(cx: &mut Context) { let view = view_mut!(ctx.editor, focus); let doc = doc_mut!(ctx.editor, &view.doc); - view.ensure_cursor_in_view(doc, config.scrolloff, config.statusline.unobtrusive); + view.ensure_cursor_in_view( + doc, + config.scrolloff, + config.statusline.unobtrusive, + ); if mode != Mode::Insert { doc.append_changes_to_history(view); diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index e1d10feff..22195f141 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -1803,7 +1803,7 @@ fn tutor( fn abort_goto_line_number_preview(cx: &mut compositor::Context) { if let Some(last_selection) = cx.editor.last_selection.take() { let config = cx.editor.config(); - + let scrolloff = config.scrolloff; let unobtrusive_statusline = config.statusline.unobtrusive; diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 0c17c4bd4..44fe9a8d0 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -104,7 +104,15 @@ impl EditorView { } if is_focused && config.cursorcolumn { - Self::highlight_cursorcolumn(doc, view, surface, theme, inner, &text_annotations, config.statusline.unobtrusive); + Self::highlight_cursorcolumn( + doc, + view, + surface, + theme, + inner, + &text_annotations, + config.statusline.unobtrusive, + ); } // Set DAP highlights, if needed. @@ -241,7 +249,12 @@ impl EditorView { let mut context = statusline::RenderContext::new(editor, doc, view, is_focused, &self.spinners); - statusline::render(&mut context, statusline_area, surface, unobtrusive_statusline); + statusline::render( + &mut context, + statusline_area, + surface, + unobtrusive_statusline, + ); } pub fn render_rulers( @@ -1196,7 +1209,13 @@ impl EditorView { MouseEventKind::Drag(MouseButton::Left) => { let (view, doc) = current!(cxt.editor); - let pos = match view.pos_at_screen_coords(doc, row, column, true, config.statusline.unobtrusive) { + let pos = match view.pos_at_screen_coords( + doc, + row, + column, + true, + config.statusline.unobtrusive, + ) { Some(pos) => pos, None => return EventResult::Ignored(None), }; diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index 888251732..98389418b 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -131,7 +131,11 @@ pub fn raw_regex_prompt( fun(cx, regex, input, event); let (view, doc) = current!(cx.editor); - view.ensure_cursor_in_view(doc, config.scrolloff, config.statusline.unobtrusive); + view.ensure_cursor_in_view( + doc, + config.scrolloff, + config.statusline.unobtrusive, + ); } Err(err) => { let (view, doc) = current!(cx.editor); diff --git a/helix-term/src/ui/statusline.rs b/helix-term/src/ui/statusline.rs index a20fde7ce..5fb99fa1a 100644 --- a/helix-term/src/ui/statusline.rs +++ b/helix-term/src/ui/statusline.rs @@ -49,7 +49,12 @@ pub struct RenderBuffer<'a> { pub right: Spans<'a>, } -pub fn render(context: &mut RenderContext, viewport: Rect, surface: &mut Surface, unobtrusive_statusline: bool) { +pub fn render( + context: &mut RenderContext, + viewport: Rect, + surface: &mut Surface, + unobtrusive_statusline: bool, +) { let base_style = if context.focused { context.editor.theme.get("ui.statusline") } else { @@ -59,7 +64,7 @@ pub fn render(context: &mut RenderContext, viewport: Rect, surface: &mut Surface let surface_style = if unobtrusive_statusline { let surface_bg = match base_style.bg { Some(color) => color, - None => helix_view::theme::Color::Reset + None => helix_view::theme::Color::Reset, }; Style::default().bg(surface_bg) } else { diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index b739e47ff..c3cd15ebc 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -2210,7 +2210,12 @@ fn try_restore_indent(doc: &mut Document, view: &mut View) { pub struct CursorCache(Cell>>); impl CursorCache { - pub fn get(&self, view: &View, doc: &Document, unobtrusive_statusline: bool) -> Option { + pub fn get( + &self, + view: &View, + doc: &Document, + unobtrusive_statusline: bool, + ) -> Option { if let Some(pos) = self.0.get() { return pos; } diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs index 88d3f3e3a..b755b07a6 100644 --- a/helix-view/src/view.rs +++ b/helix-view/src/view.rs @@ -207,7 +207,7 @@ impl View { self.area.clip_bottom(1).height.into() // -1 for statusline } } - + /// Does not account for height of statusline pub fn inner_area_raw(&self, doc: &Document) -> Rect { self.area.clip_left(self.gutter_offset(doc)) @@ -355,22 +355,42 @@ impl View { Some(offset) } - pub fn ensure_cursor_in_view(&self, doc: &mut Document, scrolloff: usize, unobtrusive_statusline: bool) { - if let Some(offset) = self.offset_coords_to_in_view_center::(doc, scrolloff, unobtrusive_statusline) { + pub fn ensure_cursor_in_view( + &self, + doc: &mut Document, + scrolloff: usize, + unobtrusive_statusline: bool, + ) { + if let Some(offset) = + self.offset_coords_to_in_view_center::(doc, scrolloff, unobtrusive_statusline) + { doc.set_view_offset(self.id, offset); } } - pub fn ensure_cursor_in_view_center(&self, doc: &mut Document, scrolloff: usize, unobtrusive_statusline: bool) { - if let Some(offset) = self.offset_coords_to_in_view_center::(doc, scrolloff, unobtrusive_statusline) { + pub fn ensure_cursor_in_view_center( + &self, + doc: &mut Document, + scrolloff: usize, + unobtrusive_statusline: bool, + ) { + if let Some(offset) = + self.offset_coords_to_in_view_center::(doc, scrolloff, unobtrusive_statusline) + { doc.set_view_offset(self.id, offset); } else { align_view(doc, self, Align::Center, unobtrusive_statusline); } } - pub fn is_cursor_in_view(&mut self, doc: &Document, scrolloff: usize, unobtrusive_statusline: bool) -> bool { - self.offset_coords_to_in_view(doc, scrolloff, unobtrusive_statusline).is_none() + pub fn is_cursor_in_view( + &mut self, + doc: &Document, + scrolloff: usize, + unobtrusive_statusline: bool, + ) -> bool { + self.offset_coords_to_in_view(doc, scrolloff, unobtrusive_statusline) + .is_none() } /// Estimates the last visible document line on screen.