-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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 insert_character_interactive
command
#11411
base: master
Are you sure you want to change the base?
Conversation
fn insert_tab_impl(cx: &mut Context, count: usize) { | ||
let (view, doc) = current!(cx.editor); | ||
// TODO: round out to nearest indentation level (for example a line with 3 spaces should | ||
// indent by one to reach 4 spaces). | ||
|
||
let indent = Tendril::from(doc.indent_style.as_str()); | ||
let indent = Tendril::from(doc.indent_style.as_str().repeat(count)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
handling count
is done here rather than in the new insert_char
command because it needs to be taken into account if this TODO is ever fixed; putting it outside insert_tab
makes it more likely to be forgotten.
@@ -397,6 +397,7 @@ impl MappableCommand { | |||
smart_tab, "Insert tab if all cursors have all whitespace to their left; otherwise, run a separate command.", | |||
insert_tab, "Insert tab char", | |||
insert_newline, "Insert newline char", | |||
insert_char_interactive, "Insert an interactively-chosen char", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm not super happy with this name or description, but hopefully it gets the idea across.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand the motivation for this - it's to avoid switching modes?
As part of introducing a plugin system I imagine we would expose the on_next_key
functionality so this should be possible via scripting in the long run
this command inserts a character of the user's choice underneath the current cursor, without exiting normal mode. multiple cursors are handled correctly. i chose `C-y` for the default mapping because it doesn't conflict with anything else. i would have preferred `C-i` (i for insert), but that conflicts with `jump_forward`; and additionally most terminals do not distinguish `C-i` from `tab`, so it's not a good choice for the default. this command does not have precedence in vim or kakoune to my knowledge, but at least vim allows replicating it with remap command (https://superuser.com/questions/581572/insert-single-character-in-vim), while helix currently does not, since there's no way to say "a character entered by the user".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand the motivation for this - it's to avoid switching modes?
yes, exactly. it's like r
but without deleting the character under the cursor.
by the way, do you happen to know a vague idea of how long that would take to land? i don't mind keeping this in my fork of helix until scripting lands, but it would be nice not to need a fork for multiple months 😅 |
Plugin system will definitely take multiple months. |
Yeah it will definitely take some time. I'm not necessarily against this change as is though. Especially if it doesn't have a default keybinding it's a very slim change and the command itself is very straightforward. I might recommand adding an |
this behaves like regular append with respect to selections: the newly inserted text will be selected when the command finishes, unlike when using `insert_char_interactive`.
i've done this :) |
this command inserts a character of the user's choice underneath the current cursor, without exiting normal mode. multiple cursors and more than 1 counts are handled correctly.
i chose
C-y
for the default mapping because it doesn't conflict with anything else. i would have preferredC-i
(i for insert), but that conflicts withjump_forward
; and additionally most terminals do not distinguishC-i
fromtab
, so it's not a good choice for the default.this command does not have a precedent in vim or kakoune to my knowledge, but at least vim allows replicating it with remap command (https://superuser.com/questions/581572/insert-single-character-in-vim), while helix currently does not, since there's no way to say "a character entered by the user".
i wasn't sure what to do when inserting multiple newlines, so that just panics for now. presumably only the last one should get indentation and all the rest should be blank lines?
here is a demo of it working (click for video):