summaryrefslogtreecommitdiffstats
path: root/kate/part/kateviewinternal.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'kate/part/kateviewinternal.cpp')
-rw-r--r--kate/part/kateviewinternal.cpp41
1 files changed, 37 insertions, 4 deletions
diff --git a/kate/part/kateviewinternal.cpp b/kate/part/kateviewinternal.cpp
index 0f12f8562..40ab06252 100644
--- a/kate/part/kateviewinternal.cpp
+++ b/kate/part/kateviewinternal.cpp
@@ -1091,11 +1091,44 @@ public:
void KateViewInternal::moveChar( Bias bias, bool sel )
{
+ if (bias == Bias::none)
+ {
+ return;
+ }
+
+ KateTextLine::Ptr tl = m_doc->m_buffer->plainLine(cursor.line());
+ if (!tl)
+ {
+ return;
+ }
+
+ // Make sure to handle surrogate pairs correctly
+ int offset = 0;
+ int col = cursor.col();
+ if (bias == Bias::left_b)
+ {
+ offset = -1;
+ if (tl->getChar(col - 1).isLowSurrogate() && tl->getChar(col - 2).isHighSurrogate())
+ {
+ offset = -2;
+ }
+ }
+ else
+ {
+ offset = 1;
+ if (tl->getChar(col).isHighSurrogate() && tl->getChar(col + 1).isLowSurrogate())
+ {
+ offset = 2;
+ }
+ }
+
KateTextCursor c;
- if ( m_view->wrapCursor() ) {
- c = WrappingCursor( this, cursor ) += bias;
- } else {
- c = BoundedCursor( this, cursor ) += bias;
+ if (m_view->wrapCursor())
+ {
+ c = WrappingCursor( this, cursor ) += offset;
+ } else
+ {
+ c = BoundedCursor( this, cursor ) += offset;
}
updateSelection( c, sel );