CEdit::MoveChar never moves cursor between bytes of one UTF-8 symbol

fix-squashed-planets
Evgeny Pestov 2021-12-17 00:49:16 +07:00
parent 65da4c42c4
commit 69ea470a26
1 changed files with 12 additions and 6 deletions

View File

@ -2261,7 +2261,7 @@ void CEdit::MoveChar(int move, bool bWord, bool bSelect)
{ {
int character; int character;
if ( move == -1 ) // back? if ( move == -1 ) // back
{ {
if ( bWord ) if ( bWord )
{ {
@ -2306,12 +2306,15 @@ void CEdit::MoveChar(int move, bool bWord, bool bSelect)
} }
else else
{ {
m_cursor1 --; if ( m_cursor1 > 0 )
if ( m_cursor1 < 0 ) m_cursor1 = 0; {
m_cursor1 --;
while ( m_cursor1 > 0 && (m_text[m_cursor1] & 0xC0) == 0x80 ) m_cursor1 --;
}
} }
} }
if ( move == 1 ) // advance? if ( move == 1 ) // advance
{ {
if ( bWord ) if ( bWord )
{ {
@ -2356,8 +2359,11 @@ void CEdit::MoveChar(int move, bool bWord, bool bSelect)
} }
else else
{ {
m_cursor1 ++; if ( m_cursor1 < m_len )
if ( m_cursor1 > m_len ) m_cursor1 = m_len; {
m_cursor1 ++;
while ( m_cursor1 < m_len && (m_text[m_cursor1] & 0xC0) == 0x80 ) m_cursor1 ++;
}
} }
} }