diff options
author | elektrahesse | 2010-09-16 18:09:52 +0200 |
---|---|---|
committer | elektrahesse | 2010-09-16 18:09:52 +0200 |
commit | e3734349d2aa0dc4f6b9c7e00616cb95861bb73d (patch) | |
tree | e98397484c7f59ce4dfc3f2492cee2a1dabb8e57 /linden/indra/newview | |
parent | Fixed a bug related to the names cache clearing :P (diff) | |
download | meta-impy-e3734349d2aa0dc4f6b9c7e00616cb95861bb73d.zip meta-impy-e3734349d2aa0dc4f6b9c7e00616cb95861bb73d.tar.gz meta-impy-e3734349d2aa0dc4f6b9c7e00616cb95861bb73d.tar.bz2 meta-impy-e3734349d2aa0dc4f6b9c7e00616cb95861bb73d.tar.xz |
Moved all the variables to a struct to keep code more clean and added a check to run the regex match only if the text in chat changes, so it's a bit lighter
Diffstat (limited to 'linden/indra/newview')
-rw-r--r-- | linden/indra/newview/llchatbar.cpp | 80 | ||||
-rw-r--r-- | linden/indra/newview/llchatbar.h | 14 |
2 files changed, 53 insertions, 41 deletions
diff --git a/linden/indra/newview/llchatbar.cpp b/linden/indra/newview/llchatbar.cpp index 9d56638..ffd5afa 100644 --- a/linden/indra/newview/llchatbar.cpp +++ b/linden/indra/newview/llchatbar.cpp | |||
@@ -116,8 +116,9 @@ LLChatBar::LLChatBar() | |||
116 | { | 116 | { |
117 | setIsChrome(TRUE); | 117 | setIsChrome(TRUE); |
118 | 118 | ||
119 | current_index = 0; | 119 | mCompletionHolder.current_index = 0; |
120 | last_initials = ""; | 120 | mCompletionHolder.last_match = ""; |
121 | mCompletionHolder.last_txt = ""; | ||
121 | 122 | ||
122 | #if !LL_RELEASE_FOR_DOWNLOAD | 123 | #if !LL_RELEASE_FOR_DOWNLOAD |
123 | childDisplayNotFound(); | 124 | childDisplayNotFound(); |
@@ -222,37 +223,40 @@ BOOL LLChatBar::handleKeyHere( KEY key, MASK mask ) | |||
222 | { | 223 | { |
223 | mInputEditor->deleteSelection(); // Clean up prev completion before attempting a new one | 224 | mInputEditor->deleteSelection(); // Clean up prev completion before attempting a new one |
224 | 225 | ||
225 | std::string txt(mInputEditor->getText()); | ||
226 | std::string to_match(txt); | ||
227 | std::string left_part = ""; | ||
228 | std::string right_part = ""; | ||
229 | S32 cursorPos = mInputEditor->getCursor(); | 226 | S32 cursorPos = mInputEditor->getCursor(); |
227 | std::string txt(mInputEditor->getText()); | ||
230 | 228 | ||
231 | if (cursorPos < (S32)txt.length()) | 229 | if (mCompletionHolder.last_txt != mInputEditor->getText()) |
232 | { | ||
233 | right_part = txt.substr(cursorPos); | ||
234 | left_part = txt.substr(0, cursorPos); | ||
235 | to_match = std::string(left_part); | ||
236 | } | ||
237 | else | ||
238 | { | 230 | { |
239 | to_match = std::string(txt); | 231 | mCompletionHolder.last_txt = std::string(mInputEditor->getText()); |
240 | left_part = txt; | ||
241 | } | ||
242 | 232 | ||
243 | std::string pattern_s = "(^|.*[_=&\\|\\<\\>#@\\[\\]\\-\\+\"',\\.\\?!:;\\*\\(\\)\\s]+)([a-z0-9]+)$"; | 233 | if (cursorPos < (S32)txt.length()) |
244 | boost::match_results<std::string::const_iterator> what; | 234 | { |
245 | boost::regex expression(pattern_s, boost::regex::icase); | 235 | mCompletionHolder.right = txt.substr(cursorPos); |
246 | if (boost::regex_search(to_match, what, expression, boost::match_extra)) | 236 | mCompletionHolder.left = txt.substr(0, cursorPos); |
247 | { | 237 | mCompletionHolder.match = std::string(mCompletionHolder.left); |
248 | to_match = what[2]; | 238 | } |
249 | if (to_match.length() < 1) | 239 | else |
240 | { | ||
241 | mCompletionHolder.right = ""; | ||
242 | mCompletionHolder.match = std::string(txt); | ||
243 | mCompletionHolder.left = txt; | ||
244 | } | ||
245 | |||
246 | std::string pattern_s = "(^|.*[_=&\\|\\<\\>#@\\[\\]\\-\\+\"',\\.\\?!:;\\*\\(\\)\\s]+)([a-z0-9]+)$"; | ||
247 | boost::match_results<std::string::const_iterator> what; | ||
248 | boost::regex expression(pattern_s, boost::regex::icase); | ||
249 | if (boost::regex_search(mCompletionHolder.match, what, expression, boost::match_extra)) | ||
250 | { | ||
251 | mCompletionHolder.match = what[2]; | ||
252 | if (mCompletionHolder.match.length() < 1) | ||
253 | return handled; | ||
254 | } | ||
255 | else | ||
250 | return handled; | 256 | return handled; |
251 | } | 257 | } |
252 | else | ||
253 | return handled; | ||
254 | 258 | ||
255 | names.clear(); | 259 | mCompletionHolder.names.clear(); |
256 | 260 | ||
257 | for (U32 i=0; i<avatar_ids.size(); i++) | 261 | for (U32 i=0; i<avatar_ids.size(); i++) |
258 | { | 262 | { |
@@ -284,26 +288,26 @@ BOOL LLChatBar::handleKeyHere( KEY key, MASK mask ) | |||
284 | 288 | ||
285 | std::string test_name(agent_name); | 289 | std::string test_name(agent_name); |
286 | std::transform(test_name.begin(), test_name.end(), test_name.begin(), tolower); | 290 | std::transform(test_name.begin(), test_name.end(), test_name.begin(), tolower); |
287 | std::transform(to_match.begin(), to_match.end(), to_match.begin(), tolower); | 291 | std::transform(mCompletionHolder.match.begin(), mCompletionHolder.match.end(), mCompletionHolder.match.begin(), tolower); |
288 | 292 | ||
289 | if (test_name.find(to_match) == 0) | 293 | if (test_name.find(mCompletionHolder.match) == 0) |
290 | names.push_back(agent_name); | 294 | mCompletionHolder.names.push_back(agent_name); |
291 | } | 295 | } |
292 | 296 | ||
293 | if (current_index >= names.size() || to_match != last_initials) | 297 | if (mCompletionHolder.current_index >= mCompletionHolder.names.size() || mCompletionHolder.match != mCompletionHolder.last_match) |
294 | { | 298 | { |
295 | current_index = 0; | 299 | mCompletionHolder.current_index = 0; |
296 | last_initials = to_match; | 300 | mCompletionHolder.last_match = mCompletionHolder.match; |
297 | } | 301 | } |
298 | 302 | ||
299 | if (names.size() > 0) | 303 | if (mCompletionHolder.names.size() > 0) |
300 | { | 304 | { |
301 | std::string current_name = names[current_index]; | 305 | std::string current_name = mCompletionHolder.names[mCompletionHolder.current_index]; |
302 | 306 | ||
303 | mInputEditor->setText(left_part.substr(0, left_part.length() - to_match.length()) + current_name + right_part); | 307 | mInputEditor->setText(mCompletionHolder.left.substr(0, mCompletionHolder.left.length() - mCompletionHolder.match.length()) + current_name + mCompletionHolder.right); |
304 | mInputEditor->setSelection(cursorPos, cursorPos + (current_name.length() - to_match.length())); | 308 | mInputEditor->setSelection(cursorPos, cursorPos + (current_name.length() - mCompletionHolder.match.length())); |
305 | 309 | ||
306 | current_index++; | 310 | mCompletionHolder.current_index++; |
307 | 311 | ||
308 | return TRUE; | 312 | return TRUE; |
309 | } | 313 | } |
diff --git a/linden/indra/newview/llchatbar.h b/linden/indra/newview/llchatbar.h index 202b006..135881f 100644 --- a/linden/indra/newview/llchatbar.h +++ b/linden/indra/newview/llchatbar.h | |||
@@ -46,6 +46,16 @@ class LLChatBarGestureObserver; | |||
46 | class LLComboBox; | 46 | class LLComboBox; |
47 | class LLSpinCtrl; | 47 | class LLSpinCtrl; |
48 | 48 | ||
49 | typedef struct { | ||
50 | std::string left; | ||
51 | std::string right; | ||
52 | std::string match; | ||
53 | std::vector<std::string> names; | ||
54 | std::string last_txt; | ||
55 | std::string last_match; | ||
56 | int current_index; | ||
57 | } CompletionHolder; | ||
58 | |||
49 | class LLChatBar | 59 | class LLChatBar |
50 | : public LLPanel | 60 | : public LLPanel |
51 | { | 61 | { |
@@ -118,9 +128,7 @@ private: | |||
118 | BOOL mChanCtrlEnabled; | 128 | BOOL mChanCtrlEnabled; |
119 | LLSpinCtrl* mChannelControl; | 129 | LLSpinCtrl* mChannelControl; |
120 | 130 | ||
121 | std::vector<std::string> names; | 131 | CompletionHolder mCompletionHolder; |
122 | std::string last_initials; | ||
123 | int current_index; | ||
124 | }; | 132 | }; |
125 | 133 | ||
126 | extern LLChatBar *gChatBar; | 134 | extern LLChatBar *gChatBar; |