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