From 5416c3f1d417eea9a24cba00a91cc6aca8dc30ad Mon Sep 17 00:00:00 2001 From: elektrahesse Date: Sun, 10 Oct 2010 15:55:33 +0200 Subject: RED-628: Tab completion isn't setting the cursor in the right position. Now the cursor goes to the end of the selected part. It's impossible to deselect on the fly upon keystroke unless we go hacking in LLLineEditor, which takes the key down before even reaching the chatbar... --- linden/indra/newview/llchatbar.cpp | 42 ++++++++++++++++---------------------- linden/indra/newview/llchatbar.h | 2 ++ 2 files changed, 20 insertions(+), 24 deletions(-) (limited to 'linden/indra') diff --git a/linden/indra/newview/llchatbar.cpp b/linden/indra/newview/llchatbar.cpp index 19ac2ab..e393342 100644 --- a/linden/indra/newview/llchatbar.cpp +++ b/linden/indra/newview/llchatbar.cpp @@ -122,6 +122,8 @@ LLChatBar::LLChatBar() mCompletionHolder.current_index = 0; mCompletionHolder.last_match = ""; mCompletionHolder.last_txt = ""; + mCompletionHolder.cursorPos = -1; + mCompletionHolder.selected = false; #if !LL_RELEASE_FOR_DOWNLOAD childDisplayNotFound(); @@ -227,16 +229,17 @@ BOOL LLChatBar::handleKeyHere( KEY key, MASK mask ) if (!avatar_ids.empty() && !txt.empty()) { - S32 cursorPos = mInputEditor->getCursor(); + if (mCompletionHolder.cursorPos == -1) // Ele: cache cursor position + mCompletionHolder.cursorPos = mInputEditor->getCursor(); if (mCompletionHolder.last_txt != mInputEditor->getText()) { mCompletionHolder.last_txt = std::string(mInputEditor->getText()); - if (cursorPos < (S32)txt.length()) + if (mCompletionHolder.cursorPos < (S32)txt.length()) { - mCompletionHolder.right = txt.substr(cursorPos); - mCompletionHolder.left = txt.substr(0, cursorPos); + mCompletionHolder.right = txt.substr(mCompletionHolder.cursorPos); + mCompletionHolder.left = txt.substr(0, mCompletionHolder.cursorPos); mCompletionHolder.match = std::string(mCompletionHolder.left); } else @@ -265,24 +268,7 @@ BOOL LLChatBar::handleKeyHere( KEY key, MASK mask ) { if (avatar_ids[i] == gAgent.getID() || avatar_ids[i].isNull()) continue; -/* - // Grab the pos again from the objects-in-view cache... LLWorld doesn't work above 1024 meters as usual :( - LLVector3d real_pos = positions[i]; - if (real_pos[2] == 0.0f) - { - LLViewerObject *av_obj = gObjectList.findObject(avatar_ids[i]); - if (av_obj != NULL && av_obj->isAvatar()) - { - LLVOAvatar* avatarp = (LLVOAvatar*)av_obj; - if (avatarp != NULL) - real_pos = avatarp->getPositionGlobal(); - } - } - F32 dist = F32(dist_vec(positions[i], gAgent.getPositionGlobal())); - if (dist > CHAT_SHOUT_RADIUS) - continue; -*/ std::string agent_name = " "; std::string agent_surname = " "; @@ -308,15 +294,22 @@ BOOL LLChatBar::handleKeyHere( KEY key, MASK mask ) std::string current_name = mCompletionHolder.names[mCompletionHolder.current_index]; mInputEditor->setText(mCompletionHolder.left.substr(0, mCompletionHolder.left.length() - mCompletionHolder.match.length()) + current_name + mCompletionHolder.right); - mInputEditor->setSelection(cursorPos, cursorPos + (current_name.length() - mCompletionHolder.match.length())); + mInputEditor->setCursor(mCompletionHolder.cursorPos + (current_name.length() - mCompletionHolder.match.length())); + mInputEditor->setSelection(mCompletionHolder.cursorPos, mCompletionHolder.cursorPos + (current_name.length() - mCompletionHolder.match.length())); mCompletionHolder.current_index++; + mCompletionHolder.selected = TRUE; return TRUE; } } } } + else + { + mCompletionHolder.cursorPos = -1; + mInputEditor->deselect(); + } return handled; } @@ -663,6 +656,9 @@ void LLChatBar::stopChat() void LLChatBar::onInputEditorKeystroke( LLLineEditor* caller, void* userdata ) { LLChatBar* self = (LLChatBar *)userdata; + KEY key = gKeyboard->currentKey(); + + self->mCompletionHolder.cursorPos = -1; // Ele: reset cached cursor pos for autocompletion LLWString raw_text; if (self->mInputEditor) raw_text = self->mInputEditor->getWText(); @@ -707,8 +703,6 @@ void LLChatBar::onInputEditorKeystroke( LLLineEditor* caller, void* userdata ) } */ - KEY key = gKeyboard->currentKey(); - // Ignore "special" keys, like backspace, arrows, etc. if (length > 1 && raw_text[0] == '/' && key < KEY_SPECIAL) { diff --git a/linden/indra/newview/llchatbar.h b/linden/indra/newview/llchatbar.h index 5542d8a..3e7ee03 100644 --- a/linden/indra/newview/llchatbar.h +++ b/linden/indra/newview/llchatbar.h @@ -54,6 +54,8 @@ struct CompletionHolder { std::string last_txt; std::string last_match; int current_index; + S32 cursorPos; + BOOL selected; }; class LLChatBar -- cgit v1.1