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

remove leading spaces when <Esc>... is pressed #685 #962

Merged
merged 1 commit into from
Oct 25, 2016

Conversation

Zzzen
Copy link
Contributor

@Zzzen Zzzen commented Oct 21, 2016

fix #685

I found it annoying that doesn't remove leading spaces in insert mode. Today, I'm going to fix it myself, contributing to this aaaaaawesome project. You guys have done a great job. 👍

@xconverge
Copy link
Member

This is not the case for all filetypes, if a file is not named, it does not do this. Not a big deal though...

@rebornix
Copy link
Member

From my observation, the leading white spaces are only deleted if they are added by Vim's autoindent feature. It means if the indentation is added by users and then you press <ESC>, they won't be deleted. That explains why you can't experience this feature in an unnamed file as Vim has no idea about indentation.

So right now, the question is how we detect whether the white spaces are added by users or not? And how we avoid deleting users' input.

@rebornix
Copy link
Member

I think that's maybe why I say there is no easy issue any more ;(

@Zzzen
Copy link
Contributor Author

Zzzen commented Oct 22, 2016

Yeah, this is a hard one. It should be easy to get current file type from VSCode. But how to avoid deleting spaces input by users is difficult. 😥 where do we store user keyboard input? And I noticed that if you create newlines by pressing Enter and then press Esc, vim will clear current line and lines above (Though VSCode has remove the trailing spaces, nice)

@Zzzen
Copy link
Contributor Author

Zzzen commented Oct 22, 2016

It seems that removing leading spaces is triggered only if the last action is inserting new line, ie, pressing o in normal mode, press Enter in insert mode.

@Zzzen
Copy link
Contributor Author

Zzzen commented Oct 22, 2016

How about this? Only when the last action before <Esc> is "o" || "O" || "\n" and language identifier is not "plaintext" will we clear current line. Your guidance will be helpful. @rebornix

@rebornix
Copy link
Member

rebornix commented Oct 24, 2016

@Zzzen I love your trick here, even though it might not be the same implementation as Vim. To avoid confusing other maintainers, do you mind adding comments before the change then we should be good to go.

And of course, rebase to the master :)

@Zzzen
Copy link
Contributor Author

Zzzen commented Oct 25, 2016

That should look better now. One problem remains that I cannot create a test case it takes effect since filename is created randomly and vscode regards them as plaintext. It seems that currently we are not able to switch language mode programmatically.

@rebornix rebornix merged commit 3814252 into VSCodeVim:master Oct 25, 2016
@rebornix
Copy link
Member

@Zzzen LGTM thanks!

This pull request was closed.
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.

In insert mode, should remove leading spaces if <ESC> or <Ctrl-c> is pressed
3 participants