Libraryless. Click here for Pure Java version (10141L/67K/235K).
1 | !7 |
2 | |
3 | !include #1006440 // Concepts |
4 | |
5 | static double maxSleepTime = 2; // compress pauses to this time (seconds) |
6 | |
7 | static Session session; |
8 | static JTextArea ta; |
9 | static int caretPos; // Reorder caret moves & edits |
10 | |
11 | p { |
12 | loadConceptsFrom(#1006438); |
13 | print("Sessions: " + collectField('id, list(Session))); |
14 | session = latest(Session); |
15 | if (session == null) { |
16 | print("Editor has not been run yet"); |
17 | ret; |
18 | } |
19 | |
20 | L<Event> events = sortConceptsByID(findBackRefs(Event, session)); |
21 | print("Using session " + session.id + " with " + n(events, "events")); |
22 | ta = showText(""); |
23 | S text = ""; |
24 | long time = session.created; |
25 | setFrameTitle(ta, "Replaying"); |
26 | for (Event e : events) { |
27 | print(sfu(e)); |
28 | long sleepTime = min(toMS(maxSleepTime), e.created-time); |
29 | time = e.created; |
30 | sleep(sleepTime); |
31 | if (e << EChange) { |
32 | text = replayEdit(e/EChange, text); |
33 | setText(ta, text); |
34 | if (caretPos != 0 && setCaretIfPossible(ta, caretPos)) |
35 | caretPos = 0; |
36 | } else if (e << ECaret) { |
37 | int pos = e/ECaret.pos; |
38 | if (!setCaretIfPossible(ta, pos)) |
39 | caretPos = pos; |
40 | } else |
41 | print("Ignoring unknown event type: " + e); |
42 | } |
43 | setFrameTitle(ta, "Replay Done"); |
44 | } |
Began life as a copy of #1006438
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, sawdedvomwva, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1006441 |
Snippet name: | WORKS: Replay Last Session From Auto-Saving Text Editor |
Eternal ID of this version: | #1006441/7 |
Text MD5: | b1119bb8755e676d54fed67ae913ba54 |
Transpilation MD5: | 2cfa2f33edc8c1cbdf687f4226915ebc |
Author: | stefan |
Category: | javax / tools |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-03-25 16:30:36 |
Source code size: | 1249 bytes / 44 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 738 / 945 |
Version history: | 6 change(s) |
Referenced in: | [show references] |