From 8465910c79b8e746e04fd581cca2d60399e569b9 Mon Sep 17 00:00:00 2001 From: Jacek Antonelli Date: Fri, 15 Aug 2008 23:45:07 -0500 Subject: Second Life viewer sources 1.18.3.2-RC --- linden/indra/llui/lllineeditor.cpp | 56 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) (limited to 'linden/indra/llui/lllineeditor.cpp') diff --git a/linden/indra/llui/lllineeditor.cpp b/linden/indra/llui/lllineeditor.cpp index 98286fa..dca62d7 100644 --- a/linden/indra/llui/lllineeditor.cpp +++ b/linden/indra/llui/lllineeditor.cpp @@ -138,6 +138,8 @@ LLLineEditor::LLLineEditor(const LLString& name, const LLRect& rect, mSelectionEnd( 0 ), mLastSelectionX(-1), mLastSelectionY(-1), + mLastSelectionStart(-1), + mLastSelectionEnd(-1), mPrevalidateFunc( prevalidate_func ), mCursorColor( LLUI::sColorsGroup->getColor( "TextCursorColor" ) ), mFgColor( LLUI::sColorsGroup->getColor( "TextFgColor" ) ), @@ -247,6 +249,19 @@ void LLLineEditor::onCommit() selectAll(); } +// virtual +BOOL LLLineEditor::isDirty() const +{ + return ( mText.getString() != mPrevText ); +} + +// virtual +void LLLineEditor::resetDirty() +{ + mPrevText = mText.getString(); +} + + // line history support void LLLineEditor::updateHistory() { @@ -468,8 +483,38 @@ BOOL LLLineEditor::handleDoubleClick(S32 x, S32 y, MASK mask) } else { - // otherwise select everything - selectAll(); + const LLWString& wtext = mText.getWString(); + + BOOL doSelectAll = TRUE; + + // Select the word we're on + if( isPartOfWord( wtext[mCursorPos] ) ) + { + S32 old_selection_start = mLastSelectionStart; + S32 old_selection_end = mLastSelectionEnd; + + // Select word the cursor is over + while ((mCursorPos > 0) && isPartOfWord( wtext[mCursorPos-1] )) + { // Find the start of the word + mCursorPos--; + } + startSelection(); + + while ((mCursorPos < (S32)wtext.length()) && isPartOfWord( wtext[mCursorPos] ) ) + { // Find the end of the word + mCursorPos++; + } + mSelectionEnd = mCursorPos; + + // If nothing changed, then the word was already selected. Select the whole line. + doSelectAll = (old_selection_start == mSelectionStart) && + (old_selection_end == mSelectionEnd); + } + + if ( doSelectAll ) + { // Select everything + selectAll(); + } } // We don't want handleMouseUp() to "finish" the selection (and thereby @@ -496,6 +541,9 @@ BOOL LLLineEditor::handleMouseDown(S32 x, S32 y, MASK mask) } else { + mLastSelectionStart = -1; + mLastSelectionStart = -1; + setFocus( TRUE ); if (mask & MASK_SHIFT) @@ -539,6 +587,10 @@ BOOL LLLineEditor::handleMouseDown(S32 x, S32 y, MASK mask) } else { + // Save selection for word/line selecting on double-click + mLastSelectionStart = mSelectionStart; + mLastSelectionEnd = mSelectionEnd; + // Move cursor and deselect for regular click setCursorAtLocalPos( x ); deselect(); -- cgit v1.1