From 60943f8b140fd2c1776bc29a7d4d4d03b1813ee7 Mon Sep 17 00:00:00 2001 From: rhysd Date: Fri, 2 Aug 2024 00:07:35 +0900 Subject: [PATCH] fix `vim` example's text selection should be inclusive in visual mode Vim's text selection is inclusive. For example, when a cursor is on 'r' of 'bar', 'r' is included in the selection. However tui-textarea's text selection is exclusive on the end of the range. Move cursor forward to emulate Vim's behavior better. --- examples/vim.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/vim.rs b/examples/vim.rs index d14f62d..ce0679c 100644 --- a/examples/vim.rs +++ b/examples/vim.rs @@ -338,6 +338,7 @@ impl Vim { ctrl: false, .. } if self.mode == Mode::Visual => { + textarea.move_cursor(CursorMove::Forward); // Vim's text selection is inclusive textarea.copy(); return Transition::Mode(Mode::Normal); } @@ -346,6 +347,7 @@ impl Vim { ctrl: false, .. } if self.mode == Mode::Visual => { + textarea.move_cursor(CursorMove::Forward); // Vim's text selection is inclusive textarea.cut(); return Transition::Mode(Mode::Normal); } @@ -354,6 +356,7 @@ impl Vim { ctrl: false, .. } if self.mode == Mode::Visual => { + textarea.move_cursor(CursorMove::Forward); // Vim's text selection is inclusive textarea.cut(); return Transition::Mode(Mode::Insert); }