diff options
author | FalseHonesty <thefalsehonesty@gmail.com> | 2020-05-26 22:18:25 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-27 20:04:52 +0200 |
commit | 08e29072107a250e563d8b12729a1cbd276b5d96 (patch) | |
tree | 3810fcefea1c82cf2778eb81454e068448d977e0 /Applications | |
parent | 139dbfd5b508bacf7494ba2318eae80f96dc5e76 (diff) | |
download | serenity-08e29072107a250e563d8b12729a1cbd276b5d96.zip |
Browser: Add console history to re-send old commands
The console has now enabled history in its input text box. Pretty
nice to not have to retype things all the time :^)
Diffstat (limited to 'Applications')
-rw-r--r-- | Applications/Browser/ConsoleWidget.cpp | 37 | ||||
-rw-r--r-- | Applications/Browser/ConsoleWidget.h | 7 |
2 files changed, 24 insertions, 20 deletions
diff --git a/Applications/Browser/ConsoleWidget.cpp b/Applications/Browser/ConsoleWidget.cpp index 9737b744bc..13626b65ad 100644 --- a/Applications/Browser/ConsoleWidget.cpp +++ b/Applications/Browser/ConsoleWidget.cpp @@ -54,26 +54,29 @@ ConsoleWidget::ConsoleWidget() html_element->append_child(head_element); auto body_element = create_element(base_document, "body"); html_element->append_child(body_element); - m_console_output_container = body_element; + m_output_container = body_element; - m_console_output_view = add<Web::HtmlView>(); - m_console_output_view->set_document(base_document); + m_output_view = add<Web::HtmlView>(); + m_output_view->set_document(base_document); - m_console_input = add<GUI::TextBox>(); - m_console_input->set_syntax_highlighter(make<GUI::JSSyntaxHighlighter>()); - m_console_input->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); - m_console_input->set_preferred_size(0, 22); + m_input = add<GUI::TextBox>(); + m_input->set_syntax_highlighter(make<GUI::JSSyntaxHighlighter>()); + m_input->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); + m_input->set_preferred_size(0, 22); // FIXME: Syntax Highlighting breaks the cursor's position on non fixed-width fonts. - m_console_input->set_font(Gfx::Font::default_fixed_width_font()); + m_input->set_font(Gfx::Font::default_fixed_width_font()); + m_input->set_history_enabled(true); - m_console_input->on_return_pressed = [this] { - auto js_source = m_console_input->text(); + m_input->on_return_pressed = [this] { + auto js_source = m_input->text(); // FIXME: An is_blank check to check if there is only whitespace would probably be preferable. if (js_source.is_empty()) return; - m_console_input->clear(); + m_input->add_current_text_to_history(); + m_input->clear(); + print_source_line(js_source); auto parser = JS::Parser(JS::Lexer(js_source)); @@ -133,19 +136,19 @@ void ConsoleWidget::print_source_line(const StringView& source) void ConsoleWidget::print_html(const StringView& line) { - auto paragraph = create_element(m_console_output_container->document(), "p"); + auto paragraph = create_element(m_output_container->document(), "p"); paragraph->set_inner_html(line); - m_console_output_container->append_child(paragraph); - m_console_output_container->document().invalidate_layout(); - m_console_output_container->document().update_layout(); + m_output_container->append_child(paragraph); + m_output_container->document().invalidate_layout(); + m_output_container->document().update_layout(); - m_console_output_view->scroll_to_bottom(); + m_output_view->scroll_to_bottom(); } void ConsoleWidget::clear_output() { - const_cast<Web::HTMLBodyElement*>(m_console_output_view->document()->body())->remove_all_children(); + const_cast<Web::HTMLBodyElement*>(m_output_view->document()->body())->remove_all_children(); } } diff --git a/Applications/Browser/ConsoleWidget.h b/Applications/Browser/ConsoleWidget.h index 7c463a5051..9f5f27be2a 100644 --- a/Applications/Browser/ConsoleWidget.h +++ b/Applications/Browser/ConsoleWidget.h @@ -26,6 +26,7 @@ #pragma once #include "BrowserConsoleClient.h" +#include "History.h" #include <LibGUI/Widget.h> #include <LibJS/Forward.h> #include <LibWeb/HtmlView.h> @@ -45,9 +46,9 @@ public: private: ConsoleWidget(); - RefPtr<GUI::TextBox> m_console_input; - RefPtr<Web::HtmlView> m_console_output_view; - RefPtr<Web::Element> m_console_output_container; + RefPtr<GUI::TextBox> m_input; + RefPtr<Web::HtmlView> m_output_view; + RefPtr<Web::Element> m_output_container; WeakPtr<JS::Interpreter> m_interpreter; OwnPtr<BrowserConsoleClient> m_console_client; }; |