Skip to content

Fix visual selection range handling for :'<,'>ClaudeCodeSend #26

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

Merged
merged 2 commits into from
Jun 11, 2025

Conversation

blink-so[bot]
Copy link
Contributor

@blink-so blink-so bot commented Jun 9, 2025

Summary

This change adds robust range-selection support to ClaudeCodeSend and fixes a related test instability.

:'<,'>ClaudeCodeSend now works reliably after leaving visual mode by reading the '< and '> marks.
• Existing visual/tracked-selection behaviour remains unchanged.
• Unit tests now cover range scenarios.
terminal_module.setup is called only when the stub exposes it, preventing unit-test crashes.

Implementation highlights

  1. selection.lua
    • Added get_range_selection(line1, line2) helper to extract text via marks.
    send_at_mention_for_visual_selection accepts optional line1/line2.

  2. init.lua
    ClaudeCodeSend detects command-range usage and forwards line1, line2.
    • Guarded terminal_module.setup call with a type check.

  3. tests/
    • New tests/unit/claudecode_send_command_spec.lua verifies command registration, parameter passing, and edge cases.

Issue fixed

Fixes #25:'<,'>ClaudeCodeSend previously reported “No visual selection”.

@blink-so blink-so bot force-pushed the fix-visual-selection-range branch 5 times, most recently from 0c2a914 to 19315c4 Compare June 11, 2025 08:03
Adds range-selection handling via marks, fixes visual selection fallback, and guards
terminal.setup call for tests. Resolves #25.

Co-authored-by: Thomas Kosiewski <[email protected]>
@blink-so blink-so bot force-pushed the fix-visual-selection-range branch from 19315c4 to f793344 Compare June 11, 2025 08:23
@ThomasK33 ThomasK33 requested a review from Copilot June 11, 2025 10:22
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Enhance ClaudeCodeSend to correctly handle range selections from :'<,'>, improve test stability, and guard terminal setup in test environments.

  • Added get_range_selection for extracting text by marks and extended send_at_mention_for_visual_selection to accept optional range arguments.
  • Updated command registration in init.lua to forward line1/line2, exit visual mode, and focus the terminal only when available.
  • Expanded unit tests to cover valid/invalid range cases and prevent test crashes by conditioning terminal_module.setup.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/unit/claudecode_send_command_spec.lua Added range-related tests and a guarded restore of the original require.
tests/selection_test.lua Introduced comprehensive get_range_selection and range-send tests.
lua/claudecode/visual_commands.lua Added safe fallback to vim.fn.mode for mode checks in test environments.
lua/claudecode/selection.lua Implemented get_range_selection and range-aware send_at_mention_for_visual_selection.
lua/claudecode/init.lua Forwarded range parameters in command callback and guarded terminal.setup.


after_each(function()
-- Restore original require
_G.require = require
Copy link
Preview

Copilot AI Jun 11, 2025

Choose a reason for hiding this comment

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

The after_each hook restores require to the already-overridden global instead of the original. Change _G.require = require to _G.require = original_require so the original loader is properly restored.

Suggested change
_G.require = require
_G.require = original_require

Copilot uses AI. Check for mistakes.

@@ -44,7 +44,11 @@ function M.validate_visual_mode()

-- Use pcall to handle test environments
local mode_success = pcall(function()
current_mode = vim.api.nvim_get_mode().mode
if vim.api and vim.api.nvim_get_mode then
Copy link
Preview

Copilot AI Jun 11, 2025

Choose a reason for hiding this comment

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

[nitpick] The mode‐detection logic (vim.api.nvim_get_mode vs vim.fn.mode) is duplicated across functions. Consider extracting it into a shared helper to reduce repetition and make future updates easier.

Copilot uses AI. Check for mistakes.

…tection helper

- Fix require restoration in test file to use original_require variable
- Extract mode detection logic to shared helper function to reduce duplication
- All quality gates pass: nix fmt, make check, make test

Co-authored-by: ThomasK33 <[email protected]>
@ThomasK33 ThomasK33 merged commit 72a4a41 into main Jun 11, 2025
4 checks passed
@ThomasK33 ThomasK33 deleted the fix-visual-selection-range branch June 11, 2025 10: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.

[BUG] :'<,'>ClaudeCodeSend doesn't see the selection
1 participant