fix(bug): correct multi-byte character handling in get_visual_selection#126
Merged
YousefHadder merged 4 commits intomainfrom Nov 14, 2025
Merged
fix(bug): correct multi-byte character handling in get_visual_selection#126YousefHadder merged 4 commits intomainfrom
YousefHadder merged 4 commits intomainfrom
Conversation
12 tasks
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a bug where get_visual_selection incorrectly handled multi-byte characters (e.g., Chinese, emoji) by returning only the first byte of the last character instead of the complete character. The fix ensures proper UTF-8 handling using Neovim's native APIs.
- Added
get_char_end_byte()helper function to convert byte positions for multi-byte characters - Updated
get_visual_selection()to properly handle multi-byte characters in both active and previous visual selections - Added comprehensive test coverage with 13 new test cases covering ASCII, multi-byte, and mixed content scenarios
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lua/markdown-plus/utils.lua | Added get_char_end_byte() helper and updated get_visual_selection() to adjust end_col for multi-byte characters in both active and previous visual modes |
| spec/markdown-plus/utils_spec.lua | Added 13 test cases covering get_char_end_byte() function and visual selection with multi-byte characters |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes issue #124 where
get_visual_selectionreturns the first byte of the last character instead of the complete character when dealing with multi-byte characters (e.g., Chinese, emoji).Changes
get_char_end_byte()helper function to properly convert byte positions for multi-byte charactersget_visual_selection()to handle multi-byte characters in both active and previous visual selectionsvim.str_utfindexandvim.str_byteindexAPIs for robust UTF-8 handlingType of Change
Related Issues
Fixes #124
Testing
Checklist