From 6fd486c65e74d744c282a996e04beae42ca684d1 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 24 Nov 2019 17:25:14 +1100 Subject: [PATCH] Replace tab characters with spaces in info/echo This is tricky to fix better than that as tabs make text length dependent on where it will get displayed and what preceedes it. Also fix an issue with empty info title Fixes #2237 --- src/client.cc | 4 ++-- src/commands.cc | 2 +- src/display_buffer.cc | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/client.cc b/src/client.cc index 03f35c3f..f847d24e 100644 --- a/src/client.cc +++ b/src/client.cc @@ -425,9 +425,9 @@ void Client::info_show(StringView title, StringView content, BufferCoord anchor, { if (not content.empty() and content.back() == '\n') content = content.substr(0, content.length() - 1); - info_show({title.str(), Face{}}, + info_show(title.empty() ? DisplayLine{} : DisplayLine{title.str(), Face{}}, content | split('\n') - | transform([](StringView s) { return DisplayLine{s.str(), Face{}}; }) + | transform([](StringView s) { return DisplayLine{replace(s, '\t', ' '), Face{}}; }) | gather(), anchor, style); } diff --git a/src/commands.cc b/src/commands.cc index 728b4403..8fe38134 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -1277,7 +1277,7 @@ const CommandDesc echo_cmd = { else if (parser.get_switch("markup")) context.print_status(parse_display_line(message, context.faces())); else - context.print_status({ std::move(message), context.faces()["StatusLine"] }); + context.print_status({replace(message, '\t', ' '), context.faces()["StatusLine"]}); } }; diff --git a/src/display_buffer.cc b/src/display_buffer.cc index 12a234e2..e7e2da54 100644 --- a/src/display_buffer.cc +++ b/src/display_buffer.cc @@ -286,7 +286,7 @@ DisplayLine parse_display_line(StringView line, const FaceRegistry& faces, const pos = closing + 1; } } - if (c == '\n') // line breaks are forbidden, replace with space + if (c == '\n' or c == '\t') // line breaks and tabs are forbidden, replace with space { content += StringView{pos, it+1}; content.back() = ' ';