Skip to content

Commit 49df0b2

Browse files
authored
Improve scrolling perforamnce (#54)
- Truncate text instead of using the native paragraph "scroll"
1 parent 7fb2ed1 commit 49df0b2

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed

src/view/context.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ impl View for ContextComponent {
5757
},
5858
None => return,
5959
};
60-
let mut lines: Vec<Line> = vec![];
6160
let layout = Layout::default()
6261
.constraints([Constraint::Length(
6362
if app.session_view.context_filter.show { 3 } else { 0 }
@@ -77,17 +76,22 @@ impl View for ContextComponent {
7776
}
7877

7978
let mut filter_path = app.session_view.context_filter.segments().clone();
79+
80+
let mut lines: Vec<Line> = vec![];
81+
let truncate_from = app.session_view.context_scroll.0 as u32;
8082
draw_properties(
8183
&app.theme(),
8284
&context.properties,
8385
&mut lines,
8486
0,
8587
&mut filter_path,
88+
&truncate_from,
89+
&mut 0
8690
);
8791

8892

8993
frame.render_widget(
90-
Paragraph::new(lines).scroll(app.session_view.context_scroll),
94+
Paragraph::new(lines.clone()),
9195
areas[1],
9296
);
9397
}

src/view/properties.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
use crate::dbgp::client::Property;
23
use crate::dbgp::client::PropertyType;
34
use crate::theme::Scheme;
@@ -10,6 +11,8 @@ pub fn draw_properties(
1011
lines: &mut Vec<Line>,
1112
level: usize,
1213
filter_path: &mut Vec<&str>,
14+
truncate_until: &u32,
15+
line_no: &mut u32,
1316
) {
1417
let filter = filter_path.pop();
1518

@@ -43,11 +46,18 @@ pub fn draw_properties(
4346
spans.push(Span::raw(delimiters.0).style(theme.syntax_brace));
4447
}
4548

46-
lines.push(Line::from(spans));
49+
// only "render" lines that we need to
50+
if *line_no >= *truncate_until {
51+
lines.push(Line::from(spans));
52+
}
53+
*line_no += 1;
4754

4855
if !property.children.is_empty() {
49-
draw_properties(theme, &property.children, lines, level + 1, filter_path);
50-
lines.push(Line::from(vec![Span::raw(delimiters.1)]).style(theme.syntax_brace));
56+
draw_properties(theme, &property.children, lines, level + 1, filter_path, truncate_until, line_no);
57+
if *line_no >= *truncate_until {
58+
lines.push(Line::from(vec![Span::raw(delimiters.1)]).style(theme.syntax_brace));
59+
}
60+
*line_no += 1;
5161
}
5262
}
5363
}
@@ -85,6 +95,8 @@ mod test {
8595
&mut lines,
8696
0,
8797
&mut Vec::new(),
98+
&0,
99+
&mut 0,
88100
);
89101
assert_eq!(0, lines.len());
90102
Ok(())
@@ -109,6 +121,8 @@ mod test {
109121
&mut lines,
110122
0,
111123
&mut Vec::new(),
124+
&0,
125+
&mut 0,
112126
);
113127
assert_eq!(vec![
114128
"foo string = \"\"{",
@@ -148,6 +162,8 @@ mod test {
148162
&mut lines,
149163
0,
150164
filter,
165+
&0,
166+
&mut 0,
151167
);
152168

153169
assert_eq!(vec![

src/view/source.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,16 @@ impl View for SourceComponent {
5151
.analyzed_files
5252
.get(&stack.source.filename.to_string());
5353

54-
for (line_no, line) in stack.source.source.lines().enumerate() {
55-
let is_current_line = stack.source.line_no == line_no as u32 + 1;
54+
55+
// trunacte the hidden lines
56+
let truncate_until = app.session_view.source_scroll.0 as u32 + 1;
57+
58+
for (line_offset, line) in stack.source.source.lines().enumerate() {
59+
let line_no = line_offset + 1;
60+
if (line_no as u32) < truncate_until {
61+
continue
62+
}
63+
let is_current_line = stack.source.line_no == line_no as u32;
5664

5765
lines.push(Line::from(vec![
5866
Span::styled(format!("{:<6}", line_no), app.theme().source_line_no),
@@ -68,7 +76,7 @@ impl View for SourceComponent {
6876

6977
if is_current_line {
7078
if let Some(analysis) = analysis {
71-
for (_, var) in analysis.row(line_no) {
79+
for (_, var) in analysis.row(line_offset) {
7280
let property = stack.get_property(var.name.as_str());
7381
if property.is_none() {
7482
continue;
@@ -82,7 +90,7 @@ impl View for SourceComponent {
8290
if labels.len() > 1 {
8391
labels.pop();
8492
annotations.push((
85-
line_no + 1,
93+
line_offset,
8694
line.len() + 8,
8795
Line::from(labels).style(app.theme().source_annotation),
8896
));
@@ -92,15 +100,15 @@ impl View for SourceComponent {
92100
}
93101

94102
frame.render_widget(
95-
Paragraph::new(lines.clone()).scroll(app.session_view.source_scroll),
103+
Paragraph::new(lines.clone()),
96104
rows[0],
97105
);
98106

99-
for (line_no, line_length, line) in annotations {
107+
for (line_offset, line_length, line) in annotations {
100108
let x_offset = rows[0].x + (line_length as u16).saturating_sub(app.session_view.source_scroll.1);
101109
let area = Rect {
102110
x: x_offset,
103-
y: (line_no as u32).saturating_sub(app.session_view.source_scroll.0 as u32) as u16 + 1,
111+
y: rows[0].y + ((line_offset as u32).saturating_sub(app.session_view.source_scroll.0 as u32) as u16),
104112
width: rows[0].width.saturating_sub(x_offset),
105113
height: 1,
106114
};

0 commit comments

Comments
 (0)