summaryrefslogtreecommitdiff
path: root/Userland/Applications/Help/History.cpp
blob: d3354255d28c971807a9bb2fabe6e12c6423c993 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
 * Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include "History.h"

void History::push(const StringView& history_item)
{
    if (!m_items.is_empty() && m_items[m_current_history_item] == history_item)
        return;

    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()
{
    VERIFY(can_go_back());
    m_current_history_item--;
}

void History::go_forward()
{
    VERIFY(can_go_forward());
    m_current_history_item++;
}

void History::clear()
{
    m_items = {};
    m_current_history_item = -1;
}