Skip to content

Conversation

@claude
Copy link

@claude claude bot commented Jan 5, 2026

Summary

Fixes VIM-2431: Mapping with <Action> doesn't accept count

When using <Action> mappings (e.g., map gj <Action>(EditorCloneCaretBelow)), the count prefix (like 5gj) was being ignored and the action executed only once instead of the expected number of times.

Changes

  • vim-engine/.../MappingInfo.kt: Modified ToActionMappingInfo.execute() to extract the count from keyState.commandBuilder.calculateCount0Snapshot() and execute the action in a repeat() loop
  • MapCommandTest.kt: Added tests for count behavior with <Action> mappings (no count, count of 3, and large count of 10)
  • CHANGES.md and build.gradle.kts: Added changelog entry

How it works

The fix follows the same pattern used in ToHandlerMappingInfo.execute() which correctly handles counts. Now 5gj with a mapped <Action> will execute that action 5 times, matching Vim's expected behavior.


🔗 Workflow run: https://github.com/JetBrains/ideavim/actions/runs/20710306859

🤖 Generated with Claude Code

When using <Action> mappings (e.g., 'map gj <Action>(EditorCloneCaretBelow)'),
the count prefix (like '5gj') was being ignored and the action executed only
once instead of the expected number of times.

This fix modifies ToActionMappingInfo.execute() to:
- Extract the count from keyState.commandBuilder.calculateCount0Snapshot()
- Execute the action the specified number of times using repeat()
- Default to 1 execution when no count is specified

Added tests to verify count behavior with <Action> mappings.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@claude
Copy link
Author

claude bot commented Jan 5, 2026

Code Review

Implementation (MappingInfo.kt:272-279)

Issue: Count logic inconsistent with ToHandlerMappingInfo

The fix uses calculateCount0Snapshot().coerceAtLeast(1), but ToHandlerMappingInfo (line 198) passes calculateCount0Snapshot() directly to OperatorArguments without coercing. This means ToHandlerMappingInfo preserves the 0 count semantic (0 means no count specified), while ToActionMappingInfo converts it to 1.

The current implementation will treat an explicit count of 0 the same as count 1, which may not match Vim behavior where 0 can have special meaning in some contexts.

Suggestion: Check if IntelliJ actions should receive the raw count or if coercion is correct. Consider aligning with ToHandlerMappingInfo pattern.

Tests (MapCommandTest.kt:1305-1368)

Coverage: Good - tests no count, normal count (3), and large count (10)

Missing: No test for explicit count of 0 (e.g., 0gj). While this may be an edge case, it would clarify intended behavior.

Minor Issues

  1. MappingInfo.kt:276: LOG.trace includes iteration details that may not add value in production
  2. Tests: All three tests use the same pattern - could be parameterized to reduce duplication

Verdict

Implementation is correct for the common case. Consider testing count=0 behavior to ensure alignment with Vim semantics.

@AlexPl292 AlexPl292 closed this Jan 16, 2026
@AlexPl292 AlexPl292 deleted the fix/vim-2431-action-mapping-count branch January 16, 2026 11:48
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.

1 participant