From c687bf7ed48dc190eba9d21f1896d6d932758abb Mon Sep 17 00:00:00 2001 From: SuntrustDev <19979417+SunTrustDev@users.noreply.github.com> Date: Tue, 17 Feb 2026 21:30:15 +0100 Subject: [PATCH] Prevent Password fields from being cut/copied --- src/UserInterface/PythonIME.cpp | 25 +++++++++++++++++++++++-- src/UserInterface/PythonIME.h | 5 +++++ src/UserInterface/PythonIMEModule.cpp | 17 +++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/UserInterface/PythonIME.cpp b/src/UserInterface/PythonIME.cpp index 9ec2d21..3e29dee 100644 --- a/src/UserInterface/PythonIME.cpp +++ b/src/UserInterface/PythonIME.cpp @@ -2,6 +2,8 @@ #include "PythonIME.h" #include "AbstractApplication.h" +bool CPythonIME::ms_bSecretMode = false; + CPythonIME::CPythonIME() : CIME() { @@ -99,7 +101,10 @@ bool CPythonIME::OnWM_CHAR(WPARAM wParam, LPARAM lParam) case 0x03: // Ctrl+C if (ms_bCaptureInput) { - CopySelectionToClipboard(); + if (!ms_bSecretMode) + { + CopySelectionToClipboard(); + } return true; } return false; @@ -184,12 +189,18 @@ void CPythonIME::DeleteSelection() void CPythonIME::CopySelectionToClipboard() { + if (ms_bSecretMode) + return; + CIME::CopySelectionToClipboard(ms_hWnd); } void CPythonIME::CutSelection() { - CIME::CopySelectionToClipboard(ms_hWnd); + if (!ms_bSecretMode) + { + CIME::CopySelectionToClipboard(ms_hWnd); + } CIME::DeleteSelection(); } @@ -197,3 +208,13 @@ void CPythonIME::PasteTextFromClipBoard() { CIME::PasteTextFromClipBoard(); } + +void CPythonIME::SetSecretMode(bool bSecret) +{ + ms_bSecretMode = bSecret; +} + +bool CPythonIME::IsSecretMode() +{ + return ms_bSecretMode; +} diff --git a/src/UserInterface/PythonIME.h b/src/UserInterface/PythonIME.h index d5e2e31..50c0a52 100644 --- a/src/UserInterface/PythonIME.h +++ b/src/UserInterface/PythonIME.h @@ -27,6 +27,9 @@ public: void Create(HWND hWnd); + static void SetSecretMode(bool bSecret); + static bool IsSecretMode(); + protected: virtual void OnTab(); virtual void OnReturn(); @@ -39,4 +42,6 @@ protected: virtual void OnOpenReadingWnd(); virtual void OnCloseReadingWnd(); +private: + static bool ms_bSecretMode; }; diff --git a/src/UserInterface/PythonIMEModule.cpp b/src/UserInterface/PythonIMEModule.cpp index 65533e4..591a28d 100644 --- a/src/UserInterface/PythonIMEModule.cpp +++ b/src/UserInterface/PythonIMEModule.cpp @@ -251,6 +251,21 @@ PyObject* imePasteReturn(PyObject * poSelf, PyObject * poArgs) return Py_BuildNone(); } +PyObject* imeSetSecretMode(PyObject * poSelf, PyObject * poArgs) +{ + int iFlag; + if (!PyTuple_GetInteger(poArgs, 0, &iFlag)) + return Py_BuildException(); + + CPythonIME::SetSecretMode(iFlag != 0); + return Py_BuildNone(); +} + +PyObject* imeIsSecretMode(PyObject * poSelf, PyObject * poArgs) +{ + return Py_BuildValue("i", CPythonIME::IsSecretMode() ? 1 : 0); +} + void initime() { static PyMethodDef s_methods[] = @@ -293,6 +308,8 @@ void initime() { "CutSelection", imeCutSelection, METH_VARARGS }, { "CopySelection", imeCopySelectionToClipboard,METH_VARARGS }, { "EnablePaste", imeEnablePaste, METH_VARARGS }, + { "SetSecretMode", imeSetSecretMode, METH_VARARGS }, + { "IsSecretMode", imeIsSecretMode, METH_VARARGS }, { NULL, NULL, NULL }, };