Details
-
Suggestion
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
5.12, 6.3
-
None
Description
Currently, when QTextEdit::echoMode is set to something other than QTextEdit::Normal then undo/redo actions are disabled to prevent potentially exposing passwords.
However, a common GUI use case, is to provide a "reveal" button which temporarily sets QTextEdit::echoMode to Normal. Currently, when switching to Normal, all of the undo/redo actions that were being blocked on the other echo modes are now suddenly available.
I would like to suggest, then whenever QTextEdit::echoMode is is changed to Normal, from any of the other modes, the undo/redo buffer is reset.
This could possibly be as easy as:
--- qwidgetlinecontrol_p.h.old 2022-08-06 10:12:06.359833943 +1000 +++ qwidgetlinecontrol_p.h.new 2022-08-06 10:19:01.382631373 +1000 @@ -242,6 +242,10 @@ uint echoMode() const { return m_echoMode; } void setEchoMode(uint mode) { + // If switching from one of the hidden modes to Normal, clear the undo history. + if ((mode == QLineEdit::Normal) && (m_echoMode != QLineEdit::Normal)) + clearUndo(); + cancelPasswordEchoTimer(); m_echoMode = mode; m_passwordEchoEditing = false;
Note, the condition check is there because I reckon it makes sense to not clear the history if setting to {{Normal, when already Normal. The alternative would be an early no-op check, like this:
--- qwidgetlinecontrol_p.h.old 2022-08-06 10:12:06.359833943 +1000 +++ qwidgetlinecontrol_p.h.new 2022-08-06 10:22:05.320326582 +1000 @@ -242,6 +242,8 @@ uint echoMode() const { return m_echoMode; } void setEchoMode(uint mode) { + if (m_echoMode == mode) return; + cancelPasswordEchoTimer(); m_echoMode = mode; m_passwordEchoEditing = false; @@ -252,6 +254,10 @@ if (m_echoMode != QLineEdit::Normal) m_text.reserve(30); + // If switching to a hide-echo mode, clear the undo history. + if (m_echoMode == QLineEdit::Normal) + clearUndo(); + updateDisplayText(); }
But that could have unintended side-effects (callers relying on repeatedly setting the same mode have some other update effects).