aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/cursor.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/cursor.c')
-rw-r--r--src/nvim/cursor.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c
index 11c734479c..1446257f7e 100644
--- a/src/nvim/cursor.c
+++ b/src/nvim/cursor.c
@@ -399,6 +399,24 @@ void check_cursor(void)
check_cursor_col();
}
+/// Check if VIsual position is valid, correct it if not.
+/// Can be called when in Visual mode and a change has been made.
+void check_visual_pos(void)
+{
+ if (VIsual.lnum > curbuf->b_ml.ml_line_count) {
+ VIsual.lnum = curbuf->b_ml.ml_line_count;
+ VIsual.col = 0;
+ VIsual.coladd = 0;
+ } else {
+ int len = (int)STRLEN(ml_get(VIsual.lnum));
+
+ if (VIsual.col > len) {
+ VIsual.col = len;
+ VIsual.coladd = 0;
+ }
+ }
+}
+
/// Make sure curwin->w_cursor is not on the NUL at the end of the line.
/// Allow it when in Visual mode and 'selection' is not "old".
void adjust_cursor_col(void)