diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-08 14:59:41 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-08 14:59:41 +0000 |
| commit | 6864b943fb91debe90b88e2e8a3a063fa89cbdce (patch) | |
| tree | 1b9f7d0ce249f471451512b0c50e1af9d8db7a04 /src/line/cursor.cc | |
| parent | 0e1493d536c564f5d75a1345fe149cfdf0daee61 (diff) | |
fix cursor moving right
Diffstat (limited to 'src/line/cursor.cc')
| -rw-r--r-- | src/line/cursor.cc | 13 |
1 files changed, 10 insertions, 3 deletions
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++; } |
