Stop _ from tearing multibyte UTF-8 sequences

Fixes #4887

[ja: add test]
This commit is contained in:
Chris Webb 2023-05-09 22:56:55 +02:00 committed by Johannes Altmanninger
parent 2adc81c4c9
commit fc6f32f9ee
4 changed files with 7 additions and 4 deletions

View File

@ -1768,6 +1768,7 @@ void spaces_to_tabs(Context& context, NormalParams params)
void trim_selections(Context& context, NormalParams) void trim_selections(Context& context, NormalParams)
{ {
using Utf8It = utf8::iterator<BufferIterator>;
auto& buffer = context.buffer(); auto& buffer = context.buffer();
ScopedSelectionEdition selection_edition{context}; ScopedSelectionEdition selection_edition{context};
auto& selections = context.selections(); auto& selections = context.selections();
@ -1776,8 +1777,8 @@ void trim_selections(Context& context, NormalParams)
for (int i = 0; i < (int)selections.size(); ++i) for (int i = 0; i < (int)selections.size(); ++i)
{ {
auto& sel = selections[i]; auto& sel = selections[i];
auto beg = buffer.iterator_at(sel.min()); auto beg = Utf8It{buffer.iterator_at(sel.min()), buffer};
auto end = buffer.iterator_at(sel.max()); auto end = Utf8It{buffer.iterator_at(sel.max()), buffer};
while (beg != end and is_blank(*beg)) while (beg != end and is_blank(*beg))
++beg; ++beg;
while (beg != end and is_blank(*end)) while (beg != end and is_blank(*end))
@ -1787,8 +1788,8 @@ void trim_selections(Context& context, NormalParams)
to_remove.push_back(i); to_remove.push_back(i);
else else
{ {
sel.min() = beg.coord(); sel.min() = beg.base().coord();
sel.max() = end.coord(); sel.max() = end.base().coord();
} }
} }

View File

@ -0,0 +1 @@
:exec %{<percent>cç<lt>esc>x_<semicolon>iab<lt>esc>}<ret>

View File

@ -0,0 +1 @@
abç