Skip to content

Commit 365df55

Browse files
committed
fix!: fix double width character cutoff in some terminals, fixes #371
BREAK: may be a minor breaking change for users with custom components. Components from filename onwards now add a space at the end of each component, instead of at the begining.
1 parent b356540 commit 365df55

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

lua/neo-tree/sources/common/components.lua

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ local log = require("neo-tree.log")
1818

1919
local M = {}
2020

21+
local make_two_char = function(symbol)
22+
if vim.fn.strchars(symbol) == 1 then
23+
return symbol .. " "
24+
else
25+
return symbol
26+
end
27+
end
2128
-- only works in the buffers component, but it's here so we don't have to defined
2229
-- multple renderers.
2330
M.bufnr = function(config, node, state)
@@ -90,17 +97,13 @@ M.diagnostics = function(config, node, state)
9097
end
9198
defined = defined and defined[1]
9299
if defined and defined.text and defined.texthl then
93-
-- for some reason it always comes padded with a space
94-
if type(defined.text) == "string" and defined.text:sub(#defined.text) == " " then
95-
defined.text = defined.text:sub(1, -2)
96-
end
97100
return {
98-
text = " " .. defined.text,
101+
text = make_two_char(defined.text),
99102
highlight = defined.texthl,
100103
}
101104
else
102105
return {
103-
text = " " .. severity:sub(1, 1),
106+
text = severity:sub(1, 1) .. " ",
104107
highlight = "Diagnostic" .. severity,
105108
}
106109
end
@@ -184,20 +187,20 @@ M.git_status = function(config, node, state)
184187
local components = {}
185188
if type(change_symbol) == "string" and #change_symbol > 0 then
186189
table.insert(components, {
187-
text = " " .. change_symbol,
190+
text = make_two_char(change_symbol),
188191
highlight = change_highlt,
189192
})
190193
end
191194
if type(status_symbol) == "string" and #status_symbol > 0 then
192195
table.insert(components, {
193-
text = " " .. status_symbol,
196+
text = make_two_char(status_symbol),
194197
highlight = status_highlt,
195198
})
196199
end
197200
return components
198201
else
199202
return {
200-
text = " [" .. git_status .. "]",
203+
text = "[" .. git_status .. "]",
201204
highlight = config.highlight or change_highlt,
202205
}
203206
end
@@ -208,27 +211,27 @@ M.filtered_by = function(config, node, state)
208211
local fby = node.filtered_by
209212
if fby.name then
210213
return {
211-
text = " (hide by name)",
214+
text = "(hide by name) ",
212215
highlight = highlights.HIDDEN_BY_NAME,
213216
}
214217
elseif fby.pattern then
215218
return {
216-
text = " (hide by pattern)",
219+
text = "(hide by pattern) ",
217220
highlight = highlights.HIDDEN_BY_NAME,
218221
}
219222
elseif fby.gitignored then
220223
return {
221-
text = " (gitignored)",
224+
text = "(gitignored) ",
222225
highlight = highlights.GIT_IGNORED,
223226
}
224227
elseif fby.dotfiles then
225228
return {
226-
text = " (dotfile)",
229+
text = "(dotfile) ",
227230
highlight = highlights.DOTFILE,
228231
}
229232
elseif fby.hidden then
230233
return {
231-
text = " (hidden)",
234+
text = "(hidden) ",
232235
highlight = highlights.WINDOWS_HIDDEN,
233236
}
234237
end
@@ -269,7 +272,7 @@ M.modified = function(config, node, state)
269272
local modified_buffers = state.modified_buffers or {}
270273
if modified_buffers[node.path] then
271274
return {
272-
text = " " .. (config.symbol or "[+]"),
275+
text = (config.symbol or "[+] "),
273276
highlight = config.highlight or highlights.MODIFIED,
274277
}
275278
else
@@ -301,7 +304,7 @@ M.name = function(config, node, state)
301304
end
302305

303306
return {
304-
text = text,
307+
text = text .. " ",
305308
highlight = highlight,
306309
}
307310
end

0 commit comments

Comments
 (0)