From 5fe122d53ec0d082431775bb97b2ab11930b1a50 Mon Sep 17 00:00:00 2001 From: Matuush Date: Thu, 13 Mar 2025 17:03:08 +0100 Subject: [PATCH] Fixed cursor movement --- main.cpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/main.cpp b/main.cpp index 9340b30..6877d80 100644 --- a/main.cpp +++ b/main.cpp @@ -64,16 +64,33 @@ void move_cursor(char ch) { switch(ch) { case 'h': - if(col > 0) move(row, --col); + if(col > 0) + move(row, --col); break; + case 'j': - if(row < file.size()-1) move(++row, col); + if(row < file.size()-1) { + move(++row, col); + if(file[row].size() <= col) { + col = file[row].size()-1; + move(row, col); + } + } break; + case 'k': - if(row > 0) move(--row, col); + if(row > 0) { + move(--row, col); + if(file[row].size() <= col) { + col = file[row].size()-1; + move(row, col); + } + } break; + case 'l': - if(col < file[row].size()) move(row, ++col); + if(col < file[row].size()-1) + move(row, ++col); break; } }