aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llui
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llui')
-rw-r--r--linden/indra/llui/lllineeditor.cpp52
-rw-r--r--linden/indra/llui/lllineeditor.h5
2 files changed, 33 insertions, 24 deletions
diff --git a/linden/indra/llui/lllineeditor.cpp b/linden/indra/llui/lllineeditor.cpp
index fc33dcf..6994f0b 100644
--- a/linden/indra/llui/lllineeditor.cpp
+++ b/linden/indra/llui/lllineeditor.cpp
@@ -135,18 +135,14 @@ LLLineEditor::LLLineEditor(const std::string& name, const LLRect& rect,
135 mSelectAllonCommit( TRUE ), 135 mSelectAllonCommit( TRUE ),
136 mPassDelete(FALSE), 136 mPassDelete(FALSE),
137 mReadOnly(FALSE), 137 mReadOnly(FALSE),
138 mHaveHistory(FALSE),
138 mImage( sImage ), 139 mImage( sImage ),
139 mReplaceNewlinesWithSpaces( TRUE ) 140 mReplaceNewlinesWithSpaces( TRUE )
140{ 141{
141 llassert( max_length_bytes > 0 ); 142 llassert( max_length_bytes > 0 );
142 143
143 // line history support: 144 // Initialize current history line iterator
144 // - initialize line history list 145 mCurrentHistoryLine = mLineHistory.begin();
145 mLineHistory.insert( mLineHistory.end(), "" );
146 // - disable line history by default
147 mHaveHistory = FALSE;
148 // - reset current history line pointer
149 mCurrentHistoryLine = 0;
150 146
151 if (font) 147 if (font)
152 { 148 {
@@ -244,16 +240,31 @@ void LLLineEditor::updateHistory()
244 // reset current history line number. 240 // reset current history line number.
245 // Be sure only to remember lines that are not empty and that are 241 // Be sure only to remember lines that are not empty and that are
246 // different from the last on the list. 242 // different from the last on the list.
247 if( mHaveHistory && mText.length() && ( mLineHistory.empty() || getText() != mLineHistory.back() ) ) 243 if( mHaveHistory && getLength() )
248 { 244 {
249 // discard possible empty line at the end of the history 245 if( !mLineHistory.empty() )
250 // inserted by setText()
251 if( !mLineHistory.back().length() )
252 { 246 {
253 mLineHistory.pop_back(); 247 // When not empty, last line of history should always be blank.
248 if( mLineHistory.back().empty() )
249 {
250 // discard the empty line
251 mLineHistory.pop_back();
252 }
253 else
254 {
255 LL_WARNS("") << "Last line of history was not blank." << LL_ENDL;
256 }
254 } 257 }
255 mLineHistory.insert( mLineHistory.end(), getText() ); 258
256 mCurrentHistoryLine = mLineHistory.size() - 1; 259 // Add text to history, ignoring duplicates
260 if( mLineHistory.empty() || getText() != mLineHistory.back() )
261 {
262 mLineHistory.push_back( getText() );
263 }
264
265 // Restore the blank line and set mCurrentHistoryLine to point at it
266 mLineHistory.push_back( "" );
267 mCurrentHistoryLine = mLineHistory.end() - 1;
257 } 268 }
258} 269}
259 270
@@ -324,11 +335,8 @@ void LLLineEditor::setText(const LLStringExplicit &new_text)
324 } 335 }
325 setCursor(llmin((S32)mText.length(), getCursor())); 336 setCursor(llmin((S32)mText.length(), getCursor()));
326 337
327 // Newly set text goes always in the last line of history.
328 // Possible empty strings (as with chat line) will be deleted later.
329 mLineHistory.insert( mLineHistory.end(), new_text );
330 // Set current history line to end of history. 338 // Set current history line to end of history.
331 mCurrentHistoryLine = mLineHistory.size() - 1; 339 mCurrentHistoryLine = mLineHistory.end() - 1;
332 340
333 mPrevText = mText; 341 mPrevText = mText;
334} 342}
@@ -1200,9 +1208,9 @@ BOOL LLLineEditor::handleSpecialKey(KEY key, MASK mask)
1200 case KEY_UP: 1208 case KEY_UP:
1201 if( mHaveHistory && ( MASK_CONTROL == mask ) ) 1209 if( mHaveHistory && ( MASK_CONTROL == mask ) )
1202 { 1210 {
1203 if( mCurrentHistoryLine > 0 ) 1211 if( mCurrentHistoryLine > mLineHistory.begin() )
1204 { 1212 {
1205 mText.assign( mLineHistory[ --mCurrentHistoryLine ] ); 1213 mText.assign( *(--mCurrentHistoryLine) );
1206 setCursor(llmin((S32)mText.length(), getCursor())); 1214 setCursor(llmin((S32)mText.length(), getCursor()));
1207 } 1215 }
1208 else 1216 else
@@ -1217,9 +1225,9 @@ BOOL LLLineEditor::handleSpecialKey(KEY key, MASK mask)
1217 case KEY_DOWN: 1225 case KEY_DOWN:
1218 if( mHaveHistory && ( MASK_CONTROL == mask ) ) 1226 if( mHaveHistory && ( MASK_CONTROL == mask ) )
1219 { 1227 {
1220 if( !mLineHistory.empty() && mCurrentHistoryLine < mLineHistory.size() - 1 ) 1228 if( !mLineHistory.empty() && mCurrentHistoryLine < mLineHistory.end() - 1 )
1221 { 1229 {
1222 mText.assign( mLineHistory[ ++mCurrentHistoryLine ] ); 1230 mText.assign( *(++mCurrentHistoryLine) );
1223 setCursor(llmin((S32)mText.length(), getCursor())); 1231 setCursor(llmin((S32)mText.length(), getCursor()));
1224 } 1232 }
1225 else 1233 else
diff --git a/linden/indra/llui/lllineeditor.h b/linden/indra/llui/lllineeditor.h
index a670b21..f7cff8f 100644
--- a/linden/indra/llui/lllineeditor.h
+++ b/linden/indra/llui/lllineeditor.h
@@ -259,8 +259,9 @@ protected:
259 259
260 // line history support: 260 // line history support:
261 BOOL mHaveHistory; // flag for enabled line history 261 BOOL mHaveHistory; // flag for enabled line history
262 std::vector<std::string> mLineHistory; // line history storage 262 typedef std::vector<std::string> line_history_t;
263 U32 mCurrentHistoryLine; // currently browsed history line 263 line_history_t mLineHistory; // line history storage
264 line_history_t::iterator mCurrentHistoryLine; // currently browsed history line
264 265
265 LLViewBorder* mBorder; 266 LLViewBorder* mBorder;
266 const LLFontGL* mGLFont; 267 const LLFontGL* mGLFont;