diff --git a/src/normal.cc b/src/normal.cc index e3220521..2bc7fc17 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -1768,6 +1768,7 @@ void spaces_to_tabs(Context& context, NormalParams params) void trim_selections(Context& context, NormalParams) { + using Utf8It = utf8::iterator; auto& buffer = context.buffer(); ScopedSelectionEdition selection_edition{context}; auto& selections = context.selections(); @@ -1776,8 +1777,8 @@ void trim_selections(Context& context, NormalParams) for (int i = 0; i < (int)selections.size(); ++i) { auto& sel = selections[i]; - auto beg = buffer.iterator_at(sel.min()); - auto end = buffer.iterator_at(sel.max()); + auto beg = Utf8It{buffer.iterator_at(sel.min()), buffer}; + auto end = Utf8It{buffer.iterator_at(sel.max()), buffer}; while (beg != end and is_blank(*beg)) ++beg; while (beg != end and is_blank(*end)) @@ -1787,8 +1788,8 @@ void trim_selections(Context& context, NormalParams) to_remove.push_back(i); else { - sel.min() = beg.coord(); - sel.max() = end.coord(); + sel.min() = beg.base().coord(); + sel.max() = end.base().coord(); } } diff --git a/test/regression/4887-torn-utf8-sequence/cmd b/test/regression/4887-torn-utf8-sequence/cmd new file mode 100644 index 00000000..8a70e75f --- /dev/null +++ b/test/regression/4887-torn-utf8-sequence/cmd @@ -0,0 +1 @@ +:exec %{esc>x_iabesc>} diff --git a/test/regression/4887-torn-utf8-sequence/in b/test/regression/4887-torn-utf8-sequence/in new file mode 100644 index 00000000..e69de29b diff --git a/test/regression/4887-torn-utf8-sequence/out b/test/regression/4887-torn-utf8-sequence/out new file mode 100644 index 00000000..155dd4fa --- /dev/null +++ b/test/regression/4887-torn-utf8-sequence/out @@ -0,0 +1 @@ +abç