Skip to content

onEnterRules should be multi-line aware #50952

Open

Description

@kghose

Use case: microsoft/vscode-cpptools#2072
Steps to Reproduce:

Type the following text in a .cpp file

a = a
    * b;

Then hit enter at the end of the line to begin a new line. You'll get

a = a
    * b;
    * 

This is not expected behavior in this context. This is perhaps expected when in the middle of a multiline decorated comment but not otherwise.

This does not happen in an unsaved file, a file with no extension, .txt extension etc. and does not happen if the cpptools extension is disabled and happens when it is re-enabled.

Activity

  1. added
    editor-core
    on Jun 1, 2018
  2. aeschli commented on Jun 4, 2018

    @aeschli
    Contributor

    The CPP extension sets onEnterRules like TypeScript:

    onEnterRules: [
    		{
    			// e.g. /** | */
    			beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
    			afterText: /^\s*\*\/$/,
    			action: { indentAction: IndentAction.IndentOutdent, appendText: ' * ' }
    		}, {
    			// e.g. /** ...|
    			beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
    			action: { indentAction: IndentAction.None, appendText: ' * ' }
    		}, {
    			// e.g.  * ...|
    			beforeText: /^(\t|[ ])*[ ]\*([ ]([^\*]|\*(?!\/))*)?$/,
    			action: { indentAction: IndentAction.None, appendText: '* ' }
    		}, 
    

    Looks like the last rule matches here and causes the observed behavior.

  3. changed the title [-]Regexp should be multi-line aware[/-] [+]onEnterRules should be multi-line aware[/+] on Jun 4, 2018
  4. added
    bug
    languages-basic
    and removed
    editor-core
    on Jun 4, 2018
  5. bobbrow commented on Jul 20, 2018

    @bobbrow

    The user wants to keep the last rule when inside a multiline comment, but from what I understand the beforeText can only match a single line, so it appears that there's no way for us to write a rule that can detect whether we're in a multiline comment or not (e.g. by looking at the previous line).

  6. added
    editor-autoindent
    and removed on Sep 18, 2018
  7. added
    feature-request
    and removed
    bug
    on Nov 3, 2020
  8. Hacker1337 commented on May 17, 2025

    @Hacker1337

    It seems like the described behaviour is fixed, but the main issue is still there. onEnterRules should be multi-line aware. I have example where this is very annoying in my usecase.
    from this position

    big_returned_output_type BigNameOfTheFunction(very_long_name_of_the_argument_one,
                                                  very_long_name_of_the_argument_two) {|
        
    }
    

    enter transfers you to

    big_returned_output_type BigNameOfTheFunction(very_long_name_of_the_argument_one,
                                                  very_long_name_of_the_argument_two) {
                                                    |    
    }
    

    instead of

    big_returned_output_type BigNameOfTheFunction(very_long_name_of_the_argument_one,
                                                  very_long_name_of_the_argument_two) {
        |
    }
    

    And then you have to erase quite a bit to get to the right indention level. While probably onEnter should just recognise both lines as the whole expression due to unclosed brackets. And indent with respect to beginning of expression.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

editor-autoindentfeature-requestlanguages-basic

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions