render cursorline only in editing area

This commit is contained in:
Dreck Sallow 2024-10-27 13:25:03 -05:00
parent 101a74bf6e
commit 9dca2ee1c4

View File

@ -99,7 +99,7 @@ pub fn render_view(
let mut decorations = DecorationManager::default();
if is_focused && config.cursorline {
decorations.add_decoration(Self::cursorline(doc, view, theme));
decorations.add_decoration(Self::cursorline(doc, view, inner, theme));
}
if is_focused && config.cursorcolumn {
@ -773,7 +773,12 @@ pub fn render_diagnostics(
}
/// Apply the highlighting on the lines where a cursor is active
pub fn cursorline(doc: &Document, view: &View, theme: &Theme) -> impl Decoration {
pub fn cursorline(
doc: &Document,
view: &View,
inner_area: Rect,
theme: &Theme,
) -> impl Decoration {
let text = doc.text().slice(..);
// TODO only highlight the visual line that contains the cursor instead of the full visual line
let primary_line = doc.selection(view.id).primary().cursor_line(text);
@ -792,10 +797,9 @@ pub fn cursorline(doc: &Document, view: &View, theme: &Theme) -> impl Decoration
let primary_style = theme.get("ui.cursorline.primary");
let secondary_style = theme.get("ui.cursorline.secondary");
let viewport = view.area;
move |renderer: &mut TextRenderer, pos: LinePos| {
let area = Rect::new(viewport.x, pos.visual_line, viewport.width, 1);
let area = Rect::new(inner_area.x, pos.visual_line, inner_area.width, 1);
if primary_line == pos.doc_line {
renderer.set_style(area, primary_style);
} else if secondary_lines.binary_search(&pos.doc_line).is_ok() {