summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gui/widgets/textfield.cpp10
-rw-r--r--src/gui/widgets/textfield.h7
-rw-r--r--src/gui/windows/chatwindow.cpp20
3 files changed, 34 insertions, 3 deletions
diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp
index aef977d80..1906c5c32 100644
--- a/src/gui/widgets/textfield.cpp
+++ b/src/gui/widgets/textfield.cpp
@@ -64,7 +64,8 @@ TextField::TextField(const Widget2 *restrict const widget,
mLastEventPaste(false),
mPadding(1),
mNumeric(false),
- mLoseFocusOnTab(loseFocusOnTab)
+ mLoseFocusOnTab(loseFocusOnTab),
+ mAllowSpecialActions(true)
{
setFrameSize(2);
mForegroundColor = getThemeColor(Theme::TEXTFIELD);
@@ -397,8 +398,11 @@ void TextField::handleCtrlKeys(const int action, bool &consumed)
}
case Input::KEY_GUI_B:
{
- moveCaretBack();
- consumed = true;
+ if (mAllowSpecialActions)
+ {
+ moveCaretBack();
+ consumed = true;
+ }
break;
}
case Input::KEY_GUI_F:
diff --git a/src/gui/widgets/textfield.h b/src/gui/widgets/textfield.h
index c459d34f7..4c1b4bffc 100644
--- a/src/gui/widgets/textfield.h
+++ b/src/gui/widgets/textfield.h
@@ -139,6 +139,12 @@ class TextField : public gcn::TextField,
void caretDeleteWord();
+ void setAllowSpecialActions(const bool b)
+ { mAllowSpecialActions = b; }
+
+ std::string getTextBeforeCaret() const
+ { return mText.substr(0, mCaretPosition); }
+
protected:
void drawCaret(Graphics* graphics, int x) override final;
@@ -166,6 +172,7 @@ class TextField : public gcn::TextField,
int mPadding;
bool mNumeric;
bool mLoseFocusOnTab;
+ bool mAllowSpecialActions;
};
#endif // GUI_WIDGETS_TEXTFIELD_H
diff --git a/src/gui/windows/chatwindow.cpp b/src/gui/windows/chatwindow.cpp
index 51d7d6db7..71915ab08 100644
--- a/src/gui/windows/chatwindow.cpp
+++ b/src/gui/windows/chatwindow.cpp
@@ -227,6 +227,7 @@ ChatWindow::ChatWindow():
mChatInput->setActionEventId("chatinput");
mChatInput->addActionListener(this);
+ mChatInput->setAllowSpecialActions(false);
mColorPicker->setActionEventId(ACTION_COLOR_PICKER);
mColorPicker->addActionListener(this);
@@ -934,6 +935,25 @@ void ChatWindow::keyPressed(KeyEvent &event)
ifKey(Input::KEY_GUI_F11, "\u2618")
ifKey(Input::KEY_GUI_F12, "\u2592")
+ if (inputManager.isActionActive(static_cast<int>(Input::KEY_GUI_CTRL)))
+ {
+ if (actionId == static_cast<int>(Input::KEY_GUI_B))
+ {
+ std::string inputText = mChatInput->getTextBeforeCaret();
+ toLower(inputText);
+ const size_t idx = inputText.rfind("##b");
+ if (idx == std::string::npos
+ || mChatInput->getTextBeforeCaret().substr(idx, 3) == "##b")
+ {
+ temp = "##B";
+ }
+ else
+ {
+ temp = "##b";
+ }
+ }
+ }
+
if (!temp.empty())
addInputText(temp, false);
}