Skip to content

fix(bug): process unicode character properly#107

Merged
YousefHadder merged 1 commit intoYousefHadder:mainfrom
SuniRein:main
Nov 4, 2025
Merged

fix(bug): process unicode character properly#107
YousefHadder merged 1 commit intoYousefHadder:mainfrom
SuniRein:main

Conversation

@SuniRein
Copy link
Copy Markdown
Contributor

@SuniRein SuniRein commented Nov 4, 2025

Description

Make <BS> delete multi-byte unicode character properly.

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Code refactoring
  • Performance improvement

Related Issues

Fixes #106

Testing

  • Tested manually
  • Added/updated tests (if applicable)

Checklist

  • Code follows project style
  • Self-reviewed my code
  • Commented complex logic
  • Updated documentation (if needed)
  • No new warnings generated

Copilot AI review requested due to automatic review settings November 4, 2025 06:13
Copy link
Copy Markdown
Contributor

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

This PR improves multi-byte character support in the backspace handler for non-list lines. The change replaces simple byte-based string slicing with character-aware operations using vim.fn.charidx() and vim.fn.byteidx(), and switches from manual string manipulation to nvim_buf_set_text() API.

  • Converts byte-based backspace deletion to character-aware deletion for multi-byte characters (e.g., emojis, non-ASCII)
  • Adds guard against attempting to delete before the start of the line
  • Uses Neovim's native buffer text API for more robust text manipulation
Comments suppressed due to low confidence (1)

lua/markdown-plus/list/handlers.lua:315

  • The backspace handling within list content (lines 310-315) still uses byte-based string slicing, which will fail to properly delete multi-byte characters. This is inconsistent with the fix applied to non-list backspace (lines 282-289). The same character-aware logic using vim.fn.charidx() and vim.fn.byteidx() should be applied here.
  -- Default backspace in list content
  if col > 0 then
    local new_line = current_line:sub(1, col - 1) .. current_line:sub(col + 1)
    utils.set_line(row, new_line)
    utils.set_cursor(row, col - 1)
  end

@SuniRein SuniRein changed the title fix: process unicode character properly fix(bug): process unicode character properly Nov 4, 2025
Copy link
Copy Markdown
Owner

@YousefHadder YousefHadder left a comment

Choose a reason for hiding this comment

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

LGTM, Thank you for contributing the fix.

@YousefHadder YousefHadder merged commit 968d132 into YousefHadder:main Nov 4, 2025
14 checks passed
@YousefHadder
Copy link
Copy Markdown
Owner

@all-contributors please add @SuniRein for code

@allcontributors
Copy link
Copy Markdown
Contributor

@YousefHadder

I've put up a pull request to add @SuniRein! 🎉

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] <BS> could not process multi-byte charcter

3 participants