aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llui/lllineeditor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llui/lllineeditor.cpp')
-rw-r--r--linden/indra/llui/lllineeditor.cpp81
1 files changed, 81 insertions, 0 deletions
diff --git a/linden/indra/llui/lllineeditor.cpp b/linden/indra/llui/lllineeditor.cpp
index a2cd9af..44616b9 100644
--- a/linden/indra/llui/lllineeditor.cpp
+++ b/linden/indra/llui/lllineeditor.cpp
@@ -157,6 +157,14 @@ LLLineEditor::LLLineEditor(const LLString& name, const LLRect& rect,
157{ 157{
158 llassert( max_length_bytes > 0 ); 158 llassert( max_length_bytes > 0 );
159 159
160 // line history support:
161 // - initialize line history list
162 mLineHistory.insert( mLineHistory.end(), "" );
163 // - disable line history by default
164 mHaveHistory = FALSE;
165 // - reset current history line pointer
166 mCurrentHistoryLine = 0;
167
160 if (font) 168 if (font)
161 { 169 {
162 mGLFont = font; 170 mGLFont = font;
@@ -229,10 +237,33 @@ void LLLineEditor::onFocusLost()
229 237
230void LLLineEditor::onCommit() 238void LLLineEditor::onCommit()
231{ 239{
240 // put current line into the line history
241 updateHistory();
242
232 LLUICtrl::onCommit(); 243 LLUICtrl::onCommit();
233 selectAll(); 244 selectAll();
234} 245}
235 246
247// line history support
248void LLLineEditor::updateHistory()
249{
250 // On history enabled line editors, remember committed line and
251 // reset current history line number.
252 // Be sure only to remember lines that are not empty and that are
253 // different from the last on the list.
254 if( mHaveHistory && mText.length() && ( mLineHistory.empty() || getText() != mLineHistory.back() ) )
255 {
256 // discard possible empty line at the end of the history
257 // inserted by setText()
258 if( !mLineHistory.back().length() )
259 {
260 mLineHistory.pop_back();
261 }
262 mLineHistory.insert( mLineHistory.end(), getText() );
263 mCurrentHistoryLine = mLineHistory.size() - 1;
264 }
265}
266
236void LLLineEditor::reshape(S32 width, S32 height, BOOL called_from_parent) 267void LLLineEditor::reshape(S32 width, S32 height, BOOL called_from_parent)
237{ 268{
238 LLUICtrl::reshape(width, height, called_from_parent ); 269 LLUICtrl::reshape(width, height, called_from_parent );
@@ -240,6 +271,10 @@ void LLLineEditor::reshape(S32 width, S32 height, BOOL called_from_parent)
240 mMaxHPixels = mRect.getWidth() - 2 * (mBorderThickness + UI_LINEEDITOR_H_PAD) + 1 - mBorderRight; 271 mMaxHPixels = mRect.getWidth() - 2 * (mBorderThickness + UI_LINEEDITOR_H_PAD) + 1 - mBorderRight;
241} 272}
242 273
274void LLLineEditor::setEnableLineHistory( BOOL enabled )
275{
276 mHaveHistory = enabled;
277}
243 278
244void LLLineEditor::setEnabled(BOOL enabled) 279void LLLineEditor::setEnabled(BOOL enabled)
245{ 280{
@@ -300,6 +335,13 @@ void LLLineEditor::setText(const LLString &new_text)
300 deselect(); 335 deselect();
301 } 336 }
302 setCursor(llmin((S32)mText.length(), getCursor())); 337 setCursor(llmin((S32)mText.length(), getCursor()));
338
339 // Newly set text goes always in the last line of history.
340 // Possible empty strings (as with chat line) will be deleted later.
341 mLineHistory.insert( mLineHistory.end(), new_text );
342 // Set current history line to end of history.
343 mCurrentHistoryLine = mLineHistory.size() - 1;
344
303 mPrevText = mText; 345 mPrevText = mText;
304} 346}
305 347
@@ -1086,6 +1128,45 @@ BOOL LLLineEditor::handleSpecialKey(KEY key, MASK mask)
1086 } 1128 }
1087 break; 1129 break;
1088 1130
1131 // handle ctrl-uparrow if we have a history enabled line editor.
1132 case KEY_UP:
1133 if( mHaveHistory && ( MASK_CONTROL & mask ) )
1134 {
1135 if( mCurrentHistoryLine > 0 )
1136 {
1137 mText.assign( mLineHistory[ --mCurrentHistoryLine ] );
1138 setCursor(llmin((S32)mText.length(), getCursor()));
1139 }
1140 else
1141 {
1142 reportBadKeystroke();
1143 }
1144 handled = TRUE;
1145 }
1146 break;
1147
1148 // handle ctrl-downarrow if we have a history enabled line editor
1149 case KEY_DOWN:
1150 if( mHaveHistory && ( MASK_CONTROL & mask ) )
1151 {
1152 if( !mLineHistory.empty() && mCurrentHistoryLine < mLineHistory.size() - 1 )
1153 {
1154 mText.assign( mLineHistory[ ++mCurrentHistoryLine ] );
1155 setCursor(llmin((S32)mText.length(), getCursor()));
1156 }
1157 else
1158 {
1159 reportBadKeystroke();
1160 }
1161 handled = TRUE;
1162 }
1163 break;
1164
1165 case KEY_RETURN:
1166 // store sent line in history
1167 updateHistory();
1168 break;
1169
1089 case KEY_ESCAPE: 1170 case KEY_ESCAPE:
1090 if (mRevertOnEsc && mText.getString() != mPrevText) 1171 if (mRevertOnEsc && mText.getString() != mPrevText)
1091 { 1172 {