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"
|
|
|
|
|
2021-11-11 02:55:02 +03:00
|
|
|
void History::push(StringView history_item)
|
2019-10-02 22:44:05 +03:00
|
|
|
{
|
2021-07-20 01:48:26 +03:00
|
|
|
if (!m_items.is_empty() && m_items[m_current_history_item] == history_item)
|
|
|
|
return;
|
|
|
|
|
2019-10-02 22:44:05 +03:00
|
|
|
m_items.shrink(m_current_history_item + 1);
|
|
|
|
m_items.append(history_item);
|
|
|
|
m_current_history_item++;
|
|
|
|
}
|
|
|
|
|
2022-12-04 21:02:33 +03:00
|
|
|
DeprecatedString History::current()
|
2019-10-02 22:44:05 +03:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|