Fix broken offset calculation

Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de>
pull/6118/merge^2
Sora 11 months ago committed by GitHub
parent 1b3c5fee17
commit a7952e284c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -265,45 +265,42 @@ pub fn render_sticky_context(
// if the definition of the function contains multiple lines // if the definition of the function contains multiple lines
if node.has_context_end { if node.has_context_end {
let (whitespace_offset, _) = visual_offset_from_block( let line = text.byte_to_line(node.byte_range.end);
text, let line_start = text.line_to_char(line);
text.line_to_byte(text.byte_to_line(node.byte_range.end)), let anchor = text.byte_to_char(node.byte_range.end);
node.byte_range.end, // TODO: we could avoid this when text rendering supports starting at
&helix_core::doc_formatter::TextFormat::default(), // a byte/char offset (doesn't work because of syntax highlighting atm)
&TextAnnotations::default(), let Position { col: whitespace_offset, .. } = pos_at_visual_coords(
text.slice(line_start..),
anchor - line_start,
); );
let whitespace_offset = whitespace_offset.col as u16 + 1; // calculation of the correct space where the end of the signature
// calculation of the correct space on where the end of the signature
// should be drawn at // should be drawn at
let mut additional_area = line_context_area; let mut additional_area = line_context_area;
additional_area.x += additional_area.x +=(already_written + dots.len() as u16);
(already_written + dots.len() as u16).saturating_sub(whitespace_offset);
// render the end of the function definition // render the end of the function definition
let mut renderer = TextRenderer::new( let mut renderer = TextRenderer::new(
surface, surface,
doc, doc,
theme, theme,
view.offset.horizontal_offset, whitespace_offset as u16,
additional_area, additional_area,
); )
new_offset.anchor = text.byte_to_char(node.byte_range.end);
let highlights = EditorView::doc_syntax_highlights(doc, new_offset.anchor, 1, theme); let highlights = EditorView::doc_syntax_highlights(doc, new_offset.anchor, 1, theme);
let mut text_format = doc.text_format(additional_area.width.saturting_sub(already_written + dots.len() as u16), Some(theme));
let mut text_format = doc.text_format(additional_area.width, Some(theme));
text_format.soft_wrap = false; text_format.soft_wrap = false;
render_text( render_text(
&mut renderer, &mut renderer,
text, text,
new_offset, ViewPosition { anchor, .. ViewPosition::default() },
&text_format, &text_format,
&virtual_text_annotations, &virtual_text_annotations,
highlights, highlights,
theme, theme,
line_decoration, &mut [],
translated_positions, &mut [],
); );
// draw the "..." with the keyword.operator style // draw the "..." with the keyword.operator style

Loading…
Cancel
Save