fix(multibyte): handle utf-8 multibyte characters in text manipulation operations#146
Merged
YousefHadder merged 2 commits intomainfrom Nov 30, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a critical bug where text manipulation operations (list handling, link/image/footnote insertion) were corrupting UTF-8 multibyte characters (Chinese, emoji, etc.) by incorrectly using byte-level string operations instead of character-aware operations.
Key Changes
- Introduced two new UTF-8-safe utility functions (
split_at_cursorandsplit_after_cursor) that properly handle character boundaries usingvim.fn.charidxandvim.fn.byteidx - Updated all text manipulation operations across the codebase to use these new utilities instead of direct byte-level
string.sub()calls - Added comprehensive test coverage (142 new test cases) for the utility functions covering ASCII, Chinese characters, emoji, and edge cases
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
spec/markdown-plus/utils_spec.lua |
Adds 142 lines of comprehensive UTF-8 tests for both new utility functions, covering ASCII, Chinese, emoji, and edge cases |
lua/markdown-plus/utils.lua |
Implements two new UTF-8-safe string splitting functions with proper character boundary detection using vim functions |
lua/markdown-plus/list/handlers.lua |
Updates handle_enter, continue_list_content, and handle_tab to use UTF-8-safe splitting for list content manipulation |
lua/markdown-plus/links/init.lua |
Updates insert_link to use UTF-8-safe splitting and corrects cursor positioning after insertion |
lua/markdown-plus/images/init.lua |
Updates insert_image to use UTF-8-safe splitting and corrects cursor positioning after insertion |
lua/markdown-plus/format/init.lua |
Refactors get_word_boundaries to iterate by characters instead of bytes, with proper UTF-8 boundary detection |
lua/markdown-plus/footnotes/insertion.lua |
Updates insert_footnote to use UTF-8-safe splitting for reference insertion |
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.
Fixes #144 footnote, link, image insertion, and list operations corrupting multibyte UTF-8 characters (Chinese, emoji, etc.) by using character-level string splitting instead of byte-level operations.