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 support for start_mode #175

Merged
merged 11 commits into from
Nov 3, 2024
Merged

Conversation

MarcelRobitaille
Copy link
Contributor

Implement start_mode. It's like start_in_insert, but more flexible.

Context

Implement #174

Description

I added start_mode. I kept start_in_insert for backwards compatibility.

Test Plan

I tried each value of start_mode with a default value and without. I also added automated tests of the backwards compatibility of start_in_insert.

@github-actions github-actions bot requested a review from stevearc October 25, 2024 15:42
Copy link
Owner

@stevearc stevearc left a comment

Choose a reason for hiding this comment

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

Left some comments. Also make sure that as you're testing this you test different combinations of your starting mode + the start_mode option. For example, try running vim.ui.input when you're already in visual mode and with start_mode = "insert". Try that for all the permutations to make sure that the start_mode is respected in all cases and there's no weirdness.

lua/dressing/config.lua Outdated Show resolved Hide resolved
@@ -4,13 +4,25 @@ local patch = require("dressing.patch")
local util = require("dressing.util")
local M = {}

---@alias dressing.StartMode "insert" | "visual" | "normal"
Copy link
Owner

Choose a reason for hiding this comment

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

Would be great to also provide support for select mode (see :help Select-mode)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you know a good way to get into select mode? The best option to me reading the help is CTRL-G since it doesn't require changing any settings, but it's not working for me. It works if I do it manually (set start_mode to visual and press CTRL-G) but not using

    vim.api.nvim_command("normal! v$")
    local ctrl_g = vim.api.nvim_replace_termcodes("<C-g>", true, false, true)
    vim.api.nvim_feedkeys(ctrl_g, "v", true)

Copy link
Owner

Choose a reason for hiding this comment

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

This seems to work for me

vim.cmd("normal! 0vg_")
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<C-g>", true, false, true), "n", true)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This snippet puts me in visual mode. Shouldn't it be "v", not "n"? I thought it was a visual mode mapping.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm still not sure what to do here.

Copy link
Owner

Choose a reason for hiding this comment

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

I just tried the snippet that I gave you on your branch and it works for me. Are you sure that it's not working? Is it possible that something else in your config is interfering with it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. I just tried this, and I got into select mode.

nvim -u NORC --noplugin -c 'lua vim.cmd("normal! 0vg_")' -c 'lua vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<C-g>", true, false, true), "n", true)'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Select mode is now working for me. What exactly is the advantage? Reading help, I see that enter deletes everything and goes into insert mode, but in our case enter confirms the input.

lua/dressing/input.lua Show resolved Hide resolved
lua/dressing/input.lua Show resolved Hide resolved
lua/dressing/input.lua Outdated Show resolved Hide resolved
@github-actions github-actions bot requested a review from stevearc October 25, 2024 21:36
@MarcelRobitaille
Copy link
Contributor Author

Thanks for the quick review. I addressed some of the comments. I left some to do because I'd like some feedback first.

@stevearc
Copy link
Owner

Only question you were waiting on was about select mode, right?

@MarcelRobitaille
Copy link
Contributor Author

Yes unless you also want to have a look at how I added back restoring the previous mode.

lua/dressing/input.lua Show resolved Hide resolved
lua/dressing/input.lua Outdated Show resolved Hide resolved
lua/dressing/input.lua Outdated Show resolved Hide resolved
@github-actions github-actions bot requested a review from stevearc October 29, 2024 22:12
lua/dressing/input.lua Show resolved Hide resolved
@@ -4,13 +4,25 @@ local patch = require("dressing.patch")
local util = require("dressing.util")
local M = {}

---@alias dressing.StartMode "insert" | "visual" | "normal"
Copy link
Owner

Choose a reason for hiding this comment

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

I just tried the snippet that I gave you on your branch and it works for me. Are you sure that it's not working? Is it possible that something else in your config is interfering with it?

Copy link
Owner

@stevearc stevearc left a comment

Choose a reason for hiding this comment

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

This looks good. Once you add support for select mode and fix the CI, it's good to merge!

lua/dressing/input.lua Show resolved Hide resolved
@github-actions github-actions bot requested a review from stevearc October 30, 2024 17:15
Copy link
Owner

@stevearc stevearc left a comment

Choose a reason for hiding this comment

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

Still some CI failures

@github-actions github-actions bot requested a review from stevearc October 31, 2024 10:00
@MarcelRobitaille
Copy link
Contributor Author

I'm having some trouble with the tests. I saw some comments that startinsert doesn't work in tests, but even if I do util.feedkeys({"i"}), vim.api.nvim_get_mode().mode always says it's in normal mode. Is it not possible to change the mode at all in tests? I'm new to this headless neovim testing.

@stevearc
Copy link
Owner

Headless testing isn't great; as you've discovered there are some difficult inconsistencies to deal with. Unfortunately I don't have any better idea what hacks will help bypass this. Just try a few things, see if you can get something working, and if not no worries I won't block the PR for lack of tests.

@MarcelRobitaille
Copy link
Contributor Author

Since insert mode doesn't work well, I mocked set_mode and restore_mode.

Copy link
Owner

@stevearc stevearc left a comment

Choose a reason for hiding this comment

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

One nit and still some styling inconsistencies

lua/dressing/input.lua Outdated Show resolved Hide resolved
@github-actions github-actions bot requested a review from stevearc November 3, 2024 09:56
@stevearc
Copy link
Owner

stevearc commented Nov 3, 2024

Great job! Thanks for the PR!

@stevearc stevearc merged commit c334ac7 into stevearc:master Nov 3, 2024
9 checks passed
@MarcelRobitaille
Copy link
Contributor Author

No, thank you! I really appreciate how patient you were with me.

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.

2 participants