2020-01-18 11:38:21 +03:00
|
|
|
/*
|
2020-01-24 16:45:29 +03:00
|
|
|
* Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@serenityos.org>
|
2020-01-18 11:38:21 +03:00
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2019-10-02 22:44:05 +03:00
|
|
|
#include "History.h"
|
|
|
|
|
|
|
|
void History::push(const StringView& history_item)
|
|
|
|
{
|
|
|
|
m_items.shrink(m_current_history_item + 1);
|
|
|
|
m_items.append(history_item);
|
|
|
|
m_current_history_item++;
|
|
|
|
}
|
|
|
|
|
|
|
|
String History::current()
|
|
|
|
{
|
|
|
|
if (m_current_history_item == -1)
|
|
|
|
return {};
|
|
|
|
return m_items[m_current_history_item];
|
|
|
|
}
|
|
|
|
|
|
|
|
void History::go_back()
|
|
|
|
{
|
2021-02-23 22:42:32 +03:00
|
|
|
VERIFY(can_go_back());
|
2019-10-02 22:44:05 +03:00
|
|
|
m_current_history_item--;
|
|
|
|
}
|
|
|
|
|
|
|
|
void History::go_forward()
|
|
|
|
{
|
2021-02-23 22:42:32 +03:00
|
|
|
VERIFY(can_go_forward());
|
2019-10-02 22:44:05 +03:00
|
|
|
m_current_history_item++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void History::clear()
|
|
|
|
{
|
|
|
|
m_items = {};
|
|
|
|
m_current_history_item = -1;
|
|
|
|
}
|