diff options
author | Timothy Flynn <trflynn89@pm.me> | 2023-01-03 08:35:06 -0500 |
---|---|---|
committer | Tim Flynn <trflynn89@pm.me> | 2023-01-03 11:50:18 -0500 |
commit | ee95cb37cd0964c9d8c52709280bbb35abf45d28 (patch) | |
tree | 2b99e7467f62ee87a2b7022eec632f42c47bdb69 /Userland/Libraries/LibGUI/FilePicker.cpp | |
parent | 0fe4f4fe53dde0486a12b57e918cf792a7ba15ec (diff) | |
download | serenity-ee95cb37cd0964c9d8c52709280bbb35abf45d28.zip |
LibGUI: Don't highlight extension text when saving files with FilePicker
By default, only highlight the base name of the file to-be-saved. When
the file includes an extension, it's useful to be able to just start
typing a file name without having to manually de-select the extension
(or having to rewrite the extension).
Diffstat (limited to 'Userland/Libraries/LibGUI/FilePicker.cpp')
-rw-r--r-- | Userland/Libraries/LibGUI/FilePicker.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/Userland/Libraries/LibGUI/FilePicker.cpp b/Userland/Libraries/LibGUI/FilePicker.cpp index 03169c2748..0998ecdf79 100644 --- a/Userland/Libraries/LibGUI/FilePicker.cpp +++ b/Userland/Libraries/LibGUI/FilePicker.cpp @@ -153,8 +153,17 @@ FilePicker::FilePicker(Window* parent_window, Mode mode, StringView filename, St m_filename_textbox = *widget.find_descendant_of_type_named<GUI::TextBox>("filename_textbox"); m_filename_textbox->set_focus(true); if (m_mode == Mode::Save) { + LexicalPath lexical_filename { filename }; m_filename_textbox->set_text(filename); - m_filename_textbox->select_all(); + + if (auto extension = lexical_filename.extension(); !extension.is_empty()) { + TextPosition start_of_filename { 0, 0 }; + TextPosition end_of_filename { 0, filename.length() - extension.length() - 1 }; + + m_filename_textbox->set_selection({ end_of_filename, start_of_filename }); + } else { + m_filename_textbox->select_all(); + } } m_filename_textbox->on_return_pressed = [&] { on_file_return(); |