Skip to content
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

[Bug]: Cyrillic words tear apart #1

Closed
WhiteBlackGoose opened this issue Jan 13, 2023 · 4 comments
Closed

[Bug]: Cyrillic words tear apart #1

WhiteBlackGoose opened this issue Jan 13, 2023 · 4 comments

Comments

@WhiteBlackGoose
Copy link

Hey there.

Great plugin! Really needed it for some time, but didn't have time to make it myself. Imma use it now.

Repro of the bug:
Type a word:

Привет

Invoke any command (italics/bold/link)

Here's what you get:

⨪鿐胑룐닐뗐⫑航

Peek 2023-01-13 14-51

@antonk52
Copy link
Owner

Glad you found useful and thanks for the bug report.

I looks like lua/neovim treats cyrillic characters rent to latin ones.

vim.split('привет', '')
{ "<d0>", "<bf>", "<d1>", "<80>", "<d0>", "<b8>", "<d0>", "<b2>", "<d0>", "<b5>", "<d1>", "<82>" }

I will try to look into this over the weekend. If you know of a solution do let me know.

@Wansmer
Copy link

Wansmer commented Jan 13, 2023

If you know of a solution do let me know.

I think you can try this approach for handling non english (non one byte chars) text:

-- NOTE: example work only when cursor on last char of selection and only charwise visual mode.
-- Edge cases are also not taken into account.
vim.keymap.set('x', '<c-b>', function()
  -- get visual selection range
  -- for case when curson on start char it need reorder (sr = er, er = sr e.t.c)
  local er, ec = unpack(vim.fn.getpos('.'), 2, 3)
  local sr, sc = unpack(vim.fn.getpos('v'), 2, 3)

  -- save real text in 'v' register (no independent of count byte in char)
  vim.cmd.normal('"vy')
  local text = vim.split(vim.fn.getreg('v'), '\n', { plain = true })
  -- clear register
  vim.fn.setreg('v', '')

  -- check two byte on end of range
  local last_row = vim.fn.getline(er)
  local char = last_row:sub(ec, ec + 1)

  local last_col
  if #char ~= 0 then
    if #char == vim.fn.strdisplaywidth(char) then
      -- if display len equals with byte len, use normal end col
      last_col = ec
    else
      print('else')
      -- if display len not equals with byte len, use delta
      last_col = #char - vim.fn.strdisplaywidth(char) + ec
    end
  else
    last_col = 0
  end

  local prefix = '**'
  local postfix = '**'

  text[1] = prefix .. text[1]
  text[#text] = text[#text] .. postfix

  vim.api.nvim_buf_set_text(0, sr - 1, sc - 1, er - 1, last_col, text)
end)
markdowny.mov

Hope this will help

@gerazov
Copy link

gerazov commented Jan 18, 2023

👍 for fixing this.

@antonk52
Copy link
Owner

I was able to fix this in 4e84ca3. Thanks to the @Wansmer 's comment. I ended up doing it slightly different. Though, now it also supports [un]surrounding without having to have the cursor on the last character.

Thanks everyone

ful1e5 added a commit to ful1e5/markdowny.nvim that referenced this issue Feb 14, 2023
I (@ful1e5) have fully rewritten the plugin and incorporated the
requested newline and singleline surroundings in code block described in
issue antonk52#7, while also taking into consideration issue antonk52#1.
antonk52 pushed a commit that referenced this issue Feb 18, 2023
I (@ful1e5) have fully rewritten the plugin and incorporated the
requested newline and singleline surroundings in code block described in
issue #7, while also taking into consideration issue #1.
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

No branches or pull requests

4 participants