mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 21:37:35 +00:00
Ladybird+LibWebView: Move console history tracking to ConsoleClient
This will allow other chromes to make use of history in their console implementations.
This commit is contained in:
parent
ed315dd950
commit
204a6f9241
6 changed files with 69 additions and 34 deletions
|
@ -47,10 +47,44 @@ ConsoleClient::~ConsoleClient()
|
|||
m_content_web_view.on_received_console_messages = nullptr;
|
||||
}
|
||||
|
||||
void ConsoleClient::execute(StringView script)
|
||||
void ConsoleClient::execute(String script)
|
||||
{
|
||||
print_source(script);
|
||||
m_content_web_view.js_console_input(script);
|
||||
m_content_web_view.js_console_input(script.to_deprecated_string());
|
||||
|
||||
if (m_history.is_empty() || m_history.last() != script) {
|
||||
m_history.append(move(script));
|
||||
m_history_index = m_history.size();
|
||||
}
|
||||
}
|
||||
|
||||
Optional<String> ConsoleClient::previous_history_item()
|
||||
{
|
||||
if (m_history_index == 0)
|
||||
return {};
|
||||
|
||||
--m_history_index;
|
||||
return m_history.at(m_history_index);
|
||||
}
|
||||
|
||||
Optional<String> ConsoleClient::next_history_item()
|
||||
{
|
||||
if (m_history.is_empty())
|
||||
return {};
|
||||
|
||||
auto last_index = m_history.size() - 1;
|
||||
|
||||
if (m_history_index < last_index) {
|
||||
++m_history_index;
|
||||
return m_history.at(m_history_index);
|
||||
}
|
||||
|
||||
if (m_history_index == last_index) {
|
||||
++m_history_index;
|
||||
return String {};
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
void ConsoleClient::clear()
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <AK/DeprecatedString.h>
|
||||
#include <AK/Function.h>
|
||||
#include <AK/Span.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibWebView/Forward.h>
|
||||
|
@ -20,7 +21,10 @@ public:
|
|||
explicit ConsoleClient(ViewImplementation& content_web_view, ViewImplementation& console_web_view);
|
||||
~ConsoleClient();
|
||||
|
||||
void execute(StringView);
|
||||
void execute(String);
|
||||
|
||||
Optional<String> previous_history_item();
|
||||
Optional<String> next_history_item();
|
||||
|
||||
void clear();
|
||||
void reset();
|
||||
|
@ -50,6 +54,9 @@ private:
|
|||
};
|
||||
Vector<Group> m_group_stack;
|
||||
int m_next_group_id { 1 };
|
||||
|
||||
Vector<String> m_history;
|
||||
size_t m_history_index { 0 };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue