Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config options related to Vi input mode #337

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

antonalekseev
Copy link
Contributor

This PR addresses #258 and adds couple of configuration options related to Vi input mode.

Setting vi_start_in_nav_mode to True enables NAVIGATION mode on startup. The issue is that due to the current behaviour of ViState.reset() input mode gets resetted back to INSERT on the every iteration of the main loop. In order to at one hand to provide the user with desired behaviour and on the other hand doesn't introduce breaking changes the other option vi_keep_last_used_mode was introduced which sets input_mode to the state observed before reset.

vi_keep_last_used_mode can be useful even with vi_start_in_nav_mode set to False in the case the user prefer to start in INSERT mode but still wants to maintain the last mode he was in.

In the case of vi_keep_last_used_mode set to False and vi_start_in_nav_mode to True NAVIGATION mode is set on every iteration the same way INSERT was set before this commit.

Maybe interfering with the pre_run on the main loop is not the best option but I don't see any other way to set input mode after reset for ViState.reset() no longer accepts mode as an argument (after this commit prompt-toolkit/python-prompt-toolkit@60b22db#diff-d95a70749837190e857489f7cbc59cdc).

Setting `vi_start_in_nav_mode` to `True` enables `NAVIGATION` mode on startup.
The issue is that due to the current behaviour of `ViState.reset()` input mode
gets resetted back to `INSERT` on the every iteration of the main loop. In order
to at one hand to provide the user with desired behaviour and on the other hand
doesn't introduce breaking changes the other option `vi_keep_last_used_mode` was
introduced which sets `input_mode` to the state observed before reset.

`vi_keep_last_used_mode` can be useful even with `vi_start_in_nav_mode` set to
`False` in the case the user prefer to start in `INSERT` mode but still wants to
maintain the last mode he was in.

In the case of `vi_keep_last_used_mode` set to `False` and
`vi_start_in_nav_mode` to `True` `NAVIGATION` mode is set on every iteration the
same way `INSERT` was set before this commit.

Fixes prompt-toolkit#258.
# Capture the current input_mode in order to restore it after reset,
# for ViState.reset() sets it to InputMode.INSERT unconditionally and
# doesn't accept any arguments despite the docstring says otherwise.
def pre_run(last_input_mode=self.app.vi_state.input_mode):

Choose a reason for hiding this comment

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

Suggested change
def pre_run(last_input_mode=self.app.vi_state.input_mode):
def pre_run(last_input_mode=self.app.vi_state.input_mode) -> None:

@jonathanslenders
Copy link
Member

Going to merge this. Sorry for the delay!

I'm renaming vi_start_in_nav_mode to vi_start_in_navigation_mode, hope that's okay.

@jonathanslenders
Copy link
Member

Rebased and merged here: #375

Thanks a lot, @antonalekseev !

@antonalekseev
Copy link
Contributor Author

Thanks, @jonathanslenders!

Just switched from my fork back to 3.0.7 and have discovered that despite vi_start_in_navigation_mode was set ptpython starts in INSERT mode. Probably due to 180462b. vi_keep_last_used_mode behaves as expected.

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