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

Auto indent on insert_at_line_start #5837

Merged

Conversation

CptPotato
Copy link
Contributor

@CptPotato CptPotato commented Feb 5, 2023

First attempt at #4859. This makes I and A automatically indent, but only if the line is empty. Otherwise it behaves exactly as before. I thought about also handling indentation when the line only contains white space, but I left this out for now. Either way, this is a breaking change.

I roughly followed the implementation of open_above/open_below. Though, I'm not sure if the implementation is very good, all the text editing functions in the code base are new to me.

Here's the result of insert_at_line_start / I with this change (the only difference is on the empty line):

before master this PR
image image image

I tried to handle all edge cases (i.e. cursor is at document start/end, multiple selections) and so far it seems to work. I also plan to make insert_at_line_end behave similarly.

Edit: insert_at_line_end now works the same.

closes #4859

@pascalkuthe
Copy link
Member

I haven't looked too closely at the implementation yet but this does seem very useful to me and like a better default too. Thanks for working on this!

That being said we might want to keep the old behaviour as a seperate command so people that don't like this change can rebind.

@pascalkuthe pascalkuthe added E-medium Call for participation: Experience needed to fix: Medium / intermediate S-waiting-on-review Status: Awaiting review from a maintainer. labels Feb 5, 2023
Copy link
Member

@pascalkuthe pascalkuthe left a comment

Choose a reason for hiding this comment

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

The idea is good I think, the implementation can be simplified (and is not quite correct, see review comments)

helix-term/src/commands.rs Outdated Show resolved Hide resolved
helix-term/src/commands.rs Outdated Show resolved Hide resolved
helix-term/src/commands.rs Outdated Show resolved Hide resolved
helix-term/src/commands.rs Outdated Show resolved Hide resolved
helix-term/src/commands.rs Outdated Show resolved Hide resolved
helix-term/src/commands.rs Outdated Show resolved Hide resolved
helix-term/src/commands.rs Outdated Show resolved Hide resolved
helix-term/src/commands.rs Outdated Show resolved Hide resolved
helix-term/src/commands.rs Outdated Show resolved Hide resolved
@pascalkuthe pascalkuthe added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from a maintainer. labels Feb 5, 2023
@CptPotato
Copy link
Contributor Author

Thanks for the detailed review and pointers @pascalkuthe. I expected that I was doing a lot of these things sub-optimally. I'll try to address these issues soon.

Copy link
Member

@pascalkuthe pascalkuthe left a comment

Choose a reason for hiding this comment

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

Two minor nits otherwise the implementation now LGTM.

helix-term/src/commands.rs Outdated Show resolved Hide resolved
helix-term/src/commands.rs Outdated Show resolved Hide resolved
@CptPotato
Copy link
Contributor Author

I made the last suggested changes, thanks again.

I also created a second commit that adds the same behavior to insert_at_line_end by moving the indent code to a separate function.

@CptPotato CptPotato marked this pull request as ready for review February 5, 2023 15:50
@kirawi kirawi added the A-helix-term Area: Helix term improvements label Feb 5, 2023
@pascalkuthe pascalkuthe added C-enhancement Category: Improvements S-waiting-on-review Status: Awaiting review from a maintainer. E-easy Call for participation: Experience needed to fix: Easy / not much and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. E-medium Call for participation: Experience needed to fix: Medium / intermediate labels Feb 5, 2023
@CptPotato
Copy link
Contributor Author

Should I look into creating a test for the new behavior?

@pascalkuthe
Copy link
Member

Should I look into creating a test for the new behavior?

I believe there is currently no tests for the existing behaviour so I wouldn't consider it a blocking issue but more tests are always good so if you want to add them go ahead

@CptPotato
Copy link
Contributor Author

CptPotato commented Feb 10, 2023

I added a test and found one remaining issue (which I fixed).

The test is a little ugly but it's the best I could do 👀
It checks both insert_at_line_start/end on all lines with this snippet:

fn foo() {
    if let Some(_) = None {

    }
 
}

fn bar() {

}

(there's one line with existing whitespace)

Is this okay or should I change the test?

@CptPotato
Copy link
Contributor Author

Looks like some recent changes are causing conflicts.

Let me know when somebody wants to review this and I'll resolve them.

pascalkuthe
pascalkuthe previously approved these changes Apr 13, 2023
Copy link
Member

@pascalkuthe pascalkuthe left a comment

Choose a reason for hiding this comment

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

I have been testing this for a bit and did a pretty thorough review a while ago. Once the bugfix release (23.3.1) is done we can resolve the conflicts here (should be pretty easy) I think we can land this

@the-mikedavis the-mikedavis self-requested a review May 5, 2023 00:21
@CptPotato CptPotato force-pushed the insert-at-line-start-indent branch from e4f9138 to e772d1b Compare May 7, 2023 07:39
@CptPotato
Copy link
Contributor Author

Sorry for the long delay. I rebased onto latest master, should be good to go now.

@archseer archseer added this to the next milestone May 18, 2023
Copy link
Member

@the-mikedavis the-mikedavis left a comment

Choose a reason for hiding this comment

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

I have a small style nit but otherwise I think this looks great (especially the integration tests!)

helix-term/src/commands.rs Outdated Show resolved Hide resolved
Copy link
Member

@pascalkuthe pascalkuthe left a comment

Choose a reason for hiding this comment

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

thanks for working on this! This is a great QOL improvement

@pascalkuthe pascalkuthe merged commit 993c68a into helix-editor:master Jun 8, 2023
@CptPotato CptPotato deleted the insert-at-line-start-indent branch June 8, 2023 17:30
Triton171 pushed a commit to Triton171/helix that referenced this pull request Jun 18, 2023
wes-adams pushed a commit to wes-adams/helix that referenced this pull request Jul 4, 2023
mtoohey31 pushed a commit to mtoohey31/helix that referenced this pull request Jun 2, 2024
smortime pushed a commit to smortime/helix that referenced this pull request Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements C-enhancement Category: Improvements E-easy Call for participation: Experience needed to fix: Easy / not much S-waiting-on-review Status: Awaiting review from a maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

insert_at_line_start with autoindent
6 participants