From b62daa4867e8551f7d54ee45c76cf921d94cc646 Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Fri, 15 May 2009 10:05:05 +0000 Subject: [PATCH] * adjusted _HandleInputMethodChanged() to not blindly insert the string that has been given via the inline input method, but to feed the individual UTF8-characters it contains to KeyDown() - this way special keys like B_BACKSPACE and cursor keys will be handled correctly instead of producing a "unknown char rectangle" git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30764 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/TextView.cpp | 54 +++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/src/kits/interface/TextView.cpp b/src/kits/interface/TextView.cpp index 87f0e914d6..708470f86c 100644 --- a/src/kits/interface/TextView.cpp +++ b/src/kits/interface/TextView.cpp @@ -5250,22 +5250,52 @@ BTextView::_HandleInputMethodChanged(BMessage *message) clauseCount++; } - int32 selectionStart = 0; - int32 selectionEnd = 0; - message->FindInt32("be:selection", 0, &selectionStart); - message->FindInt32("be:selection", 1, &selectionEnd); + if (confirmed) { + _Refresh(fSelStart, fSelEnd, true, true); + _ShowCaret(); - fInline->SetSelectionOffset(selectionStart); - fInline->SetSelectionLength(selectionEnd - selectionStart); + // now we need to feed ourselves the individual characters as if the + // user would have pressed them now - this lets KeyDown() pick out all + // the special characters like B_BACKSPACE, cursor keys and the like: + const char* currPos = string; + const char* prevPos = currPos; + while (*currPos != '\0') { + if ((*currPos & 0xC0) == 0xC0) { + // found the start of an UTF-8 char, we collect while it lasts + ++currPos; + while ((*currPos & 0xC0) == 0x80) + ++currPos; + } else if ((*currPos & 0xC0) == 0x80) { + // illegal: character starts with utf-8 intermediate byte, skip it + prevPos = ++currPos; + } else { + // single byte character/code, just feed that + ++currPos; + } + KeyDown(prevPos, currPos - prevPos); + prevPos = currPos; + } - const int32 inlineOffset = fInline->Offset(); - InsertText(string, stringLen, fSelStart, NULL); - fSelStart += stringLen; - fClickOffset = fSelEnd = fSelStart; + _Refresh(fSelStart, fSelEnd, true, true); + } else { + // temporarily show transient state of inline input + int32 selectionStart = 0; + int32 selectionEnd = 0; + message->FindInt32("be:selection", 0, &selectionStart); + message->FindInt32("be:selection", 1, &selectionEnd); - _Refresh(inlineOffset, fSelEnd, true, true); + fInline->SetSelectionOffset(selectionStart); + fInline->SetSelectionLength(selectionEnd - selectionStart); + + const int32 inlineOffset = fInline->Offset(); + InsertText(string, stringLen, fSelStart, NULL); + fSelStart += stringLen; + fClickOffset = fSelEnd = fSelStart; + + _Refresh(inlineOffset, fSelEnd, true, true); + _ShowCaret(); + } - _ShowCaret(); }