From cdf4da886be2839ba68703b2bb102912feee9579 Mon Sep 17 00:00:00 2001 From: fedepujol <9yjbd325@anonaddy.me> Date: Fri, 25 Feb 2022 11:26:30 -0300 Subject: [PATCH 01/12] First idea on handle unicode characters --- lua/core/horiz.lua | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/lua/core/horiz.lua b/lua/core/horiz.lua index 55c0ea9..d0537d9 100644 --- a/lua/core/horiz.lua +++ b/lua/core/horiz.lua @@ -13,24 +13,38 @@ M.horzChar = function(dir) local suffix = '' local result = {} local line_res = '' + local selected = '' -- Checks line limits with the direction if dir < 0 and col < 1 then return end - local selected = string.sub(line, col + 1, col + 1) + local unicode = vim.api.nvim_exec(':normal! g8', true) + unicode = string.gsub(unicode, '%s+$', '') + prefix = string.sub(line, 1, col + (dir > 0 and 0 or dir)) + + if unicode:len() > 2 then + vim.cmd(':normal! x') + selected = vim.fn.getreg('"0') + else + selected = string.sub(line, col + 1, col + 1) + end -- Put a space if the character reaches the end of the line if col == line:len() - 1 and dir > 0 then target = ' ' + elseif unicode:len() > 5 then + target = string.sub(line, col + dir + 1 + (dir > 0 and 2 or 0), col + dir + 1 + (dir > 0 and 2 or 0)) + suffix = string.sub(line, col + (dir > 0 and 5 or 4)) + elseif unicode:len() > 2 then + target = string.sub(line, col + dir + 1 + (dir > 0 and 1 or 0), col + dir + 1 + (dir > 0 and 1 or 0)) + suffix = string.sub(line, col + (dir > 0 and 4 or 3)) else - target = string.sub(line, col + 1 + dir, col + 1 + dir) + target = string.sub(line, col + dir + 1, col + dir + 1) + suffix = string.sub(line, col + (dir > 0 and 3 or 2)) end - prefix = string.sub(line, 1, col + (dir > 0 and 0 or -1)) - suffix = string.sub(line, col + (dir > 0 and 3 or 2)) - -- Remove trailing spaces before putting into the table line_res = prefix..(dir > 0 and target..selected or selected..target)..suffix line_res = line_res:gsub('%s+$', '') From ec05f7049ae99680a177e30a18a7acf875a53e06 Mon Sep 17 00:00:00 2001 From: fedepujol <9yjbd325@anonaddy.me> Date: Fri, 25 Feb 2022 19:05:56 -0300 Subject: [PATCH 02/12] Utils to handle unicode --- lua/core/horiz.lua | 57 ++++++++++++++++++++++++++++++++++++---------- lua/utils/init.lua | 44 +++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 12 deletions(-) diff --git a/lua/core/horiz.lua b/lua/core/horiz.lua index d0537d9..6ac2f5b 100644 --- a/lua/core/horiz.lua +++ b/lua/core/horiz.lua @@ -15,36 +15,69 @@ M.horzChar = function(dir) local line_res = '' local selected = '' + local sUnicode = '' + local tUnicode = '' + -- Checks line limits with the direction if dir < 0 and col < 1 then return end - local unicode = vim.api.nvim_exec(':normal! g8', true) - unicode = string.gsub(unicode, '%s+$', '') + -- Default prefix = string.sub(line, 1, col + (dir > 0 and 0 or dir)) - if unicode:len() > 2 then - vim.cmd(':normal! x') - selected = vim.fn.getreg('"0') + -- Unicode or tilde character + sUnicode = vim.api.nvim_exec(':normal! g8', true) + sUnicode = string.gsub(sUnicode, '%s+$', '') + + if isTilde(sUnicode) then + selected = getUnicodeOrTilde() else selected = string.sub(line, col + 1, col + 1) end + -- Check if target is unicode or tilde + if isTilde(sUnicode) and dir < 0 then + vim.api.nvim_win_set_cursor(0, { sRow, col + dir }) + end + tUnicode = vim.api.nvim_exec(':normal! g8', true) + tUnicode = string.gsub(tUnicode, '%s+$', '') + -- Put a space if the character reaches the end of the line + -- Default if col == line:len() - 1 and dir > 0 then target = ' ' - elseif unicode:len() > 5 then - target = string.sub(line, col + dir + 1 + (dir > 0 and 2 or 0), col + dir + 1 + (dir > 0 and 2 or 0)) - suffix = string.sub(line, col + (dir > 0 and 5 or 4)) - elseif unicode:len() > 2 then - target = string.sub(line, col + dir + 1 + (dir > 0 and 1 or 0), col + dir + 1 + (dir > 0 and 1 or 0)) - suffix = string.sub(line, col + (dir > 0 and 4 or 3)) else - target = string.sub(line, col + dir + 1, col + dir + 1) suffix = string.sub(line, col + (dir > 0 and 3 or 2)) end + if isUnicode(sUnicode) then + suffix = suffixUnicode(tUnicode, line, col, dir) + end + + if isTilde(sUnicode) then + suffix = suffixTilde(tUnicode, line, col, dir) + end + + if not isTilde(tUnicode) then + -- Default + target = string.sub(line, col + dir + 1, col + dir + 1) + + if isUnicode(sUnicode) then + target = string.sub(line, col + dir + 1 + (dir > 0 and 2 or 0), col + dir + 1 + (dir > 0 and 2 or 0)) + elseif isTilde(sUnicode) then + target = string.sub(line, col + dir + 1 + (dir > 0 and 1 or 0), col + dir + 1 + (dir > 0 and 1 or 0)) + end + else + target = getUnicodeOrTilde() + prefix = string.sub(line, 1, col) + end + + -- Return cursor position to original + vim.api.nvim_win_set_cursor(0, { sRow, col }) + + print('target: '..target, 'prefix: '..prefix, 'suffix: '..suffix) + -- Remove trailing spaces before putting into the table line_res = prefix..(dir > 0 and target..selected or selected..target)..suffix line_res = line_res:gsub('%s+$', '') diff --git a/lua/utils/init.lua b/lua/utils/init.lua index 2405b93..2bf7286 100644 --- a/lua/utils/init.lua +++ b/lua/utils/init.lua @@ -116,4 +116,48 @@ M.indent = function(amount, sLine, eLine) end + +local isTilde = function(char) + return char:len() > 2 +end + +local isUnicode = function(char) + return char:len() > 5 +end + +local getUnicodeOrTilde = function() + vim.cmd(':normal! x') + return vim.fn.getreg('"0') +end + +local suffixUnicode = function(tUnicode, line, col, dir) + local suffix = '' + + if isUnicode(tUnicode) then + suffix = string.sub(line, col + (dir > 0 and 7 or 4)) + else + suffix = string.sub(line, col + (dir > 0 and 5 or 4)) + end + + return suffix +end + +local targetUnicode = function() +end + +local suffixTilde = function(tUnicode, line, col, dir) + local suffix = '' + + if isTilde(tUnicode) then + suffix = string.sub(line, col + (dir > 0 and 5 or 3)) + else + suffix = string.sub(line, col + (dir > 0 and 4 or 3)) + end + + return suffix +end + +local targetTilde = function() +end + return M From 608cf1dda88f008e7911fde860672441694bea1a Mon Sep 17 00:00:00 2001 From: fedepujol <9yjbd325@anonaddy.me> Date: Sun, 27 Feb 2022 20:24:54 -0300 Subject: [PATCH 03/12] Update functions to handle unicode and tilde --- lua/core/horiz.lua | 93 ++++++++++++++++++++++++++++------------------ lua/utils/init.lua | 55 ++++++++++++++++----------- 2 files changed, 91 insertions(+), 57 deletions(-) diff --git a/lua/core/horiz.lua b/lua/core/horiz.lua index 6ac2f5b..f9b8a88 100644 --- a/lua/core/horiz.lua +++ b/lua/core/horiz.lua @@ -1,3 +1,5 @@ +local utils = require('utils') + local M = {} -- Moves the character under the cursor to the left or right @@ -26,57 +28,76 @@ M.horzChar = function(dir) -- Default prefix = string.sub(line, 1, col + (dir > 0 and 0 or dir)) - -- Unicode or tilde character - sUnicode = vim.api.nvim_exec(':normal! g8', true) - sUnicode = string.gsub(sUnicode, '%s+$', '') - - if isTilde(sUnicode) then - selected = getUnicodeOrTilde() - else - selected = string.sub(line, col + 1, col + 1) - end + -- Unicode or tilde character + sUnicode = utils.curUnicodeOrTilde() + selected = utils.getChar() -- Check if target is unicode or tilde - if isTilde(sUnicode) and dir < 0 then - vim.api.nvim_win_set_cursor(0, { sRow, col + dir }) - end - tUnicode = vim.api.nvim_exec(':normal! g8', true) - tUnicode = string.gsub(tUnicode, '%s+$', '') + -- move cursor to get the character + if dir < 0 then + vim.api.nvim_win_set_cursor(0, { sRow, col - 3 }) - -- Put a space if the character reaches the end of the line - -- Default - if col == line:len() - 1 and dir > 0 then - target = ' ' + tUnicode = utils.curUnicodeOrTilde() + if not utils.isUnicode(tUnicode) then + vim.api.nvim_win_set_cursor(0, { sRow, col - 2 }) + end + + tUnicode = utils.curUnicodeOrTilde() + if not utils.isTilde(tUnicode) then + vim.api.nvim_win_set_cursor(0, { sRow, col - 1 }) + end else - suffix = string.sub(line, col + (dir > 0 and 3 or 2)) + tUnicode = utils.curUnicodeOrTilde() end - if isUnicode(sUnicode) then - suffix = suffixUnicode(tUnicode, line, col, dir) - end + -- Put a space if the character reaches the end of the line + -- Default + target = utils.getChar() + suffix = string.sub(line, col + (dir > 0 and 3 or 2)) - if isTilde(sUnicode) then - suffix = suffixTilde(tUnicode, line, col, dir) + -- Character under cursor is unicode or tilde + if utils.isTilde(sUnicode) or utils.isUnicode(sUnicode) then + if utils.isUnicode(sUnicode) then + suffix = utils.suffixUnicode(tUnicode, sUnicode, line, col, dir) + else + suffix = utils.suffixTilde(line, col, dir) + end + else + if utils.isTilde(tUnicode) or utils.isUnicode(tUnicode) then + if utils.isUnicode(tUnicode) then + suffix = utils.suffixUnicode(tUnicode, sUnicode, line, col, dir) + else + suffix = utils.suffixTilde(line, col, dir) + end + end end - if not isTilde(tUnicode) then - -- Default - target = string.sub(line, col + dir + 1, col + dir + 1) - - if isUnicode(sUnicode) then - target = string.sub(line, col + dir + 1 + (dir > 0 and 2 or 0), col + dir + 1 + (dir > 0 and 2 or 0)) - elseif isTilde(sUnicode) then - target = string.sub(line, col + dir + 1 + (dir > 0 and 1 or 0), col + dir + 1 + (dir > 0 and 1 or 0)) + if utils.isTilde(tUnicode) or utils.isUnicode(tUnicode) then + if utils.isUnicode(tUnicode) then + prefix = string.sub(line, 1, col + (dir < 0 and -3 or 0)) + else + prefix = string.sub(line, 1, col + (dir < 0 and -2 or 0)) end - else - target = getUnicodeOrTilde() - prefix = string.sub(line, 1, col) end -- Return cursor position to original vim.api.nvim_win_set_cursor(0, { sRow, col }) - print('target: '..target, 'prefix: '..prefix, 'suffix: '..suffix) + if dir > 0 then + if utils.isUnicode(sUnicode) then + if col == line:len() - 3 then + target = ' ' + end + elseif utils.isTilde(sUnicode) then + if col == line:len() - 2 then + target = ' ' + end + else + if col == line:len() - 1 then + target = ' ' + end + end + end -- Remove trailing spaces before putting into the table line_res = prefix..(dir > 0 and target..selected or selected..target)..suffix diff --git a/lua/utils/init.lua b/lua/utils/init.lua index 2bf7286..dbdb21b 100644 --- a/lua/utils/init.lua +++ b/lua/utils/init.lua @@ -116,48 +116,61 @@ M.indent = function(amount, sLine, eLine) end - -local isTilde = function(char) +M.isTilde = function(char) return char:len() > 2 end -local isUnicode = function(char) +M.isUnicode = function(char) return char:len() > 5 end -local getUnicodeOrTilde = function() +M.getChar = function() vim.cmd(':normal! x') return vim.fn.getreg('"0') end -local suffixUnicode = function(tUnicode, line, col, dir) - local suffix = '' +M.curUnicodeOrTilde = function() + local uni = '' - if isUnicode(tUnicode) then - suffix = string.sub(line, col + (dir > 0 and 7 or 4)) - else - suffix = string.sub(line, col + (dir > 0 and 5 or 4)) - end - - return suffix -end + uni = vim.api.nvim_exec(':normal! g8', true) + uni = string.gsub(uni, '%s+$', '') -local targetUnicode = function() + return uni end -local suffixTilde = function(tUnicode, line, col, dir) +M.suffixUnicode = function(tUnicode, sUnicode, line, col, dir) local suffix = '' - - if isTilde(tUnicode) then - suffix = string.sub(line, col + (dir > 0 and 5 or 3)) + local offset = 0 + + if dir > 0 then + if M.isUnicode(tUnicode) then + if M.isUnicode(sUnicode) then + offset = 7 + else + offset = 5 + end + else + offset = 5 + end else - suffix = string.sub(line, col + (dir > 0 and 4 or 3)) + if M.isUnicode(tUnicode) then + if M.isUnicode(sUnicode) then + offset = 4 + else + offset = 2 + end + else + offset = 4 + end end + suffix = string.sub(line, col + offset) + return suffix end -local targetTilde = function() +M.suffixTilde = function(line, col, dir) + return string.sub(line, col + (dir > 0 and 4 or 3)) end return M From 1b57e6f9d7622f8cea1f415a865325c65e732b46 Mon Sep 17 00:00:00 2001 From: fedepujol <9yjbd325@anonaddy.me> Date: Tue, 1 Mar 2022 23:54:33 -0300 Subject: [PATCH 04/12] Correction on movin tilde and unicode characters --- lua/core/horiz.lua | 19 ++++++++++++++++--- lua/utils/init.lua | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/lua/core/horiz.lua b/lua/core/horiz.lua index f9b8a88..7f4e103 100644 --- a/lua/core/horiz.lua +++ b/lua/core/horiz.lua @@ -60,14 +60,15 @@ M.horzChar = function(dir) if utils.isUnicode(sUnicode) then suffix = utils.suffixUnicode(tUnicode, sUnicode, line, col, dir) else - suffix = utils.suffixTilde(line, col, dir) + suffix = utils.suffixTilde(tUnicode, sUnicode, line, col, dir) end else + -- Target character is tilde or unicode if utils.isTilde(tUnicode) or utils.isUnicode(tUnicode) then if utils.isUnicode(tUnicode) then suffix = utils.suffixUnicode(tUnicode, sUnicode, line, col, dir) else - suffix = utils.suffixTilde(line, col, dir) + suffix = utils.suffixTilde(tUnicode, sUnicode, line, col, dir) end end end @@ -99,6 +100,18 @@ M.horzChar = function(dir) end end + print('prefix:'..prefix, 'suffix:'..suffix, 'target:'..target) + + local offset = 0 + if utils.isUnicode(tUnicode) then + offset = 3 + (utils.isUnicode(sUnicode) and dir < 0 and -2 or 0) + elseif utils.isTilde(tUnicode) then + offset = 2 + (utils.isTilde(sUnicode) and dir < 0 and -1 or 0) + else + offset = 1 + end + offset = offset * dir + -- Remove trailing spaces before putting into the table line_res = prefix..(dir > 0 and target..selected or selected..target)..suffix line_res = line_res:gsub('%s+$', '') @@ -107,7 +120,7 @@ M.horzChar = function(dir) -- Update the line with the new one and update cursor position vim.api.nvim_buf_set_lines(0, sRow - 1, sRow, true, result) - vim.api.nvim_win_set_cursor(0, { sRow, col + dir }) + vim.api.nvim_win_set_cursor(0, { sRow, col + offset }) end -- Moves the visual area left or right diff --git a/lua/utils/init.lua b/lua/utils/init.lua index dbdb21b..873d766 100644 --- a/lua/utils/init.lua +++ b/lua/utils/init.lua @@ -149,6 +149,10 @@ M.suffixUnicode = function(tUnicode, sUnicode, line, col, dir) else offset = 5 end + elseif M.isTilde(tUnicode) then + if M.isUnicode(sUnicode) then + offset = 6 + end else offset = 5 end @@ -169,8 +173,37 @@ M.suffixUnicode = function(tUnicode, sUnicode, line, col, dir) return suffix end -M.suffixTilde = function(line, col, dir) - return string.sub(line, col + (dir > 0 and 4 or 3)) +M.suffixTilde = function(tUnicode, sUnicode, line, col, dir) + local suffix = '' + local offset = 0 + + if dir > 0 then + if M.isTilde(sUnicode) then + if M.isUnicode(tUnicode) then + offset = 6 + elseif M.isTilde(tUnicode) then + offset = 5 + else + offset = 4 + end + else + if M.isTilde(tUnicode) then + offset = 4 + end + end + else + if M.isTilde(sUnicode) then + offset = 3 + else + if M.isTilde(tUnicode) then + offset = 2 + end + end + end + + suffix = string.sub(line, col + offset) + + return suffix end return M From d590dbb4d75825a4e346282ce0372f56a320de5d Mon Sep 17 00:00:00 2001 From: fedepujol <9yjbd325@anonaddy.me> Date: Wed, 9 Mar 2022 09:13:46 -0300 Subject: [PATCH 05/12] Clean up and rename variables --- lua/core/horiz.lua | 64 +++++++++++++++------------------------------- lua/utils/init.lua | 57 +++++++++++++++++++++++++++++------------ 2 files changed, 61 insertions(+), 60 deletions(-) diff --git a/lua/core/horiz.lua b/lua/core/horiz.lua index 7f4e103..a834beb 100644 --- a/lua/core/horiz.lua +++ b/lua/core/horiz.lua @@ -17,8 +17,8 @@ M.horzChar = function(dir) local line_res = '' local selected = '' - local sUnicode = '' - local tUnicode = '' + local sChar = '' + local tChar = '' -- Checks line limits with the direction if dir < 0 and col < 1 then @@ -29,7 +29,7 @@ M.horzChar = function(dir) prefix = string.sub(line, 1, col + (dir > 0 and 0 or dir)) -- Unicode or tilde character - sUnicode = utils.curUnicodeOrTilde() + sChar = utils.curUnicodeOrTilde() selected = utils.getChar() -- Check if target is unicode or tilde @@ -37,17 +37,17 @@ M.horzChar = function(dir) if dir < 0 then vim.api.nvim_win_set_cursor(0, { sRow, col - 3 }) - tUnicode = utils.curUnicodeOrTilde() - if not utils.isUnicode(tUnicode) then + tChar = utils.curUnicodeOrTilde() + if not utils.isUnicode(tChar) then vim.api.nvim_win_set_cursor(0, { sRow, col - 2 }) end - tUnicode = utils.curUnicodeOrTilde() - if not utils.isTilde(tUnicode) then + tChar = utils.curUnicodeOrTilde() + if not utils.isTilde(tChar) then vim.api.nvim_win_set_cursor(0, { sRow, col - 1 }) end else - tUnicode = utils.curUnicodeOrTilde() + tChar = utils.curUnicodeOrTilde() end -- Put a space if the character reaches the end of the line @@ -56,25 +56,25 @@ M.horzChar = function(dir) suffix = string.sub(line, col + (dir > 0 and 3 or 2)) -- Character under cursor is unicode or tilde - if utils.isTilde(sUnicode) or utils.isUnicode(sUnicode) then - if utils.isUnicode(sUnicode) then - suffix = utils.suffixUnicode(tUnicode, sUnicode, line, col, dir) + if utils.isTilde(sChar) or utils.isUnicode(sChar) then + if utils.isUnicode(sChar) then + suffix = utils.suffixUnicode(tChar, sChar, line, col, dir) else - suffix = utils.suffixTilde(tUnicode, sUnicode, line, col, dir) + suffix = utils.suffixTilde(tChar, sChar, line, col, dir) end else -- Target character is tilde or unicode - if utils.isTilde(tUnicode) or utils.isUnicode(tUnicode) then - if utils.isUnicode(tUnicode) then - suffix = utils.suffixUnicode(tUnicode, sUnicode, line, col, dir) + if utils.isTilde(tChar) or utils.isUnicode(tChar) then + if utils.isUnicode(tChar) then + suffix = utils.suffixUnicode(tChar, sChar, line, col, dir) else - suffix = utils.suffixTilde(tUnicode, sUnicode, line, col, dir) + suffix = utils.suffixTilde(tChar, sChar, line, col, dir) end end end - if utils.isTilde(tUnicode) or utils.isUnicode(tUnicode) then - if utils.isUnicode(tUnicode) then + if utils.isTilde(tChar) or utils.isUnicode(tChar) then + if utils.isUnicode(tChar) then prefix = string.sub(line, 1, col + (dir < 0 and -3 or 0)) else prefix = string.sub(line, 1, col + (dir < 0 and -2 or 0)) @@ -85,33 +85,11 @@ M.horzChar = function(dir) vim.api.nvim_win_set_cursor(0, { sRow, col }) if dir > 0 then - if utils.isUnicode(sUnicode) then - if col == line:len() - 3 then - target = ' ' - end - elseif utils.isTilde(sUnicode) then - if col == line:len() - 2 then - target = ' ' - end - else - if col == line:len() - 1 then - target = ' ' - end + if col == line:len() - utils.calc_eolOffset(sChar) then + target = ' ' end end - print('prefix:'..prefix, 'suffix:'..suffix, 'target:'..target) - - local offset = 0 - if utils.isUnicode(tUnicode) then - offset = 3 + (utils.isUnicode(sUnicode) and dir < 0 and -2 or 0) - elseif utils.isTilde(tUnicode) then - offset = 2 + (utils.isTilde(sUnicode) and dir < 0 and -1 or 0) - else - offset = 1 - end - offset = offset * dir - -- Remove trailing spaces before putting into the table line_res = prefix..(dir > 0 and target..selected or selected..target)..suffix line_res = line_res:gsub('%s+$', '') @@ -120,7 +98,7 @@ M.horzChar = function(dir) -- Update the line with the new one and update cursor position vim.api.nvim_buf_set_lines(0, sRow - 1, sRow, true, result) - vim.api.nvim_win_set_cursor(0, { sRow, col + offset }) + vim.api.nvim_win_set_cursor(0, { sRow, col + utils.cursor_offset(tChar, sChar, dir)}) end -- Moves the visual area left or right diff --git a/lua/utils/init.lua b/lua/utils/init.lua index 873d766..40c99a0 100644 --- a/lua/utils/init.lua +++ b/lua/utils/init.lua @@ -113,7 +113,32 @@ M.indent = function(amount, sLine, eLine) elseif diff > 0 then vim.cmd('silent! '..cRow..','..eRow..string.rep('>', diff)) end +end + +M.calc_eolOffset = function(char) + local eolOffset = 1 + + if M.isUnicode(char) then + eolOffset = 3 + elseif M.isTilde(char) then + eolOffset = 2 + end + + return eolOffset +end + +M.cursor_offset = function(tChar, sChar, dir) + local offset = 0 + + if M.isUnicode(tChar) then + offset = 3 + (M.isUnicode(sChar) and dir < 0 and -2 or 0) + elseif M.isTilde(tChar) then + offset = 2 + (M.isTilde(sChar) and dir < 0 and -1 or 0) + else + offset = 1 + end + return offset * dir end M.isTilde = function(char) @@ -138,27 +163,27 @@ M.curUnicodeOrTilde = function() return uni end -M.suffixUnicode = function(tUnicode, sUnicode, line, col, dir) +M.suffixUnicode = function(tChar, sChar, line, col, dir) local suffix = '' local offset = 0 if dir > 0 then - if M.isUnicode(tUnicode) then - if M.isUnicode(sUnicode) then + if M.isUnicode(tChar) then + if M.isUnicode(sChar) then offset = 7 else offset = 5 end - elseif M.isTilde(tUnicode) then - if M.isUnicode(sUnicode) then + elseif M.isTilde(tChar) then + if M.isUnicode(sChar) then offset = 6 end else offset = 5 end else - if M.isUnicode(tUnicode) then - if M.isUnicode(sUnicode) then + if M.isUnicode(tChar) then + if M.isUnicode(sChar) then offset = 4 else offset = 2 @@ -173,31 +198,29 @@ M.suffixUnicode = function(tUnicode, sUnicode, line, col, dir) return suffix end -M.suffixTilde = function(tUnicode, sUnicode, line, col, dir) +M.suffixTilde = function(tChar, sChar, line, col, dir) local suffix = '' local offset = 0 if dir > 0 then - if M.isTilde(sUnicode) then - if M.isUnicode(tUnicode) then + if M.isTilde(sChar) then + if M.isUnicode(tChar) then offset = 6 - elseif M.isTilde(tUnicode) then + elseif M.isTilde(tChar) then offset = 5 else offset = 4 end else - if M.isTilde(tUnicode) then + if M.isTilde(tChar) then offset = 4 end end else - if M.isTilde(sUnicode) then + if M.isTilde(sChar) then offset = 3 - else - if M.isTilde(tUnicode) then - offset = 2 - end + elseif M.isTilde(tChar) then + offset = 2 end end From f9e74c436e284d8da2e1d4ffc3f15d16dfbf9da2 Mon Sep 17 00:00:00 2001 From: fedepujol <9yjbd325@anonaddy.me> Date: Sun, 27 Mar 2022 17:35:13 -0300 Subject: [PATCH 06/12] Create for visual areas --- lua/utils/init.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lua/utils/init.lua b/lua/utils/init.lua index 40c99a0..9d1f434 100644 --- a/lua/utils/init.lua +++ b/lua/utils/init.lua @@ -154,6 +154,12 @@ M.getChar = function() return vim.fn.getreg('"0') end +M.getVisualChar = function(sCol, eCol) + vim.cmd(':normal! v'..(eCol - sCol)..'l') + vim.cmd(':normal! x') + return vim.fn.getreg('"0') +end + M.curUnicodeOrTilde = function() local uni = '' From c705265ef009d72c37e7abcb26c417ce1ca67e4e Mon Sep 17 00:00:00 2001 From: fedepujol <9yjbd325@anonaddy.me> Date: Sun, 27 Mar 2022 17:35:43 -0300 Subject: [PATCH 07/12] First test with visual area --- lua/core/horiz.lua | 114 ++++++++++++++++++++++++++++++++------------- 1 file changed, 81 insertions(+), 33 deletions(-) diff --git a/lua/core/horiz.lua b/lua/core/horiz.lua index a834beb..5025434 100644 --- a/lua/core/horiz.lua +++ b/lua/core/horiz.lua @@ -35,20 +35,9 @@ M.horzChar = function(dir) -- Check if target is unicode or tilde -- move cursor to get the character if dir < 0 then - vim.api.nvim_win_set_cursor(0, { sRow, col - 3 }) - - tChar = utils.curUnicodeOrTilde() - if not utils.isUnicode(tChar) then - vim.api.nvim_win_set_cursor(0, { sRow, col - 2 }) - end - - tChar = utils.curUnicodeOrTilde() - if not utils.isTilde(tChar) then - vim.api.nvim_win_set_cursor(0, { sRow, col - 1 }) - end - else - tChar = utils.curUnicodeOrTilde() + vim.cmd(':normal! h') end + tChar = utils.curUnicodeOrTilde() -- Put a space if the character reaches the end of the line -- Default @@ -114,40 +103,99 @@ M.horzBlock = function(dir) local eRow = vim.fn.line("'>") local lines = vim.api.nvim_buf_get_lines(0, sRow - 1, eRow, true) - local line = '' + local line_res = '' local selected = '' local prefix = '' local suffix = '' local results = {} -- Iterates over the lines of the visual area - for _, v in ipairs(lines) do + for _, line in ipairs(lines) do local target = '' + local tChar = '' + local sChar = '' + + -- if dir > 0 then + -- if eCol == v:len() then + -- target = ' ' + -- else + -- target = string.sub(v, eCol + 1 , eCol + 1) + -- end + + -- selected = string.sub(v, sCol, eCol) + -- prefix = string.sub(v, 1, sCol - 1) + -- suffix = string.sub(v, eCol + 2) + -- else + -- if col == 0 then + -- return + -- end + + -- target = string.sub(v, sCol - 1, sCol - 1) + -- selected = string.sub(v, sCol, eCol) + -- prefix = string.sub(v, 1, sCol - 2) + -- suffix = string.sub(v, eCol + 1) + -- end + -- Remove trailing spaces from the lines before + -- inserting them into the results table + -- line = prefix..(dir > 0 and target..selected or selected..target)..suffix + -- line = line:gsub('%s+$', '') + -- Default + prefix = string.sub(line, 1, col + (dir > 0 and 0 or dir)) + + -- Unicode or tilde character + sChar = utils.curUnicodeOrTilde() + selected = utils.getVisualChar(sCol, eCol) + + -- Check if target is unicode or tilde + -- move cursor to get the character + if dir < 0 then + vim.cmd(':normal! h') + end + tChar = utils.curUnicodeOrTilde() - if dir > 0 then - if eCol == v:len() then - target = ' ' + -- Put a space if the character reaches the end of the line + -- Default + target = utils.getChar() + suffix = string.sub(line, col + (dir > 0 and 3 or 2)) + + -- Character under cursor is unicode or tilde + if utils.isTilde(sChar) or utils.isUnicode(sChar) then + if utils.isUnicode(sChar) then + suffix = utils.suffixUnicode(tChar, sChar, line, col, dir) else - target = string.sub(v, eCol + 1 , eCol + 1) + suffix = utils.suffixTilde(tChar, sChar, line, col, dir) end - - selected = string.sub(v, sCol, eCol) - prefix = string.sub(v, 1, sCol - 1) - suffix = string.sub(v, eCol + 2) else - if col == 0 then - return + -- Target character is tilde or unicode + if utils.isTilde(tChar) or utils.isUnicode(tChar) then + if utils.isUnicode(tChar) then + suffix = utils.suffixUnicode(tChar, sChar, line, col, dir) + else + suffix = utils.suffixTilde(tChar, sChar, line, col, dir) + end end + end - target = string.sub(v, sCol - 1, sCol - 1) - selected = string.sub(v, sCol, eCol) - prefix = string.sub(v, 1, sCol - 2) - suffix = string.sub(v, eCol + 1) + if utils.isTilde(tChar) or utils.isUnicode(tChar) then + if utils.isUnicode(tChar) then + prefix = string.sub(line, 1, col + (dir < 0 and -3 or 0)) + else + prefix = string.sub(line, 1, col + (dir < 0 and -2 or 0)) + end end - -- Remove trailing spaces from the lines before - -- inserting them into the results table - line = prefix..(dir > 0 and target..selected or selected..target)..suffix - line = line:gsub('%s+$', '') + + -- Return cursor position to original + vim.api.nvim_win_set_cursor(0, { sRow, col }) + + if dir > 0 then + if col == line:len() - utils.calc_eolOffset(sChar) then + target = ' ' + end + end + + -- Remove trailing spaces before putting into the table + line_res = prefix..(dir > 0 and target..selected or selected..target)..suffix + line_res = line_res:gsub('%s+$', '') table.insert(results, line) end From a021bce057c5be1a78a90ca746f3160547240308 Mon Sep 17 00:00:00 2001 From: fedepujol <9yjbd325@anonaddy.me> Date: Sun, 3 Apr 2022 12:44:22 -0300 Subject: [PATCH 08/12] Roll-back breacking change for horizontal block movement --- lua/core/horiz.lua | 95 ++++++++++------------------------------------ 1 file changed, 19 insertions(+), 76 deletions(-) diff --git a/lua/core/horiz.lua b/lua/core/horiz.lua index 5025434..5f7dd6a 100644 --- a/lua/core/horiz.lua +++ b/lua/core/horiz.lua @@ -112,92 +112,34 @@ M.horzBlock = function(dir) -- Iterates over the lines of the visual area for _, line in ipairs(lines) do local target = '' - local tChar = '' - local sChar = '' - - -- if dir > 0 then - -- if eCol == v:len() then - -- target = ' ' - -- else - -- target = string.sub(v, eCol + 1 , eCol + 1) - -- end - - -- selected = string.sub(v, sCol, eCol) - -- prefix = string.sub(v, 1, sCol - 1) - -- suffix = string.sub(v, eCol + 2) - -- else - -- if col == 0 then - -- return - -- end - - -- target = string.sub(v, sCol - 1, sCol - 1) - -- selected = string.sub(v, sCol, eCol) - -- prefix = string.sub(v, 1, sCol - 2) - -- suffix = string.sub(v, eCol + 1) - -- end - -- Remove trailing spaces from the lines before - -- inserting them into the results table - -- line = prefix..(dir > 0 and target..selected or selected..target)..suffix - -- line = line:gsub('%s+$', '') - -- Default - prefix = string.sub(line, 1, col + (dir > 0 and 0 or dir)) - - -- Unicode or tilde character - sChar = utils.curUnicodeOrTilde() - selected = utils.getVisualChar(sCol, eCol) - - -- Check if target is unicode or tilde - -- move cursor to get the character - if dir < 0 then - vim.cmd(':normal! h') - end - tChar = utils.curUnicodeOrTilde() - -- Put a space if the character reaches the end of the line - -- Default - target = utils.getChar() - suffix = string.sub(line, col + (dir > 0 and 3 or 2)) - - -- Character under cursor is unicode or tilde - if utils.isTilde(sChar) or utils.isUnicode(sChar) then - if utils.isUnicode(sChar) then - suffix = utils.suffixUnicode(tChar, sChar, line, col, dir) + if dir > 0 then + if eCol == line:len() then + target = ' ' else - suffix = utils.suffixTilde(tChar, sChar, line, col, dir) - end - else - -- Target character is tilde or unicode - if utils.isTilde(tChar) or utils.isUnicode(tChar) then - if utils.isUnicode(tChar) then - suffix = utils.suffixUnicode(tChar, sChar, line, col, dir) - else - suffix = utils.suffixTilde(tChar, sChar, line, col, dir) - end + target = string.sub(line, eCol + 1 , eCol + 1) end - end - if utils.isTilde(tChar) or utils.isUnicode(tChar) then - if utils.isUnicode(tChar) then - prefix = string.sub(line, 1, col + (dir < 0 and -3 or 0)) - else - prefix = string.sub(line, 1, col + (dir < 0 and -2 or 0)) + selected = string.sub(line, sCol, eCol) + prefix = string.sub(line, 1, sCol - 1) + suffix = string.sub(line, eCol + 2) + else + if col == 0 then + return end - end - - -- Return cursor position to original - vim.api.nvim_win_set_cursor(0, { sRow, col }) - if dir > 0 then - if col == line:len() - utils.calc_eolOffset(sChar) then - target = ' ' - end + target = string.sub(line, sCol - 1, sCol - 1) + selected = string.sub(line, sCol, eCol) + prefix = string.sub(line, 1, sCol - 2) + suffix = string.sub(line, eCol + 1) end - -- Remove trailing spaces before putting into the table + -- Remove trailing spaces from the lines before + -- inserting them into the results table line_res = prefix..(dir > 0 and target..selected or selected..target)..suffix - line_res = line_res:gsub('%s+$', '') + line_res = line:gsub('%s+$', '') - table.insert(results, line) + table.insert(results, line_res) end vim.api.nvim_buf_set_lines(0, sRow - 1, eRow, true, results) @@ -205,6 +147,7 @@ M.horzBlock = function(dir) -- Update the visual area with the new position of the characters vim.cmd('execute "normal! \\e\\e"') + local cmd_suffix = (eCol - sCol > 0 and (eCol - sCol)..'l' or '') cmd_suffix = cmd_suffix..(eRow - sRow > 0 and (eRow - sRow)..'j' or '') vim.cmd('execute "normal! \\'..cmd_suffix..'"') From 3aaf9b568956566671467b07ed63a45983133258 Mon Sep 17 00:00:00 2001 From: fedepujol <9yjbd325@anonaddy.me> Date: Mon, 4 Apr 2022 17:08:10 -0300 Subject: [PATCH 09/12] Change namespace according to main --- lua/{ => move}/core/horiz.lua | 43 ++++++++++++++++----------------- lua/{ => move}/core/vert.lua | 2 +- lua/{move.lua => move/init.lua} | 4 +-- lua/{ => move}/utils/init.lua | 0 4 files changed, 24 insertions(+), 25 deletions(-) rename lua/{ => move}/core/horiz.lua (78%) rename lua/{ => move}/core/vert.lua (98%) rename lua/{move.lua => move/init.lua} (61%) rename lua/{ => move}/utils/init.lua (100%) diff --git a/lua/core/horiz.lua b/lua/move/core/horiz.lua similarity index 78% rename from lua/core/horiz.lua rename to lua/move/core/horiz.lua index 5f7dd6a..b190c78 100644 --- a/lua/core/horiz.lua +++ b/lua/move/core/horiz.lua @@ -1,4 +1,4 @@ -local utils = require('utils') +local utils = require('move.utils') local M = {} @@ -80,16 +80,17 @@ M.horzChar = function(dir) end -- Remove trailing spaces before putting into the table - line_res = prefix..(dir > 0 and target..selected or selected..target)..suffix + line_res = prefix .. (dir > 0 and target .. selected or selected .. target) .. suffix line_res = line_res:gsub('%s+$', '') table.insert(result, line_res) -- Update the line with the new one and update cursor position vim.api.nvim_buf_set_lines(0, sRow - 1, sRow, true, result) - vim.api.nvim_win_set_cursor(0, { sRow, col + utils.cursor_offset(tChar, sChar, dir)}) + vim.api.nvim_win_set_cursor(0, { sRow, col + utils.cursor_offset(tChar, sChar, dir) }) end + -- Moves the visual area left or right -- and keeps it selected M.horzBlock = function(dir) @@ -103,43 +104,42 @@ M.horzBlock = function(dir) local eRow = vim.fn.line("'>") local lines = vim.api.nvim_buf_get_lines(0, sRow - 1, eRow, true) - local line_res = '' + local line = '' local selected = '' local prefix = '' local suffix = '' local results = {} -- Iterates over the lines of the visual area - for _, line in ipairs(lines) do + for _, v in ipairs(lines) do local target = '' if dir > 0 then - if eCol == line:len() then + if eCol == v:len() then target = ' ' else - target = string.sub(line, eCol + 1 , eCol + 1) + target = string.sub(v, eCol + 1, eCol + 1) end - selected = string.sub(line, sCol, eCol) - prefix = string.sub(line, 1, sCol - 1) - suffix = string.sub(line, eCol + 2) + selected = string.sub(v, sCol, eCol) + prefix = string.sub(v, 1, sCol - 1) + suffix = string.sub(v, eCol + 2) else if col == 0 then return end - target = string.sub(line, sCol - 1, sCol - 1) - selected = string.sub(line, sCol, eCol) - prefix = string.sub(line, 1, sCol - 2) - suffix = string.sub(line, eCol + 1) + target = string.sub(v, sCol - 1, sCol - 1) + selected = string.sub(v, sCol, eCol) + prefix = string.sub(v, 1, sCol - 2) + suffix = string.sub(v, eCol + 1) end - -- Remove trailing spaces from the lines before -- inserting them into the results table - line_res = prefix..(dir > 0 and target..selected or selected..target)..suffix - line_res = line:gsub('%s+$', '') + line = prefix .. (dir > 0 and target .. selected or selected .. target) .. suffix + line = line:gsub('%s+$', '') - table.insert(results, line_res) + table.insert(results, line) end vim.api.nvim_buf_set_lines(0, sRow - 1, eRow, true, results) @@ -147,10 +147,9 @@ M.horzBlock = function(dir) -- Update the visual area with the new position of the characters vim.cmd('execute "normal! \\e\\e"') - - local cmd_suffix = (eCol - sCol > 0 and (eCol - sCol)..'l' or '') - cmd_suffix = cmd_suffix..(eRow - sRow > 0 and (eRow - sRow)..'j' or '') - vim.cmd('execute "normal! \\'..cmd_suffix..'"') + local cmd_suffix = (eCol - sCol > 0 and (eCol - sCol) .. 'l' or '') + cmd_suffix = cmd_suffix .. (eRow - sRow > 0 and (eRow - sRow) .. 'j' or '') + vim.cmd('execute "normal! \\' .. cmd_suffix .. '"') end return M diff --git a/lua/core/vert.lua b/lua/move/core/vert.lua similarity index 98% rename from lua/core/vert.lua rename to lua/move/core/vert.lua index beb578b..546d6ee 100644 --- a/lua/core/vert.lua +++ b/lua/move/core/vert.lua @@ -1,4 +1,4 @@ -local utils = require('utils') +local utils = require('move.utils') local M = {} diff --git a/lua/move.lua b/lua/move/init.lua similarity index 61% rename from lua/move.lua rename to lua/move/init.lua index dee6b75..41d3a79 100644 --- a/lua/move.lua +++ b/lua/move/init.lua @@ -1,5 +1,5 @@ -local move_vert = require('core.vert') -local move_hor = require('core.horiz') +local move_hor = require('move.core.horiz') +local move_vert = require('move.core.vert') return { MoveLine = move_vert.moveLine, diff --git a/lua/utils/init.lua b/lua/move/utils/init.lua similarity index 100% rename from lua/utils/init.lua rename to lua/move/utils/init.lua From 6a84f1f047ccf7a7fdd37736cb356cc51b2c5dd2 Mon Sep 17 00:00:00 2001 From: fedepujol <9yjbd325@anonaddy.me> Date: Mon, 4 Apr 2022 18:05:31 -0300 Subject: [PATCH 10/12] Change variables names --- lua/move/core/horiz.lua | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/lua/move/core/horiz.lua b/lua/move/core/horiz.lua index b190c78..76fcb98 100644 --- a/lua/move/core/horiz.lua +++ b/lua/move/core/horiz.lua @@ -104,42 +104,42 @@ M.horzBlock = function(dir) local eRow = vim.fn.line("'>") local lines = vim.api.nvim_buf_get_lines(0, sRow - 1, eRow, true) - local line = '' + local new_line = '' local selected = '' local prefix = '' local suffix = '' local results = {} -- Iterates over the lines of the visual area - for _, v in ipairs(lines) do + for _, line in ipairs(lines) do local target = '' if dir > 0 then - if eCol == v:len() then + if eCol == line:len() then target = ' ' else - target = string.sub(v, eCol + 1, eCol + 1) + target = string.sub(line, eCol + 1, eCol + 1) end - selected = string.sub(v, sCol, eCol) - prefix = string.sub(v, 1, sCol - 1) - suffix = string.sub(v, eCol + 2) + selected = string.sub(line, sCol, eCol) + prefix = string.sub(line, 1, sCol - 1) + suffix = string.sub(line, eCol + 2) else if col == 0 then return end - target = string.sub(v, sCol - 1, sCol - 1) - selected = string.sub(v, sCol, eCol) - prefix = string.sub(v, 1, sCol - 2) - suffix = string.sub(v, eCol + 1) + target = string.sub(line, sCol - 1, sCol - 1) + selected = string.sub(line, sCol, eCol) + prefix = string.sub(line, 1, sCol - 2) + suffix = string.sub(line, eCol + 1) end -- Remove trailing spaces from the lines before -- inserting them into the results table - line = prefix .. (dir > 0 and target .. selected or selected .. target) .. suffix - line = line:gsub('%s+$', '') + new_line = prefix .. (dir > 0 and target .. selected or selected .. target) .. suffix + new_line = new_line:gsub('%s+$', '') - table.insert(results, line) + table.insert(results, new_line) end vim.api.nvim_buf_set_lines(0, sRow - 1, eRow, true, results) From e77c2a34f6afe71ccc58158daeea0c3a8a0e6596 Mon Sep 17 00:00:00 2001 From: fedepujol <9yjbd325@anonaddy.me> Date: Fri, 20 May 2022 18:04:59 -0300 Subject: [PATCH 11/12] Change how to manage unicode --- lua/move/core/horiz.lua | 59 +++++++++++++++++------------------------ lua/move/utils/init.lua | 6 +++++ 2 files changed, 30 insertions(+), 35 deletions(-) diff --git a/lua/move/core/horiz.lua b/lua/move/core/horiz.lua index 76fcb98..ac7351b 100644 --- a/lua/move/core/horiz.lua +++ b/lua/move/core/horiz.lua @@ -103,47 +103,36 @@ M.horzBlock = function(dir) local sRow, col = unpack(vim.api.nvim_win_get_cursor(0)) local eRow = vim.fn.line("'>") - local lines = vim.api.nvim_buf_get_lines(0, sRow - 1, eRow, true) - local new_line = '' - local selected = '' - local prefix = '' - local suffix = '' - local results = {} - - -- Iterates over the lines of the visual area - for _, line in ipairs(lines) do - local target = '' - - if dir > 0 then - if eCol == line:len() then - target = ' ' - else - target = string.sub(line, eCol + 1, eCol + 1) - end + -- Checks line limits with the direction + if dir < 0 and col < 1 then + vim.cmd('execute "normal! \\' .. (eCol - sCol) .. 'l' .. (eRow - sRow) .. 'j' .. '"') + return + end - selected = string.sub(line, sCol, eCol) - prefix = string.sub(line, 1, sCol - 1) - suffix = string.sub(line, eCol + 2) - else - if col == 0 then - return - end + local offset_composite = 0 + vim.api.nvim_win_set_cursor(0, { sRow, sCol - 1}) - target = string.sub(line, sCol - 1, sCol - 1) - selected = string.sub(line, sCol, eCol) - prefix = string.sub(line, 1, sCol - 2) - suffix = string.sub(line, eCol + 1) + for i = 1, eCol - sCol, 1 do + local comp = utils.isCharComposite() + print(comp) + if comp then + offset_composite = offset_composite + 1 end - -- Remove trailing spaces from the lines before - -- inserting them into the results table - new_line = prefix .. (dir > 0 and target .. selected or selected .. target) .. suffix - new_line = new_line:gsub('%s+$', '') - table.insert(results, new_line) + vim.api.nvim_win_set_cursor(0, { sRow, (sCol - 1) + i }) end + print('offset_composite:'..offset_composite) - vim.api.nvim_buf_set_lines(0, sRow - 1, eRow, true, results) - vim.api.nvim_win_set_cursor(0, { sRow, (sCol - 1) + dir }) + vim.api.nvim_win_set_cursor(0, { sRow, sCol - 1}) + vim.cmd('execute "normal! \\' .. (eCol - sCol) .. 'l' .. (eRow - sRow) .. 'j' .. '"') + vim.cmd(':normal! x') + + if dir > 0 then + vim.cmd(':normal! p') + else + vim.api.nvim_win_set_cursor(0, { sRow, sCol - 2 }) + vim.cmd(':normal! P') + end -- Update the visual area with the new position of the characters vim.cmd('execute "normal! \\e\\e"') diff --git a/lua/move/utils/init.lua b/lua/move/utils/init.lua index 9d1f434..886297e 100644 --- a/lua/move/utils/init.lua +++ b/lua/move/utils/init.lua @@ -149,6 +149,12 @@ M.isUnicode = function(char) return char:len() > 5 end +M.isCharComposite = function() + local char = vim.api.nvim_exec(':normal! g8', true) + char = string.gsub(char, '%s+$', '') + return char:len() > 2 +end + M.getChar = function() vim.cmd(':normal! x') return vim.fn.getreg('"0') From c348c11463752a7802cefa105a4109729d1e57de Mon Sep 17 00:00:00 2001 From: fedepujol <9yjbd325@anonaddy.me> Date: Mon, 23 May 2022 18:04:15 -0300 Subject: [PATCH 12/12] Create new functions for composite character offset --- lua/move/core/horiz.lua | 25 +++++++++++++++---------- lua/move/utils/init.lua | 15 +++++++++++++++ 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/lua/move/core/horiz.lua b/lua/move/core/horiz.lua index ac7351b..ad48971 100644 --- a/lua/move/core/horiz.lua +++ b/lua/move/core/horiz.lua @@ -110,21 +110,26 @@ M.horzBlock = function(dir) end local offset_composite = 0 - vim.api.nvim_win_set_cursor(0, { sRow, sCol - 1}) + vim.api.nvim_win_set_cursor(0, { sRow, sCol - 1 }) - for i = 1, eCol - sCol, 1 do + local i = sCol + + while i < eCol + 1 do local comp = utils.isCharComposite() - print(comp) if comp then - offset_composite = offset_composite + 1 + local char = utils.getCharNew() + local offset = utils.getSize(char) + offset_composite = offset_composite + utils.getSize(char) - 1 + print('col '..i, 'offComp '..offset_composite, 'offset '..offset, 'char '..char) + i = i + offset + else + i = i + 1 end - - vim.api.nvim_win_set_cursor(0, { sRow, (sCol - 1) + i }) + vim.api.nvim_win_set_cursor(0, { sRow, i - 1 }) end - print('offset_composite:'..offset_composite) - vim.api.nvim_win_set_cursor(0, { sRow, sCol - 1}) - vim.cmd('execute "normal! \\' .. (eCol - sCol) .. 'l' .. (eRow - sRow) .. 'j' .. '"') + vim.api.nvim_win_set_cursor(0, { sRow, sCol - 1 }) + vim.cmd('execute "normal! \\' .. (eCol - sCol - offset_composite) .. 'l' .. (eRow - sRow) .. 'j' .. '"') vim.cmd(':normal! x') if dir > 0 then @@ -136,7 +141,7 @@ M.horzBlock = function(dir) -- Update the visual area with the new position of the characters vim.cmd('execute "normal! \\e\\e"') - local cmd_suffix = (eCol - sCol > 0 and (eCol - sCol) .. 'l' or '') + local cmd_suffix = (eCol - sCol > 0 and (eCol - sCol - offset_composite) .. 'l' or '') cmd_suffix = cmd_suffix .. (eRow - sRow > 0 and (eRow - sRow) .. 'j' or '') vim.cmd('execute "normal! \\' .. cmd_suffix .. '"') end diff --git a/lua/move/utils/init.lua b/lua/move/utils/init.lua index 886297e..e3993cf 100644 --- a/lua/move/utils/init.lua +++ b/lua/move/utils/init.lua @@ -160,6 +160,12 @@ M.getChar = function() return vim.fn.getreg('"0') end +M.getCharNew = function() + local char = vim.api.nvim_exec(':normal! g8', true) + char = string.gsub(char, '%s+$', '') + return char +end + M.getVisualChar = function(sCol, eCol) vim.cmd(':normal! v'..(eCol - sCol)..'l') vim.cmd(':normal! x') @@ -241,4 +247,13 @@ M.suffixTilde = function(tChar, sChar, line, col, dir) return suffix end +M.getSize = function(char) + local t = {} + + for w in string.gmatch(char, "%w+") do + table.insert(t, w) + end + return #t +end + return M