Skip to content

History fix cursor update#97

Merged
sophiajt merged 6 commits into
nushell:mainfrom
nixypanda:history-fix-cursor-update
Jul 19, 2021
Merged

History fix cursor update#97
sophiajt merged 6 commits into
nushell:mainfrom
nixypanda:history-fix-cursor-update

Conversation

@nixypanda
Copy link
Copy Markdown
Contributor

Various fixes to history execution

we will most likely store multiline commands in history as `String`s so
I have opted for a converstion of this string to a vector separated by
newlines in `set_buffer`.
- On normal up down we update the cursor to the end of the line
- On prefix based up and down we do not update the cursor

Rationale for this is that when we are doing prefix search a user might
want to add more to his query so as to get better prefix matching and
having to delete through all the chars we would otherwise fill in might
be annoying.
@sholderbach
Copy link
Copy Markdown
Member

Still some usability painpoints:

  • Ctrl-R search has the refresh bugs
  • moving the cursor left/right without editing breaks the ability to go up/down
  • still skips the most recent entry going up
  • you can not return to the (empty) linebuffer by going down beyond the history (some shells like bash allow you to return to a partial manual entry if they don't support the prefix searching history browsing)

For the last two points the iterator like interface of moving while either returning Some(entry) when a move was succesful or None when exhausted had some benefits over the new setup. We want to be able to handle those cases. I started some changes on that, if I get them to work I will file a PR.

@sholderbach
Copy link
Copy Markdown
Member

OK Update regarding point two on my list. zsh's history traversal would also stop at this point as it then thinks it is in prefix mode. Yet bash allows horizontal cursor movement without interfering with the basic up/down history navigation. So this seems to be somewhat of an UI/UX choice.

@nixypanda
Copy link
Copy Markdown
Contributor Author

Ctrl-R search has the refresh bugs

IIRC this has existed for a long time, I wasn't really focused on this one. I really think we should get rid of the clock update for now and introduce it later down the road.

moving the cursor left/right without editing breaks the ability to go up/down

Can you elaborate on this one (ideally with an example). So, I can understand what the behaviour should be. I believe the present state (in the PR) should be that left/right movement etc should stop history searching altogether for Normal and PrefixSearch modes. That is what I wanted to implement.
Though I think when doing crtl-r search this should be allowed (i.e. going left/right). (Not sure what the present behaviour is)

still skips the most recent entry going up

Yeah, I plan to fix this one.

ou can not return to the (empty) line buffer by going down beyond the history (some shells like bash allow you to return to a partial manual entry if they don't support the prefix searching history browsing)

I had not really thought this through. Definitely, something that should happen.

@sophiajt
Copy link
Copy Markdown
Contributor

@sherubthakur - taking a look at this now. I'm seeing something related to a previous PR you did to clean up history and I think it'd be great to fix it as part of this update.

If you press up/down and wait a second, the input disappears. Before #92 this worked fine, but after that it seems that after the second ticks by we only draw the prompt and not the user's input.

Copy link
Copy Markdown
Member

@sholderbach sholderbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's get this merged that we can remove this history bug, and check for the new interactions.

If the refactored line buffer will have to be taken in to account depends on what gets merged first.

Comment thread src/line_buffer.rs
@@ -65,8 +65,17 @@ impl LineBuffer {

/// Set to a single line of `buffer` and reset the `InsertionPoint` cursor
pub fn set_buffer(&mut self, buffer: String) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are other users of set_buffer maybe expecting a different behavior? Else we may want to have have set_buffer_cursor_end or something else.

Comment thread src/engine.rs
self.history.set_navigation(HistoryNavigationQuery::Normal);
}
(false, HistoryNavigationQuery::PrefixSearch(_)) => {}
(false, HistoryNavigationQuery::PrefixSearch(prefix)) => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity: Against which state is this guarding?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each up/down press will call this function. if the prefix does not change we don't want to reset the history state.

@sophiajt
Copy link
Copy Markdown
Contributor

Yeah I'm also 👍 on landing and continuing to polish. @sherubthakur thanks for the fixes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants