Skip to content

Commit 0d68c14

Browse files
committed
Remove highlightinfo based smooth scrolling support
1 parent 2ded8e2 commit 0d68c14

File tree

6 files changed

+8
-171
lines changed

6 files changed

+8
-171
lines changed

src/bridge/api_info.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ pub struct ApiInformation {
178178
}
179179

180180
impl ApiInformation {
181+
#[allow(dead_code)]
181182
pub fn has_event(&self, event_name: &str) -> bool {
182183
self.ui_events.iter().any(|event| event.name == event_name)
183184
}

src/bridge/events.rs

Lines changed: 2 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ use rmpv::Value;
99
use skia_safe::Color4f;
1010
use strum::AsRefStr;
1111

12-
use crate::editor::{
13-
Colors, CursorMode, CursorShape, HighlightInfo, HighlightKind, Style, UnderlineStyle,
14-
};
12+
use crate::editor::{Colors, CursorMode, CursorShape, Style, UnderlineStyle};
1513

1614
#[derive(Clone, Debug)]
1715
pub enum ParseError {
@@ -503,7 +501,7 @@ fn parse_default_colors(default_colors_arguments: Vec<Value>) -> Result<RedrawEv
503501
})
504502
}
505503

506-
fn parse_style(style_map: Value, info_array: Value) -> Result<Style> {
504+
fn parse_style(style_map: Value, _info_array: Value) -> Result<Style> {
507505
let attributes = parse_map(style_map)?;
508506

509507
let mut style = Style::new(Colors::new(None, None, None));
@@ -551,69 +549,9 @@ fn parse_style(style_map: Value, info_array: Value) -> Result<Style> {
551549
}
552550
}
553551

554-
style.infos = parse_array(info_array)?
555-
.into_iter()
556-
.map(parse_highlight_info)
557-
.collect::<Result<Vec<_>>>()?;
558-
559552
Ok(style)
560553
}
561554

