Apply basic suggestions

pull/6118/merge^2
SoraTenshi 11 months ago
parent 92d2067fe9
commit 9f4f0ce8a2

@ -654,15 +654,14 @@ impl EditorView {
(true, false) => gutter_selected_style_virtual, (true, false) => gutter_selected_style_virtual,
}; };
let mut doc_line = Some(pos.doc_line); let mut doc_line = pos.doc_line;
if let Some(current_context) = context if let Some(current_context) = context
.as_ref() .as_ref()
.and_then(|c| c.iter().find(|n| n.visual_line == pos.visual_line)) .and_then(|c| c.iter().find(|n| n.visual_line == pos.visual_line))
{ {
doc_line = if current_context.indicator.is_some() { doc_line = match current_context.indicator {
None Some(_) => return,
} else { None => current_context.line,
Some(current_context.line)
}; };
} }
@ -926,22 +925,23 @@ impl EditorView {
query_match query_match
.nodes_for_capture_index(start_index) .nodes_for_capture_index(start_index)
.flat_map(move |context| { .flat_map(move |context| {
end_nodes end_nodes.clone().into_iter().filter_map(move |it| {
.clone() let start_range = context.byte_range();
.into_iter() let end = it.start_byte();
.filter(move |it| { if start_range.contains(&end)
let start_range = context.byte_range();
let end = it.start_byte();
start_range.contains(&end)
&& start_range.contains(&top_first_byte) && start_range.contains(&top_first_byte)
&& start_range.contains(&last_scan_byte) && start_range.contains(&last_scan_byte)
// only match @context.end nodes that aren't at the end of the line // only match @context.end nodes that aren't at the end of the line
&& context.start_position().row != it.start_position().row && context.start_position().row != it.start_position().row
}) {
// in some cases, the start byte of a block is on the next line Some(context.start_byte()..it.start_byte().saturating_sub(1))
// which causes to show the actual first line of content instead of } else {
// the actual wanted "end of signature" line None
.map(move |it| context.start_byte()..it.start_byte().saturating_sub(1)) }
})
// in some cases, the start byte of a block is on the next line
// which causes to show the actual first line of content instead of
// the actual wanted "end of signature" line
}) })
.next() .next()
} }

@ -13,8 +13,7 @@ fn count_digits(n: usize) -> usize {
std::iter::successors(Some(n), |&n| (n >= 10).then_some(n / 10)).count() std::iter::successors(Some(n), |&n| (n >= 10).then_some(n / 10)).count()
} }
pub type GutterFn<'doc> = pub type GutterFn<'doc> = Box<dyn FnMut(usize, bool, bool, &mut String) -> Option<Style> + 'doc>;
Box<dyn FnMut(Option<usize>, bool, bool, &mut String) -> Option<Style> + 'doc>;
pub type Gutter = pub type Gutter =
for<'doc> fn(&'doc Editor, &'doc Document, &View, &Theme, bool, usize) -> GutterFn<'doc>; for<'doc> fn(&'doc Editor, &'doc Document, &View, &Theme, bool, usize) -> GutterFn<'doc>;
@ -61,11 +60,10 @@ pub fn diagnostic<'doc>(
let diagnostics = &doc.diagnostics; let diagnostics = &doc.diagnostics;
Box::new( Box::new(
move |line: Option<usize>, _selected: bool, first_visual_line: bool, out: &mut String| { move |line: usize, _selected: bool, first_visual_line: bool, out: &mut String| {
if !first_visual_line { if !first_visual_line {
return None; return None;
} }
let line = line?;
use helix_core::diagnostic::Severity; use helix_core::diagnostic::Severity;
let first_diag_idx_maybe_on_line = diagnostics.partition_point(|d| d.line < line); let first_diag_idx_maybe_on_line = diagnostics.partition_point(|d| d.line < line);
let diagnostics_on_line = diagnostics[first_diag_idx_maybe_on_line..] let diagnostics_on_line = diagnostics[first_diag_idx_maybe_on_line..]
@ -104,7 +102,7 @@ pub fn diff<'doc>(
let mut hunk_i = 0; let mut hunk_i = 0;
let mut hunk = hunks.nth_hunk(hunk_i); let mut hunk = hunks.nth_hunk(hunk_i);
Box::new( Box::new(
move |line: Option<usize>, move |line: usize,
_selected: bool, _selected: bool,
first_visual_line: bool, first_visual_line: bool,
out: &mut String| { out: &mut String| {
@ -113,7 +111,6 @@ pub fn diff<'doc>(
// we need to special case removals here // we need to special case removals here
// these technically do not have a range of lines to highlight (`hunk.after.start == hunk.after.end`). // these technically do not have a range of lines to highlight (`hunk.after.start == hunk.after.end`).
// However we still want to display these hunks correctly we must not yet skip to the next hunk here // However we still want to display these hunks correctly we must not yet skip to the next hunk here
let line = line?;
while hunk.after.end < line as u32 while hunk.after.end < line as u32
|| !hunk.is_pure_removal() && line as u32 == hunk.after.end || !hunk.is_pure_removal() && line as u32 == hunk.after.end
@ -173,8 +170,7 @@ pub fn line_numbers<'doc>(
let mode = editor.mode; let mode = editor.mode;
Box::new( Box::new(
move |line: Option<usize>, selected: bool, first_visual_line: bool, out: &mut String| { move |line: usize, selected: bool, first_visual_line: bool, out: &mut String| {
let line = line?;
if line == last_line_in_view && !draw_last { if line == last_line_in_view && !draw_last {
write!(out, "{:>1$}", '~', width).unwrap(); write!(out, "{:>1$}", '~', width).unwrap();
Some(linenr) Some(linenr)
@ -233,7 +229,7 @@ pub fn padding<'doc>(
_is_focused: bool, _is_focused: bool,
) -> GutterFn<'doc> { ) -> GutterFn<'doc> {
Box::new( Box::new(
|_line: Option<usize>, _selected: bool, _first_visual_line: bool, _out: &mut String| None, |_line: usize, _selected: bool, _first_visual_line: bool, _out: &mut String| None,
) )
} }
@ -265,11 +261,10 @@ pub fn breakpoints<'doc>(
}; };
Box::new( Box::new(
move |line: Option<usize>, _selected: bool, first_visual_line: bool, out: &mut String| { move |line: usize, _selected: bool, first_visual_line: bool, out: &mut String| {
if !first_visual_line { if !first_visual_line {
return None; return None;
} }
let line = line?;
let breakpoint = breakpoints let breakpoint = breakpoints
.iter() .iter()
.find(|breakpoint| breakpoint.line == line)?; .find(|breakpoint| breakpoint.line == line)?;
@ -310,8 +305,7 @@ fn execution_pause_indicator<'doc>(
doc.path().is_some() && frame_source_path.unwrap_or(None) == doc.path(); doc.path().is_some() && frame_source_path.unwrap_or(None) == doc.path();
Box::new( Box::new(
move |line: Option<usize>, _selected: bool, first_visual_line: bool, out: &mut String| { move |line: usize, _selected: bool, first_visual_line: bool, out: &mut String| {
let line = line?;
if !first_visual_line if !first_visual_line
|| !is_focused || !is_focused
|| line != frame_line? || line != frame_line?

Loading…
Cancel
Save