aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-08 14:59:41 +0000
committer_ov4 <ov4@ov4.org>2026-10-08 14:59:41 +0000
commit6864b943fb91debe90b88e2e8a3a063fa89cbdce (patch)
tree1b9f7d0ce249f471451512b0c50e1af9d8db7a04
parent0e1493d536c564f5d75a1345fe149cfdf0daee61 (diff)
fix cursor moving right
-rw-r--r--include/line/cursor.h2
-rw-r--r--include/line/getter.h3
-rw-r--r--src/line/cursor.cc13
-rw-r--r--src/line/getter.cc6
4 files changed, 16 insertions, 8 deletions
diff --git a/include/line/cursor.h b/include/line/cursor.h
index 46b8423..032269d 100644
--- a/include/line/cursor.h
+++ b/include/line/cursor.h
@@ -12,7 +12,7 @@ namespace ov4
// 1-based
inline int cursor_row;
inline int cursor_col;
-inline int line_end_pos;
+//inline int line_end_pos;
inline int prompt_pos;
diff --git a/include/line/getter.h b/include/line/getter.h
index a572c38..8a3ef7e 100644
--- a/include/line/getter.h
+++ b/include/line/getter.h
@@ -8,8 +8,9 @@ namespace ov4
int get_terminal_pos_cursor();
int get_buffer_index_display_begin();
int get_buffer_index_display_end();
+int get_terminal_pos_line_end();
-void update_line_end_pos();
+//void update_line_end_pos();
T_position get_cursor_position();
diff --git a/src/line/cursor.cc b/src/line/cursor.cc
index 3c701e5..b44054e 100644
--- a/src/line/cursor.cc
+++ b/src/line/cursor.cc
@@ -84,7 +84,7 @@ void cursor_input_char(char c)
line_buffer.insert(buffer_index_cursor, 1, c);
// print("\x1b[C"); fflush(stdout); // move cursor to the right
// buffer_index_cursor++;
- update_line_end_pos();
+ // update_line_end_pos();
// int end_possible_buffer_index = window_size_col-prompt_pos-1;
// buffer_index_display_end =
// (end_possible_buffer_index > (buffer_index_display_end)+1)
@@ -99,7 +99,7 @@ void cursor_input_char(char c)
line_buffer.erase(buffer_index_cursor, 1);
// print("\x1b[D"); fflush(stdout); // move cursor to the left
// buffer_index_cursor--;
- update_line_end_pos();
+ // update_line_end_pos();
// TODO: backspace page
move_cursor(T_cursor_movement_direction::LEFT);
@@ -131,6 +131,8 @@ void move_cursor(T_cursor_movement_direction d)
// margin
else
{
+ // already at the beginning of buffer
+ if (buffer_index_cursor == 0) break;
buffer_index_cursor--;
_buffer_index_display_begin--;
}
@@ -138,14 +140,19 @@ void move_cursor(T_cursor_movement_direction d)
case T_cursor_movement_direction::RIGHT:
// if cursor is not at right margin
- if (line_end_pos > get_terminal_pos_cursor())
+ if (window_size_col > get_terminal_pos_cursor())
{
+ // already at the end of buffer
+ if (buffer_index_cursor == line_buffer.size()) break;
+
buffer_index_cursor++;
print("\x1b[C"); fflush(stdout); // move cursor to the right
}
// margin
else
{
+ // already at the end of buffer
+ if (buffer_index_cursor == line_buffer.size()) break;
buffer_index_cursor++;
_buffer_index_display_begin++;
}
diff --git a/src/line/getter.cc b/src/line/getter.cc
index 50456d8..73b0c03 100644
--- a/src/line/getter.cc
+++ b/src/line/getter.cc
@@ -33,10 +33,10 @@ int get_buffer_index_display_end()
return min(max_possible_end, window_possible_end);
}
-void update_line_end_pos()
+int get_terminal_pos_line_end()
{
- line_end_pos = prompt_pos + line_buffer.size();
- line_end_pos = (line_end_pos > window_size_col) ? window_size_col : line_end_pos;
+ int possible = prompt_pos + line_buffer.size();
+ return min(possible, window_size_col);
}