562-
fn parse_highlight_info(info_map: Value) -> Result<HighlightInfo> {
563-
let attributes = parse_map(info_map)?;
564-
565-
let mut kind = None;
566-
let mut ui_name = None;
567-
let mut hi_name = None;
568-
let mut id = None;
569-
570-
for attribute in attributes {
571-
if let (Value::String(name), value) = attribute {
572-
match (name.as_str().unwrap(), value) {
573-
("kind", value) => {
574-
let kind_str = parse_string(value)?;
575-
match kind_str.as_str() {
576-
"ui" => kind = Some(HighlightKind::Ui),
577-
"syntax" => kind = Some(HighlightKind::Syntax),
578-
// The documentation says terminal but Neovim 0.9.4 sends term...
579-
"terminal" | "term" => kind = Some(HighlightKind::Terminal),
580-
_ => return Err(ParseError::Format("Invalid highlight kind".to_string())),
581-
}
582-
}
583-
("ui_name", value) => ui_name = Some(parse_string(value)?),
584-
("hi_name", value) => hi_name = Some(parse_string(value)?),
585-
("id", value) => id = Some(parse_u64(value)?),
586-
_ => debug!("Ignored highlight info attribute: {}", name),
587-
}
588-
} else {
589-
return Err(ParseError::Format(
590-
"Invalid highlight info format".to_string(),
591-
));
592-
}
593-
}
594-
let kind = kind.ok_or(ParseError::Format(
595-
"kind field not found in highlight info".to_string(),
596-
))?;
597-
let ui_name = if kind == HighlightKind::Ui {
598-
ui_name.ok_or(ParseError::Format(
599-
"ui_name field not found in highlight info".to_string(),
600-
))?
601-
} else {
602-
String::default()
603-
};
604-
// hi_name can actually be absent for terminal, even though the documentation indicates otherwise
605-
let hi_name = hi_name.unwrap_or_default();
606-
let id = id.ok_or(ParseError::Format(
607-
"id field not found in highlight info".to_string(),
608-
))?;
609-
Ok(HighlightInfo {
610-
kind,
611-
ui_name,
612-
hi_name,
613-
id,
614-
})
615-
}
616-
617555
fn parse_hl_attr_define(hl_attr_define_arguments: Vec<Value>) -> Result<RedrawEvent> {
618556
let [id, attributes, _terminal_attributes, infos] = extract_values(hl_attr_define_arguments)?;
619557

src/bridge/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,6 @@ async fn launch(handler: NeovimHandler, grid_size: Option<GridSize<u32>>) -> Res
110110
SETTINGS.read_initial_values(&session.neovim).await?;
111111

112112
let mut options = UiAttachOptions::new();
113-
if !api_information.has_event("win_viewport_margins") {
114-
options.set_hlstate_external(true);
115-
}
116113
options.set_linegrid_external(true);
117114
options.set_multigrid_external(!settings.no_multi_grid);
118115
options.set_rgb(true);

src/editor/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use crate::{cmd_line::CmdLineSettings, frame::Frame, settings::SETTINGS};
2929

3030
pub use cursor::{Cursor, CursorMode, CursorShape};
3131
pub use draw_command_batcher::DrawCommandBatcher;
32-
pub use style::{Colors, HighlightInfo, HighlightKind, Style, UnderlineStyle};
32+
pub use style::{Colors, Style, UnderlineStyle};
3333
pub use window::*;
3434

3535
const MODE_CMDLINE: u64 = 4;

src/editor/style.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,6 @@ pub struct Style {
3131
pub blend: u8,
3232
#[new(default)]
3333
pub underline: Option<UnderlineStyle>,
34-
#[new(default)]
35-
pub infos: Vec<HighlightInfo>,
36-
}
37-
38-
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
39-
pub enum HighlightKind {
40-
Ui,
41-
Syntax,
42-
Terminal,
43-
}
44-
45-
#[derive(Debug, Clone, PartialEq)]
46-
pub struct HighlightInfo {
47-
pub kind: HighlightKind,
48-
pub ui_name: String,
49-
pub hi_name: String,
50-
pub id: u64,
5134
}
5235

5336
impl Style {

src/renderer/rendered_window.rs

Lines changed: 4 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ pub struct LineFragment {
2828
pub struct ViewportMargins {
2929
pub top: u64,
3030
pub bottom: u64,
31-
pub inferred: bool,
3231
}
3332

3433
#[derive(Clone, Debug, PartialEq)]
@@ -71,7 +70,6 @@ struct Line {
7170
line_fragments: Vec<LineFragment>,
7271
background_picture: Option<Picture>,
7372
foreground_picture: Option<Picture>,
74-
is_inferred_border: bool,
7573
blend: u8,
7674
is_valid: bool,
7775
}
@@ -141,11 +139,7 @@ impl RenderedWindow {
141139
actual_lines: RingBuffer::new(grid_size.height as usize, None),
142140
scrollback_lines: RingBuffer::new(2 * grid_size.height as usize, None),
143141
scroll_delta: 0,
144-
viewport_margins: ViewportMargins {
145-
top: 0,
146-
bottom: 0,
147-
inferred: true,
148-
},
142+
viewport_margins: ViewportMargins { top: 0, bottom: 0 },
149143

150144
grid_start_position: grid_position.cast(),
151145
grid_current_position: grid_position.cast(),
@@ -455,47 +449,14 @@ impl RenderedWindow {
455449
} => {
456450
tracy_zone!("draw_line_cmd", 0);
457451

458-
let mut line = Line {
452+
let line = Line {
459453
line_fragments,
460454
background_picture: None,
461455
foreground_picture: None,
462-
is_inferred_border: false,
463456
blend: 0,
464457
is_valid: false,
465458
};
466459

467-
if self.viewport_margins.inferred {
468-
let check_border = |fragment: &LineFragment, check: &dyn Fn(&str) -> bool| {
469-
fragment.style.as_ref().map_or(false, |style| {
470-
style.infos.last().map_or(false, |info| {
471-
// The specification seems to indicate that kind should be UI and
472-
// then we only need to test ui_name. But at least for FloatTitle,
473-
// that is not the case, the kind is set to syntax and hi_name is
474-
// set.
475-
check(&info.ui_name) || check(&info.hi_name)
476-
})
477-
})
478-
};
479-
480-
let float_border =
481-
|s: &str| matches!(s, "FloatBorder" | "FloatTitle" | "FloatFooter");
482-
let winbar = |s: &str| matches!(s, "WinBar" | "WinBarNC");
483-
484-
// Lines with purly border highlight groups are considered borders.
485-
line.is_inferred_border = line
486-
.line_fragments
487-
.iter()
488-
.map(|fragment| check_border(fragment, &float_border))
489-
.all(|v| v);
490-
491-
// And also lines with a winbar highlight anywhere
492-
line.is_inferred_border |= line
493-
.line_fragments
494-
.iter()
495-
.map(|fragment| check_border(fragment, &winbar))
496-
.any(|v| v)
497-
}
498-
499460
self.actual_lines[row] = Some(Rc::new(RefCell::new(line)));
500461
}
501462
WindowDrawCommand::Scroll {
@@ -543,47 +504,13 @@ impl RenderedWindow {
543504
self.scroll_delta = scroll_delta.round() as isize;
544505
}
545506
WindowDrawCommand::ViewportMargins { top, bottom, .. } => {
546-
self.viewport_margins = ViewportMargins {
547-
top,
548-
bottom,
549-
inferred: false,
550-
}
507+
self.viewport_margins = ViewportMargins { top, bottom }
551508
}
552509
_ => {}
553510
};
554511
}
555512

556-
fn infer_viewport_margins(&mut self) {
557-
if self.viewport_margins.inferred {
558-
self.viewport_margins.top = self
559-
.actual_lines
560-
.iter()
561-
.take_while(|line| {
562-
if let Some(line) = line {
563-
line.borrow().is_inferred_border
564-
} else {
565-
false
566-
}
567-
})
568-
.count() as u64;
569-
self.viewport_margins.bottom = (self.viewport_margins.top as usize
570-
..self.actual_lines.len())
571-
.rev()
572-
.map(|i| self.actual_lines[i].as_ref())
573-
.take_while(|line| {
574-
if let Some(line) = line {
575-
line.borrow().is_inferred_border
576-
} else {
577-
false
578-
}
579-
})
580-
.count() as u64;
581-
}
582-
}
583-
584513
pub fn flush(&mut self, renderer_settings: &RendererSettings) {
585-
self.infer_viewport_margins();
586-
587514
// If the borders are changed, reset the scrollback to only fit the inner view
588515
let inner_range = self.viewport_margins.top as isize
589516
..(self.actual_lines.len() - self.viewport_margins.bottom as usize) as isize;
@@ -641,19 +568,10 @@ impl RenderedWindow {
641568
let actual_line_count = self.actual_lines.len() as isize;
642569
let bottom_border_indices =
643570
actual_line_count - self.viewport_margins.bottom as isize..actual_line_count;
644-
let margins_inferred = self.viewport_margins.inferred;
645571

646572
top_border_indices
647573
.chain(bottom_border_indices)
648-
.filter_map(move |i| {
649-
self.actual_lines[i].as_ref().and_then(|line| {
650-
if !margins_inferred || line.borrow().is_inferred_border {
651-
Some((i, line))
652-
} else {
653-
None
654-
}
655-
})
656-
})
574+
.filter_map(move |i| self.actual_lines[i].as_ref().map(|line| (i, line)))
657575
}
658576

659577
// Iterates over the scrollable lines (excluding the viewport margins). Includes the index for

0 commit comments

Comments
 (0)