mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:37:35 +00:00
TableView: Do not select input on keydown
In the Spreadsheet app, selecting a cell and typing something (like "1") would create an empty editing delegate, set "1" as its value and immediately select the entire contents of the text box. If your goal was to type "123", that "1" was selected and will be replaced by "23". This changes the behavior of TableView to not select the editing delegate's contents if its creation was a result of a keydown event.
This commit is contained in:
parent
bc5d50e78b
commit
0f35912bd7
4 changed files with 23 additions and 13 deletions
|
@ -14,6 +14,11 @@ namespace GUI {
|
|||
|
||||
class ModelEditingDelegate {
|
||||
public:
|
||||
enum SelectionBehavior {
|
||||
DoNotSelect,
|
||||
SelectAll,
|
||||
};
|
||||
|
||||
virtual ~ModelEditingDelegate() { }
|
||||
|
||||
void bind(Model& model, const ModelIndex& index)
|
||||
|
@ -32,7 +37,7 @@ public:
|
|||
Function<void()> on_rollback;
|
||||
|
||||
virtual Variant value() const = 0;
|
||||
virtual void set_value(const Variant&) = 0;
|
||||
virtual void set_value(Variant const&, SelectionBehavior selection_behavior = SelectionBehavior::SelectAll) = 0;
|
||||
|
||||
virtual void will_begin_editing() { }
|
||||
|
||||
|
@ -76,11 +81,12 @@ public:
|
|||
return textbox;
|
||||
}
|
||||
virtual Variant value() const override { return static_cast<const TextBox*>(widget())->text(); }
|
||||
virtual void set_value(const Variant& value) override
|
||||
virtual void set_value(Variant const& value, SelectionBehavior selection_behavior) override
|
||||
{
|
||||
auto& textbox = static_cast<TextBox&>(*widget());
|
||||
textbox.set_text(value.to_string());
|
||||
textbox.select_all();
|
||||
if (selection_behavior == SelectionBehavior::SelectAll)
|
||||
textbox.select_all();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue