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,
};
let mut doc_line = Some(pos.doc_line);
let mut doc_line = pos.doc_line;
if let Some(current_context) = context
.as_ref()
.and_then(|c| c.iter().find(|n| n.visual_line == pos.visual_line))
{
doc_line = if current_context.indicator.is_some() {
None
} else {
Some(current_context.line)
doc_line = match current_context.indicator {
Some(_) => return,
None => current_context.line,
};
}
@ -926,22 +925,23 @@ impl EditorView {
query_match
.nodes_for_capture_index(start_index)
.flat_map(move |context| {
end_nodes
.clone()
.into_iter()
.filter(move |it| {
let start_range = context.byte_range();
let end = it.start_byte();
start_range.contains(&end)
end_nodes.clone().into_iter().filter_map(move |it| {
let start_range = context.byte_range();
let end = it.start_byte();
if start_range.contains(&end)
&& start_range.contains(&top_first_byte)
&& start_range.contains(&last_scan_byte)
// only match @context.end nodes that aren't at the end of the line
&& context.start_position().row != it.start_position().row
})
// 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
.map(move |it| context.start_byte()..it.start_byte().saturating_sub(1))
{
Some(context.start_byte()..it.start_byte().saturating_sub(1))
} else {
None
}
})
// 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()
}

@ -13,8 +13,7 @@ fn count_digits(n: usize) -> usize {
std::iter::successors(Some(n), |&n| (n >= 10).then_some(n / 10)).count()
}
pub type GutterFn<'doc> =
Box<dyn FnMut(Option<usize>, bool, bool, &mut String) -> Option<Style> + 'doc>;
pub type GutterFn<'doc> = Box<dyn FnMut(usize, bool, bool, &mut String) -> Option<Style> + 'doc>;
pub type Gutter =
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;
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 {
return None;
}
let line = line?;
use helix_core::diagnostic::Severity;
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..]
@ -104,7 +102,7 @@ pub fn diff<'doc>(
let mut hunk_i = 0;
let mut hunk = hunks.nth_hunk(hunk_i);
Box::new(
move |line: Option<usize>,
move |line: usize,
_selected: bool,
first_visual_line: bool,
out: &mut String| {
@ -113,7 +111,6 @@ pub fn diff<'doc>(
// we need to special case removals here
// 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
let line = line?;
while hunk.after.end < line as u32
|| !hunk.is_pure_removal() && line as u32 == hunk.after.end
@ -173,8 +170,7 @@ pub fn line_numbers<'doc>(
let mode = editor.mode;
Box::new(
move |line: Option<usize>, selected: bool, first_visual_line: bool, out: &mut String| {
let line = line?;
move |line: usize, selected: bool, first_visual_line: bool, out: &mut String| {
if line == last_line_in_view && !draw_last {
write!(out, "{:>1$}", '~', width).unwrap();
Some(linenr)
@ -233,7 +229,7 @@ pub fn padding<'doc>(
_is_focused: bool,
) -> GutterFn<'doc> {
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(
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 {
return None;
}
let line = line?;
let breakpoint = breakpoints
.iter()
.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();
Box::new(
move |line: Option<usize>, _selected: bool, first_visual_line: bool, out: &mut String| {
let line = line?;
move |line: usize, _selected: bool, first_visual_line: bool, out: &mut String| {
if !first_visual_line
|| !is_focused
|| line != frame_line?

Loading…
Cancel
Save