Serenity Operating System
1/*
2 * Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@serenityos.org>
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#include "History.h"
8
9void History::push(StringView history_item)
10{
11 if (!m_items.is_empty() && m_items[m_current_history_item] == history_item)
12 return;
13
14 m_items.shrink(m_current_history_item + 1);
15 m_items.append(history_item);
16 m_current_history_item++;
17}
18
19DeprecatedString History::current()
20{
21 if (m_current_history_item == -1)
22 return {};
23 return m_items[m_current_history_item];
24}
25
26void History::go_back()
27{
28 VERIFY(can_go_back());
29 m_current_history_item--;
30}
31
32void History::go_forward()
33{
34 VERIFY(can_go_forward());
35 m_current_history_item++;
36}
37
38void History::clear()
39{
40 m_items = {};
41 m_current_history_item = -1;
42}