style: format files

pull/12020/head
Nikita Revenco 2 weeks ago
parent 28e6509751
commit 26c22de1d0

@ -679,7 +679,7 @@ fn move_impl(cx: &mut Context, move_fn: MoveFn, dir: Direction, behaviour: Movem
let config = cx.editor.config(); let config = cx.editor.config();
let (view, doc) = current!(cx.editor); let (view, doc) = current!(cx.editor);
let unobtrusive_statusline = config.statusline.unobtrusive; let unobtrusive_statusline = config.statusline.unobtrusive;
let text = doc.text().slice(..); let text = doc.text().slice(..);
let text_fmt = doc.text_format(view.inner_area(doc, unobtrusive_statusline).width, None); let text_fmt = doc.text_format(view.inner_area(doc, unobtrusive_statusline).width, None);
let mut annotations = view.text_annotations(doc, 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)); let (view, doc) = (view_mut!(cx.editor), doc_mut!(cx.editor, &meta.id));
doc.set_selection(view.id, meta.selection.clone()); doc.set_selection(view.id, meta.selection.clone());
if action.align_view(view, doc.id()) { 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 view = view_mut!(ctx.editor, focus);
let doc = doc_mut!(ctx.editor, &view.doc); 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 { if mode != Mode::Insert {
doc.append_changes_to_history(view); doc.append_changes_to_history(view);

@ -1803,7 +1803,7 @@ fn tutor(
fn abort_goto_line_number_preview(cx: &mut compositor::Context) { fn abort_goto_line_number_preview(cx: &mut compositor::Context) {
if let Some(last_selection) = cx.editor.last_selection.take() { if let Some(last_selection) = cx.editor.last_selection.take() {
let config = cx.editor.config(); let config = cx.editor.config();
let scrolloff = config.scrolloff; let scrolloff = config.scrolloff;
let unobtrusive_statusline = config.statusline.unobtrusive; let unobtrusive_statusline = config.statusline.unobtrusive;

@ -104,7 +104,15 @@ impl EditorView {
} }
if is_focused && config.cursorcolumn { 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. // Set DAP highlights, if needed.
@ -241,7 +249,12 @@ impl EditorView {
let mut context = let mut context =
statusline::RenderContext::new(editor, doc, view, is_focused, &self.spinners); 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( pub fn render_rulers(
@ -1196,7 +1209,13 @@ impl EditorView {
MouseEventKind::Drag(MouseButton::Left) => { MouseEventKind::Drag(MouseButton::Left) => {
let (view, doc) = current!(cxt.editor); 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, Some(pos) => pos,
None => return EventResult::Ignored(None), None => return EventResult::Ignored(None),
}; };

@ -131,7 +131,11 @@ pub fn raw_regex_prompt(
fun(cx, regex, input, event); fun(cx, regex, input, event);
let (view, doc) = current!(cx.editor); 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) => { Err(err) => {
let (view, doc) = current!(cx.editor); let (view, doc) = current!(cx.editor);

@ -49,7 +49,12 @@ pub struct RenderBuffer<'a> {
pub right: Spans<'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 { let base_style = if context.focused {
context.editor.theme.get("ui.statusline") context.editor.theme.get("ui.statusline")
} else { } else {
@ -59,7 +64,7 @@ pub fn render(context: &mut RenderContext, viewport: Rect, surface: &mut Surface
let surface_style = if unobtrusive_statusline { let surface_style = if unobtrusive_statusline {
let surface_bg = match base_style.bg { let surface_bg = match base_style.bg {
Some(color) => color, Some(color) => color,
None => helix_view::theme::Color::Reset None => helix_view::theme::Color::Reset,
}; };
Style::default().bg(surface_bg) Style::default().bg(surface_bg)
} else { } else {

@ -2210,7 +2210,12 @@ fn try_restore_indent(doc: &mut Document, view: &mut View) {
pub struct CursorCache(Cell<Option<Option<Position>>>); pub struct CursorCache(Cell<Option<Option<Position>>>);
impl CursorCache { impl CursorCache {
pub fn get(&self, view: &View, doc: &Document, unobtrusive_statusline: bool) -> Option<Position> { pub fn get(
&self,
view: &View,
doc: &Document,
unobtrusive_statusline: bool,
) -> Option<Position> {
if let Some(pos) = self.0.get() { if let Some(pos) = self.0.get() {
return pos; return pos;
} }

@ -207,7 +207,7 @@ impl View {
self.area.clip_bottom(1).height.into() // -1 for statusline self.area.clip_bottom(1).height.into() // -1 for statusline
} }
} }
/// Does not account for height of statusline /// Does not account for height of statusline
pub fn inner_area_raw(&self, doc: &Document) -> Rect { pub fn inner_area_raw(&self, doc: &Document) -> Rect {
self.area.clip_left(self.gutter_offset(doc)) self.area.clip_left(self.gutter_offset(doc))
@ -355,22 +355,42 @@ impl View {
Some(offset) Some(offset)
} }
pub fn ensure_cursor_in_view(&self, doc: &mut Document, scrolloff: usize, unobtrusive_statusline: bool) { pub fn ensure_cursor_in_view(
if let Some(offset) = self.offset_coords_to_in_view_center::<false>(doc, scrolloff, unobtrusive_statusline) { &self,
doc: &mut Document,
scrolloff: usize,
unobtrusive_statusline: bool,
) {
if let Some(offset) =
self.offset_coords_to_in_view_center::<false>(doc, scrolloff, unobtrusive_statusline)
{
doc.set_view_offset(self.id, offset); doc.set_view_offset(self.id, offset);
} }
} }
pub fn ensure_cursor_in_view_center(&self, doc: &mut Document, scrolloff: usize, unobtrusive_statusline: bool) { pub fn ensure_cursor_in_view_center(
if let Some(offset) = self.offset_coords_to_in_view_center::<true>(doc, scrolloff, unobtrusive_statusline) { &self,
doc: &mut Document,
scrolloff: usize,
unobtrusive_statusline: bool,
) {
if let Some(offset) =
self.offset_coords_to_in_view_center::<true>(doc, scrolloff, unobtrusive_statusline)
{
doc.set_view_offset(self.id, offset); doc.set_view_offset(self.id, offset);
} else { } else {
align_view(doc, self, Align::Center, unobtrusive_statusline); align_view(doc, self, Align::Center, unobtrusive_statusline);
} }
} }
pub fn is_cursor_in_view(&mut self, doc: &Document, scrolloff: usize, unobtrusive_statusline: bool) -> bool { pub fn is_cursor_in_view(
self.offset_coords_to_in_view(doc, scrolloff, unobtrusive_statusline).is_none() &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. /// Estimates the last visible document line on screen.

Loading…
Cancel
Save