Browse Source

Console Lose First Responder

Modified the console text edit box so that it doesn't run its contents when it loses focus. Typically the console only loses focus after it's closed. It's not good for it to be running code unexpectedly when you can't see it.
Peter Robinson 3 years ago
parent
commit
7e7cf0e5aa
2 changed files with 20 additions and 0 deletions
  1. 19 0
      engine/source/gui/guiConsoleEditCtrl.cc
  2. 1 0
      engine/source/gui/guiConsoleEditCtrl.h

+ 19 - 0
engine/source/gui/guiConsoleEditCtrl.cc

@@ -177,4 +177,23 @@ bool GuiConsoleEditCtrl::handleDelete()
     return result;
 }
 
+void GuiConsoleEditCtrl::onLoseFirstResponder()
+{
+    Platform::disableKeyboardTranslation();
+
+    if (isMethod("onLoseFirstResponder"))
+        Con::executef(this, 2, "onLoseFirstResponder");
+
+    mSelector.setFirstResponder(false);
+    mTextOffsetY = 0;
+    mScrollVelocity = 0;
+    if (!mTextWrap && mTextBlockList.size() > 0)
+    {
+        mTextBlockList.front().resetScroll();
+    }
+
+    // Redraw the control:
+    setUpdate();
+}
+
 

+ 1 - 0
engine/source/gui/guiConsoleEditCtrl.h

@@ -72,6 +72,7 @@ public:
    static void initPersistFields();
 
    bool onKeyDown(const GuiEvent &event);
+   void onLoseFirstResponder();
 };
 
 #endif //_GUI_TEXTEDIT_CTRL_H