Enhance jumping
This commit is contained in:
parent
8e29aad9e0
commit
61ce077ea0
1 changed files with 15 additions and 11 deletions
26
main.cpp
26
main.cpp
|
@ -18,6 +18,18 @@ struct position {
|
|||
position operator+(count_type offset) { return {r + offset, c}; }
|
||||
};
|
||||
|
||||
// Utilities
|
||||
count_type min(count_type a, count_type b) {
|
||||
if(a <= b)
|
||||
return a;
|
||||
return b;
|
||||
}
|
||||
count_type max(count_type a, count_type b) {
|
||||
if(a >= b)
|
||||
return a;
|
||||
return b;
|
||||
}
|
||||
|
||||
// Global variables
|
||||
treap file;
|
||||
position cur = {0, 0};
|
||||
|
@ -233,17 +245,9 @@ void move_cursor(char ch) {
|
|||
}
|
||||
// Jump to line
|
||||
void jump(count_type r) {
|
||||
count_type last_start = file.size()-LINES;
|
||||
if(last_start < 0)
|
||||
last_start = 0;
|
||||
cur.r = 0;
|
||||
file_offset = r;
|
||||
if(file_offset > last_start) {
|
||||
file_offset = last_start;
|
||||
cur.r = r - file_offset;
|
||||
if(cur.r >= LINES)
|
||||
cur.r = LINES-1;
|
||||
}
|
||||
if(r - file_offset > LINES || r < file_offset)
|
||||
file_offset = max(0, min(file.size()-LINES, r));
|
||||
cur.r = max(0, r - file_offset);
|
||||
jump_line_end();
|
||||
}
|
||||
// Jump to position
|
||||
|
|
Loading…
Reference in a new issue