Giter Site home page Giter Site logo

Comments (3)

faho avatar faho commented on June 23, 2024

I'm disagreeing that this is a good first issue, it cuts to a fundamental issue with vi-mode: The cursor placement isn't the same as in emacs mode.

That needs some careful consideration, because it would probably touch a lot more than the one bind function.

See also #8189 or #3005, which both mention it as an issue with $, and #3006, which tried to fix it exclusively for $.

I'm going to close both of those and leave the issue at hand to be tracked here.

from fish-shell.

johnpyp avatar johnpyp commented on June 23, 2024

Until this gets fixed fundamentally, is there any intermediary fish script conditional hack that could fix this specific pattern (normal mode forward-char accepting suggestions behavior)? Or are the apis necessary just not available?

from fish-shell.

krobelus avatar krobelus commented on June 23, 2024

It's not worth to add a hack.
Better change Vi mode to always put the cursor on a character (except maybe if the commandline is empty).
We can start from this and fix any remaining issues.

diff --git a/src/reader.rs b/src/reader.rs
index 45dbe69fd..5fd0425c1 100644
--- a/src/reader.rs
+++ b/src/reader.rs
@@ -1181,13 +1181,26 @@ impl ReaderData {
     }
 
     /// Update the cursor position.
-    fn update_buff_pos(&mut self, elt: EditableLineTag, new_pos: Option<usize>) {
-        if let Some(pos) = new_pos {
+    fn update_buff_pos(&mut self, elt: EditableLineTag, new_pos: Option<usize>) -> bool {
+        if let Some(mut pos) = new_pos {
+            if self
+                .vars()
+                .get_unless_empty(L!("fish_cursor_selection_mode"))
+                .is_some_and(|mode| mode.as_list()[0] == "inclusive")
+            {
+                let el = self.edit_line(elt);
+                if !el.is_empty() && pos == el.len() {
+                    pos = el.len() - 1;
+                    if el.position() == pos {
+                        return false;
+                    }
+                }
+            }
             self.edit_line_mut(elt).set_position(pos);
         }
 
         if elt != EditableLineTag::Commandline {
-            return;
+            return true;
         }
         let buff_pos = self.command_line.position();
         let target_char = if self.cursor_selection_mode == CursorSelectionMode::Inclusive {
@@ -1196,7 +1209,7 @@ impl ReaderData {
             0
         };
         let Some(selection) = self.selection.as_mut() else {
-            return;
+            return true;
         };
         if selection.begin <= buff_pos {
             selection.start = selection.begin;
@@ -1205,6 +1218,7 @@ impl ReaderData {
             selection.start = buff_pos;
             selection.stop = selection.begin + target_char;
         }
+        true
     }
 }
 
@@ -2240,7 +2254,9 @@ impl ReaderData {
                     }
                     position
                 };
-                self.update_buff_pos(self.active_edit_line_tag(), Some(position + 1));
+                if !self.update_buff_pos(self.active_edit_line_tag(), Some(position + 1)) {
+                    break;
+                }
             },
             rl::BeginningOfBuffer => {
                 self.update_buff_pos(EditableLineTag::Commandline, Some(0));
@@ -2644,9 +2660,9 @@ impl ReaderData {
                 let (elt, el) = self.active_edit_line();
                 if self.is_navigating_pager_contents() {
                     self.select_completion_in_direction(SelectionMotion::East, false);
-                } else if el.position() != el.len() {
-                    self.update_buff_pos(elt, Some(el.position() + 1));
-                } else {
+                } else if el.position() == el.len()
+                    || !self.update_buff_pos(elt, Some(el.position() + 1))
+                {
                     self.accept_autosuggestion(
                         /*full=*/ c != rl::ForwardSingleChar,
                         /*single=*/ c == rl::ForwardSingleChar,

from fish-shell.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.