Enter before indented Java line comment removes indentation
- Dominant language
- Java
- Stars
- 3.1k
- Forks
- 935
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 17
Description
### Apache NetBeans version
Apache NetBeans 30
### What happened
When pressing Enter immediately in front of an indented Java line comment, the indentation of the line comment is not maintained. This is inconsistent with the behavior of pressing Enter before other indented elements.
It is also inconsistent with pressing Enter on an earlier column before the start of the line column, which does maintain the comment's indentation.
It is furthermore inconsistent with the behavior of pressing Enter on front of a block comment (`/* ... */`), even for a single-line one.
### Language / Project Type / NetBeans Component
Java, Editor
### How to reproduce
Example:
```java
class Example
{
Example()
{
int x = 5;
// some comment
// second line
int y = 7;
}
}
```
With the input caret at the beginning of "//" (column 9), pressing Enter (to insert a line before the comment) results in the indentation of the line comment being removed:
```java
class Example
{
Example()
{
int x = 5;
// some comment
// second line
int y = 7;
}
}
```
The same happens when pressing Enter before subsequent line comments:
```java
class Example
{
Example()
{
int x = 5;
// some comment
// second line
int y = 7;
}
}
```
This is inconsistent with how indentation behaves for non-comment lines. For example, pressing Enter before `int` maintains the indentation of the statement.
When pressing Enter at an earlier column, for example on column 8, the indentation of the comment is maintained (however the indentation of the now-empty line before the caret is correspondingly shorter):
```java
class Example
{
Example()
{
int x = 5;
← empty line ends here
// some comment
// second line
int y = 7;
}
}
```
Compare also with the behavior for a block comment, which remains properely indented when pressing Enter in front of it:
```java
class Example
{
Example()
{
int x = 5;
/* block comment */
int y = 7;
}
}
```
### Did this work correctly in an earlier version?
No / Don't know
### Operating System
Windows 11
### JDK
JDK 21
### Apache NetBeans packaging
Apache NetBeans binary zip
### Anything else
_No response_
### Are you willing to submit a pull request?
No
Contributor guide
Research direction
Reproduce the issue in the NetBeans Java Editor using the example and the caret at the start of an indented line comment. Trace the Enter-key handling for line comments and compare it with block comments and ordinary statements. Done means indentation is retained when inserting a line before either comment, with regression coverage for the reported cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100