From 0656a8d40bfa670183454abe5bc6478beb061768 Mon Sep 17 00:00:00 2001 From: zuu Date: Mon, 10 Sep 2012 18:45:29 +0000 Subject: (svn r24520) -Feature [FS#5203]: Ctrl + Arrow keys to move entire words in text edit boxes (sbr) --- src/misc_gui.cpp | 1 + src/textbuf.cpp | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 7dbb84ad0..7d21ad19e 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -744,6 +744,7 @@ HandleEditBoxResult QueryString::HandleEditBoxKey(Window *w, int wid, uint16 key break; case WKC_LEFT: case WKC_RIGHT: case WKC_END: case WKC_HOME: + case WKC_CTRL | WKC_LEFT: case WKC_CTRL | WKC_RIGHT: if (this->text.MovePos(keycode)) w->SetWidgetDirty(wid); break; diff --git a/src/textbuf.cpp b/src/textbuf.cpp index 673e77e49..d9069755a 100644 --- a/src/textbuf.cpp +++ b/src/textbuf.cpp @@ -224,7 +224,7 @@ WChar Textbuf::MoveCaretRight() /** * Handle text navigation with arrow keys left/right. * This defines where the caret will blink and the next characer interaction will occur - * @param navmode Direction in which navigation occurs WKC_LEFT, WKC_RIGHT, WKC_END, WKC_HOME + * @param navmode Direction in which navigation occurs (WKC_CTRL |) WKC_LEFT, (WKC_CTRL |) WKC_RIGHT, WKC_END, WKC_HOME * @return Return true on successful change of Textbuf, or false otherwise */ bool Textbuf::MovePos(int navmode) @@ -237,6 +237,26 @@ bool Textbuf::MovePos(int navmode) } break; + case WKC_CTRL | WKC_LEFT: { + if (!this->CanMoveCaretLeft()) break; + + /* Unconditionally move one char to the left. */ + WChar c = this->MoveCaretLeft(); + /* Consume left whitespaces. */ + while (IsWhitespace(c)) { + if (!this->CanMoveCaretLeft()) return true; + c = this->MoveCaretLeft(); + } + /* Consume left word. */ + while (!IsWhitespace(c)) { + if (!this->CanMoveCaretLeft()) return true; + c = this->MoveCaretLeft(); + } + /* Place caret at the begining of the left word. */ + this->MoveCaretRight(); + return true; + } + case WKC_RIGHT: if (this->CanMoveCaretRight()) { this->MoveCaretRight(); @@ -244,6 +264,24 @@ bool Textbuf::MovePos(int navmode) } break; + case WKC_CTRL | WKC_RIGHT: { + if (!this->CanMoveCaretRight()) break; + + /* Unconditionally move one char to the right. */ + WChar c = this->MoveCaretRight(); + /* Continue to consume current word. */ + while (!IsWhitespace(c)) { + if (!this->CanMoveCaretRight()) return true; + c = this->MoveCaretRight(); + } + /* Consume right whitespaces. */ + while (IsWhitespace(c)) { + if (!this->CanMoveCaretRight()) return true; + c = this->MoveCaretRight(); + } + return true; + } + case WKC_HOME: this->caretpos = 0; this->caretxoffs = 0; -- cgit v1.2.3-70-g09d2