-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patho.cpp
More file actions
44 lines (37 loc) · 1.92 KB
/
o.cpp
File metadata and controls
44 lines (37 loc) · 1.92 KB
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
43
44
#include "o.h"
std::string history_string;
html_output o;
extern "C" {
void EMSCRIPTEN_KEEPALIVE i(int chosen_link) //if clicked link, count up from 0 sequentially. keyboard press, count down from -1 sequentially, with neutral link = -link_count - 1.
{
int link_in_order;
if (chosen_link >= 0) link_in_order = chosen_link; //mouse clicked
else //chosen_link < 0, which means keyboard pressed
{
link_in_order = o.link_position.at(-chosen_link - 1); //either a non-negative number or -1
if (link_in_order == -1) return;
}
if (link_in_order >= o.links.size()) return; //referenced a link which doesn't exist
if (o.links.at(link_in_order).second == nullptr) return; //if the link is nullptr, it's a dummy link
//reconstruct the message without clickable links.
//we can't move the existing DOM message to the history section, because we'll have a nesting error if the </span> of the cmessage is in the middle of a paragraph.
//if we did move something, we could use http://stackoverflow.com/a/33724397, which moves them to a fragment before moving them again. operating on non-visible elements is faster.
for (int increm = 0; ; ++increm)
{
if (increm >= o.texts.size()) break;
if (o.suppress_history_section_number == increm)
{
history_string.append(o.texts.at(increm).substr(0, o.suppress_history_char_offset));
break;
}
history_string.append(o.texts.at(increm));
if (increm >= o.links.size()) break;
if (o.links.at(increm).second == nullptr) history_string.append("<a class=disabled_link>" + o.links.at(increm).first + "</a>");
else history_string.append(((increm == link_in_order) ? "<a class='history chosen_link_in_history'>" : "<a class=history>") + o.links.at(increm).first + "</a>");
}
history_string = convert_newlines_to_paragraph_tags(history_string);
std::function<void()> to_be_called = o.links.at(link_in_order).second;
o = html_output(); //reset it
to_be_called();
}
}