mod: reduce the amount of unnecessary re-renderings
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 1m8s

This commit is contained in:
2024-12-08 21:38:19 +01:00
parent 3947c2b5af
commit f7cd61d619
2 changed files with 36 additions and 8 deletions

View File

@@ -64,18 +64,32 @@ pub fn Widget(comptime Event: type, comptime Renderer: type) type {
var require_render = true;
if (key.matches(.{ .cp = 'g' })) {
// top
this.idx = 0;
if (this.idx != 0) {
this.idx = 0;
} else {
require_render = false;
}
} else if (key.matches(.{ .cp = 'G' })) {
// bottom
this.idx = this.contents.items.len -| 1;
if (this.idx < this.contents.items.len -| 1) {
this.idx = this.contents.items.len -| 1;
} else {
require_render = false;
}
} else if (key.matches(.{ .cp = 'j' })) {
// down
if (this.idx < this.contents.items.len -| 1) {
this.idx +|= 1;
this.idx += 1;
} else {
require_render = false;
}
} else if (key.matches(.{ .cp = 'k' })) {
// up
this.idx -|= 1;
if (this.idx > 0) {
this.idx -= 1;
} else {
require_render = false;
}
} else {
require_render = false;
}

View File

@@ -55,18 +55,32 @@ pub fn Widget(comptime Event: type, comptime Renderer: type) type {
.key => |key| {
if (key.matches(.{ .cp = 'g' })) {
// top
this.line = 0;
if (this.line != 0) {
this.line = 0;
} else {
require_render = false;
}
} else if (key.matches(.{ .cp = 'G' })) {
// bottom
this.line = this.line_index.items.len -| 1 -| this.size.rows;
if (this.line < this.line_index.items.len -| 1 -| this.size.rows) {
this.line = this.line_index.items.len -| 1 -| this.size.rows;
} else {
require_render = false;
}
} else if (key.matches(.{ .cp = 'j' })) {
// down
if (this.line < this.line_index.items.len -| 1 -| this.size.rows) {
this.line +|= 1;
this.line += 1;
} else {
require_render = false;
}
} else if (key.matches(.{ .cp = 'k' })) {
// up
this.line -|= 1;
if (this.line > 0) {
this.line -= 1;
} else {
require_render = false;
}
} else {
require_render = false;
}