Skip to content

[BUG] error in toggle_format for multi-byte char #124

@SuniRein

Description

@SuniRein

Description

When using toggle_format for multi-byte char, only the first byte of the last char will be chosen.

Steps to Reproduce

  1. Type 这是一段文本.
  2. Visual selection it.
  3. Type <leader>mb.
  4. is split to 3 bytes, and ** is add after the first byte.

Expected Behavior

**这是一段文本**

Actual Behavior

Image

Environment

  • Neovim version: 0.11.5
  • Plugin version: e1eb10b
  • OS: Linux

Additional Context

It happened due to utils.get_visual_selection, in which vim.fn.getpos is used to get the end_col. However, it will return the pos of the first byte instead.

In fact, many vim APIs are designed for byte, which could not handle multi-byte char correctly. It is more recommanded to use neovim APIs like nvim_buf_get_mark. But it need huge changes. So a compromise method may be acceptable, to use byteidx to get the last byte of the char.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions