fix(pickers): improve CRLF line splitting support for windows (#3127)
* fix(help_tags): show help tags on windows (#3126) On Windows, `builtin.help_tags` picker does not show any help tags. To fix this, the following changes are needed: 1. `util.path_tail` checks unix separator `/` on Windows and leave the original implementation intact on unix systems. 2. Line endings should be taken carefully on Windows. `vim.split` with only newline `\n` character as separator may result in unexpected crash when parsing large files. When splits on lines are needed, call it with `\r?\n`, or even set up a wrapper function in utils is more prefered. Fixes #3126 * fix: handle cross platform line splits
This commit is contained in:
@@ -216,13 +216,25 @@ end)()
|
||||
utils.path_tail = (function()
|
||||
local os_sep = utils.get_separator()
|
||||
|
||||
return function(path)
|
||||
for i = #path, 1, -1 do
|
||||
if path:sub(i, i) == os_sep then
|
||||
return path:sub(i + 1, -1)
|
||||
if os_sep == "/" then
|
||||
return function(path)
|
||||
for i = #path, 1, -1 do
|
||||
if path:sub(i, i) == os_sep then
|
||||
return path:sub(i + 1, -1)
|
||||
end
|
||||
end
|
||||
return path
|
||||
end
|
||||
else
|
||||
return function(path)
|
||||
for i = #path, 1, -1 do
|
||||
local c = path:sub(i, i)
|
||||
if c == os_sep or c == "/" then
|
||||
return path:sub(i + 1, -1)
|
||||
end
|
||||
end
|
||||
return path
|
||||
end
|
||||
return path
|
||||
end
|
||||
end)()
|
||||
|
||||
@@ -727,4 +739,16 @@ utils.reverse_table = function(input_table)
|
||||
return temp_table
|
||||
end
|
||||
|
||||
utils.split_lines = (function()
|
||||
if utils.iswin then
|
||||
return function(s, opts)
|
||||
return vim.split(s, "\r?\n", opts)
|
||||
end
|
||||
else
|
||||
return function(s, opts)
|
||||
return vim.split(s, "\n", opts)
|
||||
end
|
||||
end
|
||||
end)()
|
||||
|
||||
return utils
|
||||
|
||||
Reference in New Issue
Block a user