Do not strip whitespaces with '*'

Stripping whitespaces there is a failed experiment as it breaks the
ability to use multi-selections consistently: Using '*' followed by some
`N` to add following matches, we end up with mismatched selections
due to whitespace stripping the original selection still contains
whitespaces where all the new ones do not. Once we get to this state,
most selection commands will give different results for the initial
selection and the other ones, breaking predictible multiselection use,
one of the cornerstones of Kakoune editing model.
This commit is contained in:
Maxime Coste 2018-01-30 11:08:03 +11:00
parent c30a954dfc
commit 81eb2ee428
2 changed files with 3 additions and 10 deletions

View File

@ -47,7 +47,8 @@ static const char* startup_info =
" * Regex implementation switched to a custom one, the syntax is slightly\n" " * Regex implementation switched to a custom one, the syntax is slightly\n"
" less tolerant.\n" " less tolerant.\n"
" * ModeChange hook has been introduced and is expected to replace\n" " * ModeChange hook has been introduced and is expected to replace\n"
" the various ${MODE}Begin/${MODE}End hooks, consider those deprecated.\n"; " the various ${MODE}Begin/${MODE}End hooks, consider those deprecated.\n"
" * '*' Does not strip whitespaces anymore\n";
struct startup_error : runtime_error struct startup_error : runtime_error
{ {

View File

@ -838,15 +838,7 @@ void use_selection_as_search_pattern(Context& context, NormalParams params)
const auto& buffer = context.buffer(); const auto& buffer = context.buffer();
for (auto& sel : sels) for (auto& sel : sels)
{ {
auto beg = sel.min(), end = sel.max(); const auto beg = sel.min(), end = buffer.char_next(sel.max());
if (smart) // skip whitespaces
{
while (is_blank(buffer.byte_at(beg)) and beg != end)
beg = buffer.char_next(beg);
while (is_blank(buffer.byte_at(end)) and beg != end)
end = buffer.char_prev(end);
}
end = buffer.char_next(end);
patterns.push_back(format("{}\\Q{}\\E{}", patterns.push_back(format("{}\\Q{}\\E{}",
smart and is_bow(buffer, beg) ? "\\b" : "", smart and is_bow(buffer, beg) ? "\\b" : "",
buffer.string(beg, end), buffer.string(beg, end),