-
Notifications
You must be signed in to change notification settings - Fork 802
Maintenance: InsertDeleteInsertedTextAction - Remove wildcard import and dead code #1391
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
base: master
Are you sure you want to change the base?
Conversation
…and dead code Clean up code quality issues in InsertDeleteInsertedTextAction: - Replace wildcard import java.util.* with explicit EnumSet import - Remove unreachable dead code: the check for deleteTo != -1 was always true since getLeadingCharacterOffset never returns -1 - Simplify logic: directly check if there's nothing to delete (deleteTo == offset) - Add comprehensive edge case tests for empty lines, whitespace-only lines, and various insertion scenarios 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
|
|
||
| // If there's nothing to delete (deleteTo == offset), skip deletion | ||
| if (deleteTo == offset) { | ||
| return true |
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.
Good defensive programming: This early return check prevents unnecessary deletion attempts. However, I have a concern about the logic flow:
The PR description states this replaces "dead code" that checked if (deleteTo != -1), but the new check if (deleteTo == offset) serves a different purpose. Looking at the function flow:
- Line 52:
deleteTois initialized tocaret.vimInsertStart.startOffset - Line 54-56: If cursor hasn't moved from insert start,
deleteTois reassigned to skip leading whitespace - Line 59-61: If still nothing to delete, return early
Potential issue: What if moveCaretToCurrentLineStartSkipLeading() on line 55 returns the same value as the initial deleteTo? According to getLeadingCharacterOffset(), it returns the position of the first non-whitespace character OR the end of line for whitespace-only lines. This means:
- On empty lines: returns line end offset
- On whitespace-only lines: returns line end offset
- On normal lines: returns first non-whitespace offset
If the caret is already at the insert start AND that insert start is at the beginning of leading whitespace, this check would prevent deletion even when the user might expect to delete the leading whitespace up to the first character.
Question: Is this the intended Vim behavior? Should <C-U> delete leading whitespace when pressed at the start of an insert that began in the whitespace?
| } | ||
|
|
||
| @Test | ||
| fun `test C-U at start of insert on empty line`() { |
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.
Test coverage is good but there's a missing edge case: What happens when you start insert mode at the beginning of leading whitespace and immediately press <C-U>?
Example:
@Test
fun `test C-U at start of insert in leading whitespace`() {
configureByText("${c} text")
typeText("i")
typeText("<C-U>")
// What should happen here? Delete whitespace or no-op?
assertState("???")
}This would help verify the behavior I questioned in the other comment.
| fun `test C-U with text inserted after existing content`() { | ||
| configureByText(" text${c}") | ||
| typeText("A") | ||
| typeText(" more") | ||
| assertState(" text more${c}") | ||
| assertMode(Mode.INSERT) | ||
| typeText("<C-U>") | ||
| assertState(" text${c}") | ||
| assertMode(Mode.INSERT) | ||
| } | ||
|
|
||
| @Test | ||
| fun `test C-U in middle of line after inserting text`() { |
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.
Excellent test cases! These thoroughly cover the scenarios mentioned in the PR description. The test names are descriptive and follow the project's naming conventions.
Minor suggestion: Consider adding a test for multiple <C-U> presses in sequence to ensure it behaves correctly (should only delete on first press, then no-op afterward when at insert start).
Pull Request ReviewSummaryThis PR performs maintenance on Positive Aspects ✅
Concerns and Questions
|
Summary
Performed maintenance on
InsertDeleteInsertedTextAction.ktand its test file to improve code quality and test coverage.Area Inspected
vim-engine/src/main/kotlin/com/maddyhome/idea/vim/action/change/insert/InsertDeleteInsertedTextAction.ktsrc/test/java/org/jetbrains/plugins/ideavim/action/change/insert/InsertDeleteInsertedTextActionTest.ktIssues Found
1. Wildcard Import
import java.util.*which is discouraged per maintenance guidelinesEnumSetwas actually used from this package2. Dead Code
if (deleteTo != -1)on line 57 was unreachablegetLeadingCharacterOffset()never returns -1; it returns either:falsethrough this code path3. Test Coverage Gaps
Changes Made
Code Quality Improvements
import java.util.EnumSet-1check with a meaningful check fordeleteTo == offsetto skip deletion when there's nothing to deleteTest Coverage Enhancements
Added 4 new comprehensive test cases:
test C-U at start of insert on empty line- Verifies no-op behavior on empty linestest C-U at start of insert on line with only whitespace- Tests whitespace-only linestest C-U with text inserted after existing content- Tests deletion after appending texttest C-U in middle of line after inserting text- Tests insertion in the middle of existing textWhy These Changes Improve the Code
🤖 Generated with Claude Code