pipe: auto insert and end of line if needed

This commit is contained in:
Maxime Coste 2013-07-24 13:38:26 +01:00
parent 62fdacb757
commit f6308409a1

View File

@ -261,9 +261,17 @@ void pipe(Context& context)
Editor& editor = context.editor(); Editor& editor = context.editor();
std::vector<String> strings; std::vector<String> strings;
for (auto& sel : context.editor().selections()) for (auto& sel : context.editor().selections())
strings.push_back(ShellManager::instance().pipe(content(context.buffer(), sel), {
cmdline, context, {}, auto str = content(context.buffer(), sel);
EnvVarMap{})); bool insert_eol = str.back() != '\n';
if (insert_eol)
str += '\n';
str = ShellManager::instance().pipe(str, cmdline, context,
{}, EnvVarMap{});
if (insert_eol and str.back() == '\n')
str = str.substr(0, str.length()-1);
strings.push_back(str);
}
editor.insert(strings, InsertMode::Replace); editor.insert(strings, InsertMode::Replace);
}); });
} }