Skip to content

Commit

Permalink
Add support for selecting all text in editbox via CTRL+A (#2238)
Browse files Browse the repository at this point in the history
  • Loading branch information
rh101 authored Nov 22, 2024
1 parent 502961d commit 449d921
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
14 changes: 14 additions & 0 deletions core/ui/UIEditBox/UIEditBoxImpl-win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ EditBoxImpl* __createSystemEditBox(EditBox* pEditBox)

EditBoxImplWin::EditBoxImplWin(EditBox* pEditText)
: EditBoxImplCommon(pEditText)
, _hotKeyIdCtrlA(0)
, _hwndEdit(NULL)
, _changedTextManually(false)
, _hasFocus(false)
Expand Down Expand Up @@ -100,6 +101,10 @@ void EditBoxImplWin::cleanupEditCtrl()
{
if (_hwndEdit)
{
UnregisterHotKey(_hwndEdit, _hotKeyIdCtrlA);
GlobalDeleteAtom(_hotKeyIdCtrlA);
_hotKeyIdCtrlA = 0;

SetWindowLongPtrW(_hwndEdit, GWLP_WNDPROC, (LONG_PTR)_prevWndProc);
::DestroyWindow(_hwndEdit);
_hasFocus = false;
Expand Down Expand Up @@ -132,6 +137,9 @@ void EditBoxImplWin::createEditCtrl(bool singleLine)
s_previousFocusWnd = s_hwndCocos;
this->setNativeFont(this->getNativeDefaultFontName(), this->_fontSize);
this->setNativeText(this->_text.c_str());

_hotKeyIdCtrlA = GlobalAddAtom(L"CTRL+A");
RegisterHotKey(_hwndEdit, _hotKeyIdCtrlA, MOD_CONTROL | MOD_NOREPEAT, 'A');
}
}

Expand Down Expand Up @@ -361,6 +369,12 @@ void EditBoxImplWin::_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa
this->editBoxEditingDidEnd(this->getText(), _endAction);
}
break;
case WM_HOTKEY:
if (wParam == (WPARAM)_hotKeyIdCtrlA)
{
::SendMessageW(_hwndEdit, EM_SETSEL, 0, -1);
}
break;
default:
break;
}
Expand Down
2 changes: 2 additions & 0 deletions core/ui/UIEditBox/UIEditBoxImpl-win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class AX_GUI_DLL EditBoxImplWin : public EditBoxImplCommon
void _WindowProc(HWND, UINT, WPARAM, LPARAM);

WNDPROC _prevWndProc;
ATOM _hotKeyIdCtrlA;

static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
static LRESULT CALLBACK hookGLFWWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

Expand Down

0 comments on commit 449d921

Please sign in to comment.