1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 02:47:34 +00:00

LibGUI: Ensure that edit actions are disabled for password boxes

This ensures that the user can't copy/cut text from password boxes which
would reveal the password. It also makes sure that the undo/redo actions
stay disabled because it's difficult to reason about what these do
exactly without being able to see the result.
This commit is contained in:
Gunnar Beutner 2021-08-02 11:10:56 +02:00 committed by Linus Groh
parent 9179d01915
commit 17505ea5d9
3 changed files with 18 additions and 7 deletions

View file

@ -77,8 +77,7 @@ PasswordBox::PasswordBox()
: TextBox() : TextBox()
{ {
set_substitution_code_point('*'); set_substitution_code_point('*');
undo_action().set_enabled(false); set_text_is_secret(true);
redo_action().set_enabled(false);
} }
} }

View file

@ -1478,7 +1478,7 @@ void TextEditor::set_mode(const Mode mode)
m_mode = mode; m_mode = mode;
switch (mode) { switch (mode) {
case Editable: case Editable:
m_cut_action->set_enabled(has_selection()); m_cut_action->set_enabled(has_selection() && !text_is_secret());
m_delete_action->set_enabled(true); m_delete_action->set_enabled(true);
m_paste_action->set_enabled(true); m_paste_action->set_enabled(true);
set_accepts_emoji_input(true); set_accepts_emoji_input(true);
@ -1502,8 +1502,8 @@ void TextEditor::set_mode(const Mode mode)
void TextEditor::did_update_selection() void TextEditor::did_update_selection()
{ {
m_cut_action->set_enabled(is_editable() && has_selection()); m_cut_action->set_enabled(is_editable() && has_selection() && !text_is_secret());
m_copy_action->set_enabled(has_selection()); m_copy_action->set_enabled(has_selection() && !text_is_secret());
if (on_selection_change) if (on_selection_change)
on_selection_change(); on_selection_change();
if (is_wrapping_enabled()) { if (is_wrapping_enabled()) {
@ -1774,8 +1774,8 @@ void TextEditor::document_did_update_undo_stack()
return builder.to_string(); return builder.to_string();
}; };
m_undo_action->set_enabled(can_undo()); m_undo_action->set_enabled(can_undo() && !text_is_secret());
m_redo_action->set_enabled(can_redo()); m_redo_action->set_enabled(can_redo() && !text_is_secret());
m_undo_action->set_text(make_action_text("&Undo", document().undo_stack().undo_action_text())); m_undo_action->set_text(make_action_text("&Undo", document().undo_stack().undo_action_text()));
m_redo_action->set_text(make_action_text("&Redo", document().undo_stack().redo_action_text())); m_redo_action->set_text(make_action_text("&Redo", document().undo_stack().redo_action_text()));
@ -1980,4 +1980,11 @@ void TextEditor::redo()
document().redo(); document().redo();
} }
void TextEditor::set_text_is_secret(bool text_is_secret)
{
m_text_is_secret = text_is_secret;
document_did_update_undo_stack();
did_update_selection();
}
} }

View file

@ -203,6 +203,9 @@ public:
void delete_text_range(TextRange); void delete_text_range(TextRange);
bool text_is_secret() const { return m_text_is_secret; }
void set_text_is_secret(bool text_is_secret);
protected: protected:
explicit TextEditor(Type = Type::MultiLine); explicit TextEditor(Type = Type::MultiLine);
@ -387,6 +390,8 @@ private:
Gfx::IntPoint m_last_mousemove_position; Gfx::IntPoint m_last_mousemove_position;
RefPtr<Gfx::Bitmap> m_icon; RefPtr<Gfx::Bitmap> m_icon;
bool m_text_is_secret { false };
}; };
} }