summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Webb <chris@arachsys.com>2023-05-09 22:56:55 +0200
committerJohannes Altmanninger <aclopte@gmail.com>2023-05-09 23:07:07 +0200
commitfc6f32f9ee409bf755b420263eb698e8e5d6ccca (patch)
treea117a45c4195fa249d300e0fb9198b8621a95389
parent2adc81c4c937e2422b1f3fa7cf470e1e7b040ffa (diff)
Stop _ from tearing multibyte UTF-8 sequences
Fixes #4887 [ja: add test]
-rw-r--r--src/normal.cc9
-rw-r--r--test/regression/4887-torn-utf8-sequence/cmd1
-rw-r--r--test/regression/4887-torn-utf8-sequence/in0
-rw-r--r--test/regression/4887-torn-utf8-sequence/out1
4 files changed, 7 insertions, 4 deletions
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<BufferIterator>;
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 %{<percent>cç<lt>esc>x_<semicolon>iab<lt>esc>}<ret>
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
--- /dev/null
+++ b/test/regression/4887-torn-utf8-sequence/in
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ç