From 979d139af1866efdb7237c940783877170e82c1a Mon Sep 17 00:00:00 2001 From: Inusaito Sayori Date: Sun, 29 Sep 2013 19:14:56 -0400 Subject: [PATCH] Address Issue 352: Ctrl-Backspace in editable text fields --- indra/llui/lllineeditor.cpp | 39 ++++++++++++++++++++++++++++++++++++- indra/llui/lllineeditor.h | 1 + indra/llui/lltexteditor.cpp | 38 +++++++++++++++++++++++++++++++++++- indra/llui/lltexteditor.h | 1 + 4 files changed, 77 insertions(+), 2 deletions(-) diff --git a/indra/llui/lllineeditor.cpp b/indra/llui/lllineeditor.cpp index 15b387cbc..79ccb6469 100644 --- a/indra/llui/lllineeditor.cpp +++ b/indra/llui/lllineeditor.cpp @@ -860,6 +860,32 @@ void LLLineEditor::removeChar() } } +// Remove a word (set of characters up to next space/punctuation) from the text +void LLLineEditor::removeWord(bool prev) +{ + const U32 pos(getCursor()); + if (prev ? pos > 0 : static_cast(pos) < getLength()) + { + U32 new_pos(prev ? prevWordPos(pos) : nextWordPos(pos)); + if (new_pos == pos) // Other character we don't jump over + new_pos = prev ? prevWordPos(new_pos-1) : nextWordPos(new_pos+1); + + const U32 diff(labs(pos - new_pos)); + if (prev) + { + mText.erase(new_pos, diff); + setCursor(new_pos); + } + else + { + mText.erase(pos, diff); + } + } + else + { + reportBadKeystroke(); + } +} void LLLineEditor::addChar(const llwchar uni_char) { @@ -1318,7 +1344,10 @@ BOOL LLLineEditor::handleSpecialKey(KEY key, MASK mask) else if( 0 < getCursor() ) { - removeChar(); + if (mask == MASK_CONTROL) + removeWord(true); + else + removeChar(); } else { @@ -1328,6 +1357,14 @@ BOOL LLLineEditor::handleSpecialKey(KEY key, MASK mask) handled = TRUE; break; + case KEY_DELETE: + if (!mReadOnly && mask == MASK_CONTROL) + { + removeWord(false); + handled = true; + } + break; + case KEY_PAGE_UP: case KEY_HOME: if (!mIgnoreArrowKeys) diff --git a/indra/llui/lllineeditor.h b/indra/llui/lllineeditor.h index c665ad96c..bc6df16f3 100644 --- a/indra/llui/lllineeditor.h +++ b/indra/llui/lllineeditor.h @@ -266,6 +266,7 @@ private: void pasteHelper(bool is_primary); void removeChar(); + void removeWord(bool prev); void addChar(const llwchar c); void setCursorAtLocalPos(S32 local_mouse_x); S32 calculateCursorFromMouse(S32 local_mouse_x); diff --git a/indra/llui/lltexteditor.cpp b/indra/llui/lltexteditor.cpp index e6049f843..4a65879f8 100644 --- a/indra/llui/lltexteditor.cpp +++ b/indra/llui/lltexteditor.cpp @@ -1814,6 +1814,33 @@ void LLTextEditor::removeChar() } } +// Remove a word (set of characters up to next space/punctuation) from the text +void LLTextEditor::removeWord(bool prev) +{ + const U32 pos(mCursorPos); + if (prev ? pos > 0 : static_cast(pos) < getLength()) + { + U32 new_pos(prev ? prevWordPos(pos) : nextWordPos(pos)); + if (new_pos == pos) // Other character we don't jump over + new_pos = prev ? prevWordPos(new_pos-1) : nextWordPos(new_pos+1); + + const U32 diff(labs(pos - new_pos)); + if (prev) + { + remove(new_pos, diff, false); + setCursorPos(new_pos); + } + else + { + remove(pos, diff, false); + } + } + else + { + reportBadKeystroke(); + } +} + // Add a single character to the text S32 LLTextEditor::addChar(S32 pos, llwchar wc) { @@ -2447,7 +2474,10 @@ BOOL LLTextEditor::handleSpecialKey(const KEY key, const MASK mask, BOOL* return else if( 0 < mCursorPos ) { - removeCharOrTab(); + if (mask == MASK_CONTROL) + removeWord(true); + else + removeCharOrTab(); } else { @@ -2455,6 +2485,12 @@ BOOL LLTextEditor::handleSpecialKey(const KEY key, const MASK mask, BOOL* return } break; + case KEY_DELETE: + if (getEnabled() && mask == MASK_CONTROL) + { + removeWord(false); + } + break; case KEY_RETURN: if (mask == MASK_NONE) diff --git a/indra/llui/lltexteditor.h b/indra/llui/lltexteditor.h index 51300450d..6016b7e94 100644 --- a/indra/llui/lltexteditor.h +++ b/indra/llui/lltexteditor.h @@ -408,6 +408,7 @@ protected: S32 overwriteChar(S32 pos, llwchar wc); void removeChar(); S32 removeChar(S32 pos); + void removeWord(bool prev); S32 insert(const S32 pos, const LLWString &wstr, const BOOL group_with_next_op); S32 remove(const S32 pos, const S32 length, const BOOL group_with_next_op); S32 append(const LLWString &wstr, const BOOL group_with_next_op);