offline-tex-editor 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- offline_tex_editor/__init__.py +2 -0
- offline_tex_editor/__main__.py +3 -0
- offline_tex_editor/gitapi.py +250 -0
- offline_tex_editor/index.html +132 -0
- offline_tex_editor/latexlog.py +205 -0
- offline_tex_editor/project.py +403 -0
- offline_tex_editor/server.py +923 -0
- offline_tex_editor/static/app.css +231 -0
- offline_tex_editor/static/app.js +72 -0
- offline_tex_editor/static/compile.js +83 -0
- offline_tex_editor/static/complete.js +159 -0
- offline_tex_editor/static/diffview.js +72 -0
- offline_tex_editor/static/editor.js +230 -0
- offline_tex_editor/static/files.js +181 -0
- offline_tex_editor/static/git.js +120 -0
- offline_tex_editor/static/package.json +5 -0
- offline_tex_editor/static/panels.js +83 -0
- offline_tex_editor/static/pdfview.js +254 -0
- offline_tex_editor/static/textindex.js +45 -0
- offline_tex_editor/static/tools.js +72 -0
- offline_tex_editor/static/util.js +57 -0
- offline_tex_editor/vendor/README.md +29 -0
- offline_tex_editor/vendor/codemirror/LICENSE +21 -0
- offline_tex_editor/vendor/codemirror/addon/dialog/dialog.min.css +1 -0
- offline_tex_editor/vendor/codemirror/addon/dialog/dialog.min.js +1 -0
- offline_tex_editor/vendor/codemirror/addon/edit/matchbrackets.min.js +1 -0
- offline_tex_editor/vendor/codemirror/addon/search/jump-to-line.min.js +1 -0
- offline_tex_editor/vendor/codemirror/addon/search/search.min.js +1 -0
- offline_tex_editor/vendor/codemirror/addon/search/searchcursor.min.js +1 -0
- offline_tex_editor/vendor/codemirror/addon/selection/active-line.min.js +1 -0
- offline_tex_editor/vendor/codemirror/codemirror.min.css +1 -0
- offline_tex_editor/vendor/codemirror/codemirror.min.js +1 -0
- offline_tex_editor/vendor/codemirror/mode/markdown/markdown.min.js +1 -0
- offline_tex_editor/vendor/codemirror/mode/python/python.min.js +1 -0
- offline_tex_editor/vendor/codemirror/mode/stex/stex.min.js +1 -0
- offline_tex_editor/vendor/pdfjs/LICENSE +177 -0
- offline_tex_editor/vendor/pdfjs/pdf.min.mjs +21 -0
- offline_tex_editor/vendor/pdfjs/pdf.worker.min.mjs +21 -0
- offline_tex_editor-0.2.0.dist-info/METADATA +193 -0
- offline_tex_editor-0.2.0.dist-info/RECORD +44 -0
- offline_tex_editor-0.2.0.dist-info/WHEEL +5 -0
- offline_tex_editor-0.2.0.dist-info/entry_points.txt +2 -0
- offline_tex_editor-0.2.0.dist-info/licenses/LICENSE +21 -0
- offline_tex_editor-0.2.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--bg: #f6f7f9; --panel: #ffffff; --ink: #1d2433; --muted: #667085; --line: #e3e6eb;
|
|
3
|
+
--accent: #2f6f4f; --accent-ink: #ffffff; --err: #b42318; --warn: #b54708; --ok: #2f6f4f; --info: #3b6fb6;
|
|
4
|
+
--sel: #e8f1ec; --pdfbg: #e9ebef; --hl: rgba(255, 196, 0, .35); --ins: #1a7f37; --rem: #cf222e;
|
|
5
|
+
--ours: rgba(46, 160, 67, .12); --theirs: rgba(59, 111, 182, .14); --shadow: 0 4px 16px rgba(0, 0, 0, .16);
|
|
6
|
+
}
|
|
7
|
+
@media (prefers-color-scheme: dark) {
|
|
8
|
+
:root:not([data-theme="light"]) {
|
|
9
|
+
--bg: #14171c; --panel: #1b1f26; --ink: #e6e8ec; --muted: #98a2b3; --line: #2b313b;
|
|
10
|
+
--accent: #5fb88a; --accent-ink: #0d1512; --err: #f97066; --warn: #fdb022; --ok: #5fb88a; --info: #84adea;
|
|
11
|
+
--sel: #23332b; --pdfbg: #0f1216; --hl: rgba(255, 196, 0, .30); --ins: #56d364; --rem: #ff7b72;
|
|
12
|
+
--ours: rgba(86, 211, 100, .12); --theirs: rgba(132, 173, 234, .14); --shadow: 0 4px 16px rgba(0, 0, 0, .5);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
:root[data-theme="dark"] {
|
|
16
|
+
--bg: #14171c; --panel: #1b1f26; --ink: #e6e8ec; --muted: #98a2b3; --line: #2b313b;
|
|
17
|
+
--accent: #5fb88a; --accent-ink: #0d1512; --err: #f97066; --warn: #fdb022; --ok: #5fb88a; --info: #84adea;
|
|
18
|
+
--sel: #23332b; --pdfbg: #0f1216; --hl: rgba(255, 196, 0, .30); --ins: #56d364; --rem: #ff7b72;
|
|
19
|
+
--ours: rgba(86, 211, 100, .12); --theirs: rgba(132, 173, 234, .14); --shadow: 0 4px 16px rgba(0, 0, 0, .5);
|
|
20
|
+
}
|
|
21
|
+
* { box-sizing: border-box; }
|
|
22
|
+
html, body { height: 100%; margin: 0; }
|
|
23
|
+
body { background: var(--bg); color: var(--ink); font: 13px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
|
|
24
|
+
display: grid; grid-template-rows: auto 1fr auto; }
|
|
25
|
+
[hidden] { display: none !important; }
|
|
26
|
+
button, .chk, select { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line);
|
|
27
|
+
border-radius: 6px; padding: 4px 10px; cursor: pointer; }
|
|
28
|
+
button:hover { border-color: var(--muted); }
|
|
29
|
+
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
|
|
30
|
+
button.danger { background: var(--err); color: #fff; border-color: var(--err); font-weight: 600; }
|
|
31
|
+
button.link { border: 0; background: none; padding: 0 4px; color: var(--muted); }
|
|
32
|
+
button.link:hover { color: var(--ink); }
|
|
33
|
+
button:disabled { opacity: .55; cursor: default; }
|
|
34
|
+
input[type="text"], input:not([type]), textarea { font: inherit; color: var(--ink); background: var(--bg);
|
|
35
|
+
border: 1px solid var(--line); border-radius: 6px; padding: 4px 7px; }
|
|
36
|
+
.chk { display: inline-flex; gap: 5px; align-items: center; }
|
|
37
|
+
.muted { color: var(--muted); }
|
|
38
|
+
.spacer { flex: 1; }
|
|
39
|
+
.row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
|
|
40
|
+
|
|
41
|
+
header { display: flex; align-items: center; gap: 6px; padding: 6px 10px; background: var(--panel);
|
|
42
|
+
border-bottom: 1px solid var(--line); flex-wrap: wrap; }
|
|
43
|
+
header .title { font-weight: 600; margin-right: 4px; }
|
|
44
|
+
#mainDoc { font-family: ui-monospace, monospace; font-size: 12px; }
|
|
45
|
+
#pageNav { display: inline-flex; gap: 4px; align-items: center; color: var(--muted); font-variant-numeric: tabular-nums; }
|
|
46
|
+
#pageNum { width: 3.2em; padding: 3px 4px; text-align: center; background: var(--panel); }
|
|
47
|
+
#status { min-width: 160px; max-width: 420px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
48
|
+
#status.ok { color: var(--ok); } #status.err { color: var(--err); } #status.run { color: var(--warn); }
|
|
49
|
+
|
|
50
|
+
main { display: grid; grid-template-columns: 240px 1fr 6px 1fr; min-height: 0; }
|
|
51
|
+
#side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
|
|
52
|
+
#sideTabs { display: flex; gap: 3px; padding: 8px 6px 0; }
|
|
53
|
+
#sideTabs button { flex: 1; padding: 4px 2px; font-size: 12px; }
|
|
54
|
+
#sideTabs button.on { background: var(--sel); font-weight: 600; }
|
|
55
|
+
#gitBadge { color: var(--warn); font-weight: 700; }
|
|
56
|
+
.pane { display: flex; flex-direction: column; min-height: 0; flex: 1; padding: 8px; gap: 6px; }
|
|
57
|
+
.pane > .scroll { overflow: auto; flex: 1; min-height: 0; margin: 0 -8px; }
|
|
58
|
+
|
|
59
|
+
/* files */
|
|
60
|
+
#files .dir { color: var(--muted); padding: 5px 8px 2px; font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
|
|
61
|
+
display: flex; align-items: center; gap: 4px; }
|
|
62
|
+
#files .dir.toggle { cursor: pointer; user-select: none; }
|
|
63
|
+
#files .dir.toggle:hover { color: var(--ink); }
|
|
64
|
+
#files .f { padding: 3px 8px 3px 18px; cursor: pointer; white-space: nowrap; display: flex; align-items: center; gap: 4px; }
|
|
65
|
+
#files .f .nm { overflow: hidden; text-overflow: ellipsis; flex: 1; }
|
|
66
|
+
#files .f:hover, #files .dir:hover { background: var(--bg); }
|
|
67
|
+
#files .f.active { background: var(--sel); font-weight: 600; }
|
|
68
|
+
#files .f.asset .nm { color: var(--muted); font-style: italic; }
|
|
69
|
+
#files .f.mod .nm::after { content: " ●"; color: var(--warn); }
|
|
70
|
+
#files .badge { font-size: 10px; color: var(--accent); border: 1px solid var(--accent); border-radius: 4px; padding: 0 3px; }
|
|
71
|
+
#files .acts { display: none; gap: 2px; }
|
|
72
|
+
#files .f:hover .acts, #files .dir:hover .acts, #files .confirm .acts { display: inline-flex; }
|
|
73
|
+
#files .acts button { padding: 0 4px; font-size: 11px; line-height: 1.4; }
|
|
74
|
+
#files .confirm { background: color-mix(in srgb, var(--err) 12%, transparent); }
|
|
75
|
+
#files.drop { outline: 2px dashed var(--accent); outline-offset: -4px; }
|
|
76
|
+
#files .dir.drop { background: var(--sel); }
|
|
77
|
+
#fsForm input { width: 100%; }
|
|
78
|
+
#fsHint { font-size: 11px; color: var(--muted); margin-top: 2px; }
|
|
79
|
+
|
|
80
|
+
/* outline */
|
|
81
|
+
#outline .o { padding: 2px 8px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
82
|
+
#outline .o:hover { background: var(--bg); }
|
|
83
|
+
#outline .o.cur { background: var(--sel); font-weight: 600; }
|
|
84
|
+
#outline .o small { color: var(--muted); }
|
|
85
|
+
#outline .l0, #outline .l1 { font-weight: 600; }
|
|
86
|
+
|
|
87
|
+
/* search */
|
|
88
|
+
.toggles label { display: inline-flex; gap: 3px; align-items: center; color: var(--muted); font-size: 12px; cursor: pointer; }
|
|
89
|
+
#searchCount { color: var(--muted); font-size: 12px; }
|
|
90
|
+
#searchResults .sf { padding: 6px 8px 2px; font-weight: 600; font-size: 12px; display: flex; gap: 6px; }
|
|
91
|
+
#searchResults .sf small { color: var(--muted); font-weight: 400; }
|
|
92
|
+
#searchResults .sm { padding: 1px 8px 1px 14px; font: 12px/1.45 ui-monospace, Menlo, Consolas, monospace; cursor: pointer;
|
|
93
|
+
white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
94
|
+
#searchResults .sm:hover { background: var(--bg); }
|
|
95
|
+
#searchResults .sm b { background: var(--hl); color: inherit; font-weight: inherit; border-radius: 2px; }
|
|
96
|
+
#searchResults .sm i { color: var(--muted); font-style: normal; display: inline-block; min-width: 2.8em; }
|
|
97
|
+
|
|
98
|
+
/* git */
|
|
99
|
+
#gitHead { display: flex; justify-content: space-between; gap: 6px; font-family: ui-monospace, monospace; font-size: 12px; }
|
|
100
|
+
#gitSync { color: var(--muted); }
|
|
101
|
+
.gitBtns { display: flex; gap: 6px; flex-wrap: wrap; }
|
|
102
|
+
.gitBtns button { padding: 3px 8px; }
|
|
103
|
+
#gitMsg { width: 100%; resize: vertical; }
|
|
104
|
+
#gitMsgOut { font-size: 12px; white-space: pre-wrap; word-break: break-word; }
|
|
105
|
+
#gitMsgOut.err { color: var(--err); } #gitMsgOut.ok { color: var(--ok); }
|
|
106
|
+
#gitState { border: 1px solid var(--warn); border-radius: 6px; padding: 6px; font-size: 12px; }
|
|
107
|
+
.gsec { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; margin-top: 6px;
|
|
108
|
+
display: flex; justify-content: space-between; align-items: center; }
|
|
109
|
+
.gsec button { padding: 0 6px; font-size: 11px; text-transform: none; letter-spacing: 0; }
|
|
110
|
+
.gf { display: flex; align-items: center; gap: 6px; padding: 2px 4px; border-radius: 4px; cursor: pointer; }
|
|
111
|
+
.gf:hover { background: var(--bg); }
|
|
112
|
+
.gf .st { width: 14px; text-align: center; font-family: ui-monospace, monospace; font-weight: 700; }
|
|
113
|
+
.gf .st.M { color: var(--warn); } .gf .st.A, .gf .st.U { color: var(--ok); } .gf .st.D, .gf .st.C { color: var(--err); } .gf .st.R { color: var(--info); }
|
|
114
|
+
.gf .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
115
|
+
.gf .nm small { color: var(--muted); }
|
|
116
|
+
.gf button { padding: 0 6px; line-height: 1.3; }
|
|
117
|
+
.gl { padding: 3px 4px; font-size: 12px; cursor: pointer; border-radius: 4px; }
|
|
118
|
+
.gl:hover { background: var(--bg); }
|
|
119
|
+
.gl code { color: var(--accent); } .gl small { color: var(--muted); }
|
|
120
|
+
|
|
121
|
+
/* editor */
|
|
122
|
+
#editorWrap { position: relative; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
|
|
123
|
+
#tabs { display: flex; overflow-x: auto; background: var(--bg); border-bottom: 1px solid var(--line); min-height: 30px; scrollbar-width: thin; }
|
|
124
|
+
#tabs .tab { display: flex; align-items: center; gap: 4px; padding: 5px 6px 5px 10px; border-right: 1px solid var(--line);
|
|
125
|
+
cursor: pointer; white-space: nowrap; color: var(--muted); font-size: 12px; user-select: none; }
|
|
126
|
+
#tabs .tab.on { background: var(--panel); color: var(--ink); font-weight: 600; box-shadow: inset 0 2px 0 var(--accent); }
|
|
127
|
+
#tabs .tab .x { border: 0; background: none; padding: 0 3px; color: var(--muted); line-height: 1; }
|
|
128
|
+
#tabs .tab .x:hover { color: var(--ink); }
|
|
129
|
+
#tabs .tab.mod .x::before { content: "●"; color: var(--warn); }
|
|
130
|
+
#tabs .tab.mod .x span { display: none; }
|
|
131
|
+
#tabs .tab.mod:hover .x::before { content: ""; }
|
|
132
|
+
#tabs .tab.mod:hover .x span { display: inline; }
|
|
133
|
+
#banner { display: none; padding: 6px 10px; background: var(--sel); border-bottom: 1px solid var(--line); gap: 8px; align-items: center; }
|
|
134
|
+
#banner.show { display: flex; }
|
|
135
|
+
.CodeMirror { flex: 1; height: auto; font: 13.5px/1.5 ui-monospace, "SF Mono", Menlo, Consolas, monospace; background: var(--panel); color: var(--ink); }
|
|
136
|
+
.CodeMirror-gutters { background: var(--panel); border-right: 1px solid var(--line); }
|
|
137
|
+
.CodeMirror-linenumber { color: var(--muted); }
|
|
138
|
+
.CodeMirror-cursor { border-left-color: var(--ink); }
|
|
139
|
+
.CodeMirror-activeline-background { background: var(--bg); }
|
|
140
|
+
.CodeMirror-selected, .CodeMirror-focused .CodeMirror-selected { background: var(--sel) !important; }
|
|
141
|
+
.CodeMirror-dialog { background: var(--panel); color: var(--ink); }
|
|
142
|
+
.cm-tag, .cm-builtin { color: var(--info); } .cm-comment { color: #8a8f98; font-style: italic; }
|
|
143
|
+
.cm-bracket { color: #9b5de5; } .cm-keyword { color: #b5179e; } .cm-atom, .cm-number { color: #2a9d8f; }
|
|
144
|
+
.cm-error { color: var(--err); }
|
|
145
|
+
.line-error { background: rgba(240, 68, 56, .14); }
|
|
146
|
+
.line-hit { background: var(--hl); }
|
|
147
|
+
.cf-marker { background: color-mix(in srgb, var(--warn) 30%, transparent); font-weight: 700; }
|
|
148
|
+
.cf-ours { background: var(--ours); } .cf-theirs { background: var(--theirs); }
|
|
149
|
+
#diffView, #preview { position: absolute; inset: 0; background: var(--panel); display: flex; flex-direction: column; z-index: 5; }
|
|
150
|
+
#diffHead, #previewHead { display: flex; gap: 8px; align-items: center; padding: 6px 10px; border-bottom: 1px solid var(--line); }
|
|
151
|
+
#diffBody { flex: 1; overflow: auto; margin: 0; padding: 8px 0; font: 12.5px/1.45 ui-monospace, Menlo, Consolas, monospace; }
|
|
152
|
+
#diffBody div { padding: 0 10px; white-space: pre-wrap; word-break: break-word; }
|
|
153
|
+
#diffBody .add { background: rgba(46, 160, 67, .16); } #diffBody .del { background: rgba(248, 81, 73, .16); }
|
|
154
|
+
#diffBody .hunk { color: var(--info); background: var(--bg); } #diffBody .meta { color: var(--muted); }
|
|
155
|
+
#diffBody .cfile { font-weight: 700; padding-top: 10px; border-bottom: 1px solid var(--line); }
|
|
156
|
+
#diffBody .chunk { cursor: pointer; }
|
|
157
|
+
#diffBody .chunk:hover { background: var(--bg); }
|
|
158
|
+
#diffBody .cbody { padding-bottom: 6px; }
|
|
159
|
+
#diffBody .ins { color: var(--ins); background: rgba(46, 160, 67, .10); }
|
|
160
|
+
#diffBody .rem { color: var(--rem); text-decoration: line-through; background: rgba(248, 81, 73, .08); }
|
|
161
|
+
#previewBody { flex: 1; overflow: auto; display: flex; align-items: flex-start; justify-content: center; padding: 16px; background: var(--pdfbg); }
|
|
162
|
+
#previewBody img, #previewBody canvas { max-width: 100%; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.25); }
|
|
163
|
+
|
|
164
|
+
/* autocomplete */
|
|
165
|
+
.complete { position: fixed; z-index: 50; list-style: none; margin: 0; padding: 3px 0; min-width: 220px; max-width: 520px;
|
|
166
|
+
max-height: 264px; overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
|
|
167
|
+
box-shadow: var(--shadow); font: 12.5px/1.35 ui-monospace, Menlo, Consolas, monospace; }
|
|
168
|
+
.complete li { padding: 3px 10px; display: flex; gap: 10px; cursor: pointer; white-space: nowrap; }
|
|
169
|
+
.complete li.on { background: var(--sel); }
|
|
170
|
+
.complete li .d { color: var(--muted); overflow: hidden; text-overflow: ellipsis; font-family: system-ui, sans-serif; font-size: 12px; }
|
|
171
|
+
|
|
172
|
+
/* tools popover */
|
|
173
|
+
.popover { position: fixed; z-index: 40; background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
|
|
174
|
+
box-shadow: var(--shadow); padding: 10px 12px; width: 320px; display: flex; flex-direction: column; gap: 8px; }
|
|
175
|
+
.popover label.field { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
|
|
176
|
+
.popover select { width: 100%; padding: 3px 6px; }
|
|
177
|
+
.popover .note { font-size: 11.5px; color: var(--muted); }
|
|
178
|
+
.popover code { font-size: 11.5px; }
|
|
179
|
+
.popover hr { border: 0; border-top: 1px solid var(--line); margin: 2px 0; width: 100%; }
|
|
180
|
+
#wcOut table { border-collapse: collapse; font-size: 12px; width: 100%; }
|
|
181
|
+
#wcOut td { padding: 1px 0; } #wcOut td + td { text-align: right; font-variant-numeric: tabular-nums; }
|
|
182
|
+
kbd { font: 11px ui-monospace, monospace; border: 1px solid var(--line); border-radius: 3px; padding: 0 3px; background: var(--bg); }
|
|
183
|
+
.keys { display: grid; grid-template-columns: auto 1fr; gap: 2px 8px; font-size: 12px; }
|
|
184
|
+
|
|
185
|
+
/* PDF */
|
|
186
|
+
#split { cursor: col-resize; background: var(--line); }
|
|
187
|
+
#pdfPane { position: relative; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
|
|
188
|
+
#pdfWrap { flex: 1; background: var(--pdfbg); overflow: auto; position: relative; min-height: 0; }
|
|
189
|
+
#pdf { padding: 12px 0; display: flex; flex-direction: column; align-items: center; gap: 12px; }
|
|
190
|
+
.page { position: relative; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.25); }
|
|
191
|
+
.page canvas { display: block; }
|
|
192
|
+
.mark { position: absolute; left: 0; right: 0; height: 18px; background: var(--hl); pointer-events: none; transition: opacity 1.2s; z-index: 3; }
|
|
193
|
+
#pdfEmpty { color: var(--muted); padding: 40px; text-align: center; }
|
|
194
|
+
#pdfFind { position: absolute; top: 8px; right: 20px; z-index: 6; display: flex; gap: 4px; align-items: center; padding: 4px;
|
|
195
|
+
background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
|
|
196
|
+
#findInput { width: 200px; }
|
|
197
|
+
#findCount { color: var(--muted); min-width: 5.5em; text-align: center; font-variant-numeric: tabular-nums; white-space: nowrap; }
|
|
198
|
+
#findCount.none { color: var(--err); }
|
|
199
|
+
#pdfFind button { padding: 2px 8px; }
|
|
200
|
+
/* pdf.js text layer: transparent text over the page image, for selecting, copying and find highlights */
|
|
201
|
+
.textLayer { position: absolute; inset: 0; overflow: clip; line-height: 1; z-index: 2; transform-origin: 0 0;
|
|
202
|
+
-webkit-text-size-adjust: none; text-size-adjust: none; forced-color-adjust: none; }
|
|
203
|
+
.textLayer span, .textLayer br { color: transparent; position: absolute; white-space: pre; cursor: text; transform-origin: 0% 0%; }
|
|
204
|
+
.textLayer span.markedContent { top: 0; height: 0; }
|
|
205
|
+
.textLayer ::selection { background: rgba(0, 110, 255, .28); }
|
|
206
|
+
.textLayer br::selection { background: transparent; }
|
|
207
|
+
.textLayer span.hl { position: static; background: rgba(255, 196, 0, .45); border-radius: 2px; }
|
|
208
|
+
.textLayer span.hl.cur { background: rgba(255, 110, 0, .65); }
|
|
209
|
+
|
|
210
|
+
/* log */
|
|
211
|
+
footer { background: var(--panel); border-top: 1px solid var(--line); max-height: 36vh; display: flex; flex-direction: column; }
|
|
212
|
+
footer .bar { display: flex; gap: 12px; padding: 4px 10px; align-items: center; cursor: pointer; user-select: none; }
|
|
213
|
+
footer .bar b.e { color: var(--err); } footer .bar b.w { color: var(--warn); }
|
|
214
|
+
#log { overflow: auto; display: none; border-top: 1px solid var(--line); }
|
|
215
|
+
#log.open { display: block; }
|
|
216
|
+
#log .item { padding: 5px 10px; border-bottom: 1px solid var(--line); font-size: 12px; }
|
|
217
|
+
#log .item.link { cursor: pointer; }
|
|
218
|
+
#log .item.link:hover { background: var(--bg); }
|
|
219
|
+
#log .item.e { border-left: 3px solid var(--err); } #log .item.w { border-left: 3px solid var(--warn); }
|
|
220
|
+
#log .item .where { font-family: ui-monospace, monospace; color: var(--muted); margin-right: 8px; }
|
|
221
|
+
#log .item .msg { font-family: ui-monospace, monospace; }
|
|
222
|
+
#log .item .ctx { font-family: ui-monospace, monospace; color: var(--muted); display: block; margin-top: 2px; white-space: pre-wrap; }
|
|
223
|
+
#log .item .hint { display: block; margin-top: 3px; }
|
|
224
|
+
#log .item .hint::before { content: "Hint: "; font-weight: 600; }
|
|
225
|
+
#log pre { margin: 0; padding: 8px 10px; font-size: 11.5px; color: var(--muted); white-space: pre-wrap; }
|
|
226
|
+
|
|
227
|
+
@media (max-width: 900px) {
|
|
228
|
+
main { grid-template-columns: 1fr; grid-template-rows: 200px 1fr 0 1fr; }
|
|
229
|
+
#side { border-right: 0; border-bottom: 1px solid var(--line); }
|
|
230
|
+
#split { display: none; }
|
|
231
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// Entry point: loads the modules (each one wires up its part of the page), then starts the editor.
|
|
2
|
+
import { $, app, state, project, store, api, setStatus, debounce } from './util.js';
|
|
3
|
+
import './editor.js';
|
|
4
|
+
import './complete.js';
|
|
5
|
+
import './files.js';
|
|
6
|
+
import './diffview.js';
|
|
7
|
+
import './compile.js';
|
|
8
|
+
import './pdfview.js';
|
|
9
|
+
import './panels.js';
|
|
10
|
+
import './git.js';
|
|
11
|
+
import './tools.js';
|
|
12
|
+
|
|
13
|
+
app.project = project;
|
|
14
|
+
|
|
15
|
+
// ---------- theme ----------
|
|
16
|
+
const applyTheme = t => { if (t) document.documentElement.dataset.theme = t; else delete document.documentElement.dataset.theme; };
|
|
17
|
+
applyTheme(store.get('theme', null));
|
|
18
|
+
$('themeBtn').onclick = () => {
|
|
19
|
+
const dark = matchMedia('(prefers-color-scheme: dark)').matches;
|
|
20
|
+
const cur = document.documentElement.dataset.theme || (dark ? 'dark' : 'light');
|
|
21
|
+
const next = cur === 'dark' ? 'light' : 'dark'; applyTheme(next); store.set('theme', next);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// ---------- side panels ----------
|
|
25
|
+
export function showTab(t) {
|
|
26
|
+
for (const b of document.querySelectorAll('#sideTabs button')) {
|
|
27
|
+
const on = b.dataset.tab === t;
|
|
28
|
+
b.classList.toggle('on', on); $(b.dataset.tab + 'Pane').hidden = !on;
|
|
29
|
+
}
|
|
30
|
+
store.set('sideTab', t);
|
|
31
|
+
if (t === 'git') app.gitRefresh(false);
|
|
32
|
+
if (t === 'outline') app.refreshOutline();
|
|
33
|
+
}
|
|
34
|
+
document.querySelectorAll('#sideTabs button').forEach(b => { b.onclick = () => showTab(b.dataset.tab); });
|
|
35
|
+
app.showTab = showTab;
|
|
36
|
+
|
|
37
|
+
// ---------- keeping things fresh ----------
|
|
38
|
+
const afterSave = debounce(() => {
|
|
39
|
+
app.gitSoon(); app.refreshCompletions();
|
|
40
|
+
if (!$('outlinePane').hidden) app.refreshOutline();
|
|
41
|
+
}, 600);
|
|
42
|
+
app.onSaved = afterSave;
|
|
43
|
+
app.filesChanged = () => { afterSave(); app.refreshSettings(); };
|
|
44
|
+
app.onCursor = () => app.markCurrentSection();
|
|
45
|
+
app.onFileOpened = () => { app.markCurrentSection(); };
|
|
46
|
+
|
|
47
|
+
// ---------- keyboard ----------
|
|
48
|
+
document.addEventListener('keydown', e => {
|
|
49
|
+
if (e.defaultPrevented) return; // the editor handled it (its own search, completion, …)
|
|
50
|
+
const mod = e.ctrlKey || e.metaKey, key = e.key.toLowerCase();
|
|
51
|
+
if (mod && e.shiftKey && key === 'f') { e.preventDefault(); app.showSearch(); return; }
|
|
52
|
+
// Ctrl/Cmd+F outside the editor (and its search box) searches the PDF.
|
|
53
|
+
if (mod && !e.shiftKey && !e.altKey && key === 'f' && $('diffView').hidden && $('preview').hidden &&
|
|
54
|
+
!app.cm.getWrapperElement().contains(e.target)) { e.preventDefault(); app.openFind(); return; }
|
|
55
|
+
if (e.key === 'Escape') {
|
|
56
|
+
if (!$('tools').hidden) app.closeTools();
|
|
57
|
+
else if (!$('preview').hidden) app.closePreview();
|
|
58
|
+
else if (!$('diffView').hidden) app.closeDiff();
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// ---------- start ----------
|
|
63
|
+
(async () => {
|
|
64
|
+
await app.loadFiles();
|
|
65
|
+
await app.restoreTabs(project.main);
|
|
66
|
+
showTab(store.get('sideTab', 'files'));
|
|
67
|
+
app.refreshSettings(); app.refreshCompletions(); app.gitRefresh(false);
|
|
68
|
+
const s = await api('/api/status');
|
|
69
|
+
if (s.running) setStatus('initial compile…', 'run');
|
|
70
|
+
else if (s.finished) app.showResult(s);
|
|
71
|
+
await app.loadPdf();
|
|
72
|
+
})();
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// Compiling: run, queue, stop; the log panel with errors, warnings and hints; polling for compiles and PDFs that
|
|
2
|
+
// happen elsewhere.
|
|
3
|
+
import { $, el, app, state, api, post, setStatus } from './util.js';
|
|
4
|
+
|
|
5
|
+
let queued = false; // a save arrived while a compile was running: compile once more when it ends
|
|
6
|
+
|
|
7
|
+
function running(on) {
|
|
8
|
+
$('stopBtn').hidden = !on;
|
|
9
|
+
$('compileBtn').disabled = on;
|
|
10
|
+
$('compileBtn').textContent = on ? 'Compiling…' : 'Recompile';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export async function compile() {
|
|
14
|
+
if (!(await app.saveAll())) return;
|
|
15
|
+
if (state.compiling) { queued = true; setStatus('compiling… (will compile again for the latest changes)', 'run'); return; }
|
|
16
|
+
state.compiling = true; running(true); setStatus('compiling…', 'run');
|
|
17
|
+
const r = await post('/api/compile');
|
|
18
|
+
state.compiling = false; running(false);
|
|
19
|
+
if (r.status === 409) { queued = true; setStatus('compiling… (started elsewhere; will compile again)', 'run'); return; }
|
|
20
|
+
if (!r.ok) setStatus('compile failed: ' + (r.error || r.status), 'err');
|
|
21
|
+
else { showResult(r); await app.loadPdf(); }
|
|
22
|
+
if (queued) { queued = false; compile(); }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function stop() {
|
|
26
|
+
setStatus('stopping…', 'run');
|
|
27
|
+
await post('/api/compile/stop');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const plural = (n, w) => `${n} ${w}${n === 1 ? '' : 's'}`;
|
|
31
|
+
const where = e => e.file ? `${e.file}${e.line ? ':' + e.line : ''}` : '';
|
|
32
|
+
|
|
33
|
+
export function showResult(r) {
|
|
34
|
+
state.lastResult = r;
|
|
35
|
+
const errors = r.errors || [], warnings = r.warnings || [];
|
|
36
|
+
$('nErr').textContent = plural(errors.length, 'error'); $('nWarn').textContent = plural(warnings.length, 'warning');
|
|
37
|
+
const engine = r.engine ? `${r.engine}${r.engine_source && r.engine_source !== 'default' ? ` (from ${r.engine_source})` : ''}`
|
|
38
|
+
: 'engine chosen by latexmkrc';
|
|
39
|
+
if (r.stopped) setStatus('compile stopped', 'err');
|
|
40
|
+
else if (r.success) setStatus(`compiled in ${r.seconds}s${r.engine && r.engine !== 'pdflatex' ? ' · ' + r.engine : ''}`, 'ok', `Compiled with ${engine}`);
|
|
41
|
+
else if (errors.length) setStatus(`${plural(errors.length, 'error')}: ${errors[0].message}${errors[0].file ? ` (${where(errors[0])})` : ''}`, 'err', `Compiled with ${engine}`);
|
|
42
|
+
else setStatus(`latexmk failed (${r.seconds}s): see the log`, 'err');
|
|
43
|
+
|
|
44
|
+
const item = (cls, x) => {
|
|
45
|
+
const link = x.file && x.line && !x.external && app.project.files.includes(x.file);
|
|
46
|
+
return el('div', { className: `item ${cls}${link ? ' link' : ''}`, title: link ? 'Open this line' : '',
|
|
47
|
+
onclick: link ? () => app.openFile(x.file, x.line, { flash: true }) : null },
|
|
48
|
+
where(x) ? el('span', { className: 'where' }, where(x)) : null,
|
|
49
|
+
el('span', { className: 'msg' }, x.message),
|
|
50
|
+
x.context ? el('span', { className: 'ctx' }, x.context) : null,
|
|
51
|
+
x.hint ? el('span', { className: 'hint' }, x.hint) : null);
|
|
52
|
+
};
|
|
53
|
+
$('log').replaceChildren(...errors.map(e => item('e', e)), ...warnings.map(w => item('w', w)),
|
|
54
|
+
el('pre', {}, r.log_tail || ''));
|
|
55
|
+
if (errors.length || (!r.success && !r.stopped)) openLog(true);
|
|
56
|
+
app.markErrors();
|
|
57
|
+
app.refreshChangesIfOpen?.();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function openLog(open) {
|
|
61
|
+
$('log').classList.toggle('open', open);
|
|
62
|
+
$('logHint').textContent = open ? 'click to collapse' : 'click to expand';
|
|
63
|
+
}
|
|
64
|
+
$('logBar').onclick = () => openLog(!$('log').classList.contains('open'));
|
|
65
|
+
$('compileBtn').onclick = () => compile();
|
|
66
|
+
$('stopBtn').onclick = stop;
|
|
67
|
+
$('saveBtn').onclick = () => app.save();
|
|
68
|
+
|
|
69
|
+
// Compiles started elsewhere (the start-up compile, another tab, latexmk -pvc in a terminal) and edits made by other
|
|
70
|
+
// programs. The PDF is loaded only when the server says it is complete, never half-written.
|
|
71
|
+
async function poll() {
|
|
72
|
+
app.checkExternalChange();
|
|
73
|
+
const s = await api('/api/status');
|
|
74
|
+
if (!s.ok) { if (s.status === 0) setStatus('the editor server is not running', 'err'); return; }
|
|
75
|
+
if (s.running) { if (!state.compiling) { running(true); setStatus('compiling…', 'run'); } return; }
|
|
76
|
+
if (!state.compiling) running(false);
|
|
77
|
+
if (queued && !state.compiling) { queued = false; compile(); return; }
|
|
78
|
+
if (s.finished && s.finished !== state.lastResult?.finished && !state.compiling) showResult(s);
|
|
79
|
+
if (s.pdf_complete && s.pdf_mtime && s.pdf_mtime !== app.pdf.mtime && !app.pdf.rendering) app.loadPdf();
|
|
80
|
+
}
|
|
81
|
+
setInterval(poll, 3000);
|
|
82
|
+
|
|
83
|
+
Object.assign(app, { compile, showResult });
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
// Autocompletion: \ref labels, \cite keys, environments, file names and commands (built-in and the project's own).
|
|
2
|
+
import { el, app, project, api } from './util.js';
|
|
3
|
+
|
|
4
|
+
// [name, number of {} arguments]
|
|
5
|
+
const BUILTIN = [
|
|
6
|
+
['section', 1], ['subsection', 1], ['subsubsection', 1], ['chapter', 1], ['part', 1], ['paragraph', 1],
|
|
7
|
+
['section*', 1], ['subsection*', 1], ['chapter*', 1], ['label', 1], ['ref', 1], ['eqref', 1], ['pageref', 1],
|
|
8
|
+
['autoref', 1], ['cref', 1], ['Cref', 1], ['cite', 1], ['citep', 1], ['citet', 1], ['parencite', 1], ['textcite', 1],
|
|
9
|
+
['autocite', 1], ['nocite', 1], ['footnote', 1], ['footnotemark', 0], ['url', 1], ['href', 2], ['emph', 1],
|
|
10
|
+
['textbf', 1], ['textit', 1], ['texttt', 1], ['textsc', 1], ['textrm', 1], ['textsf', 1], ['underline', 1],
|
|
11
|
+
['mathbf', 1], ['mathrm', 1], ['mathit', 1], ['mathcal', 1], ['mathbb', 1], ['mathfrak', 1], ['mathsf', 1],
|
|
12
|
+
['boldsymbol', 1], ['operatorname', 1], ['text', 1], ['frac', 2], ['dfrac', 2], ['tfrac', 2], ['sqrt', 1],
|
|
13
|
+
['binom', 2], ['overline', 1], ['underbrace', 1], ['overbrace', 1], ['hat', 1], ['bar', 1], ['tilde', 1],
|
|
14
|
+
['vec', 1], ['dot', 1], ['ddot', 1], ['widehat', 1], ['widetilde', 1], ['left', 0], ['right', 0], ['sum', 0],
|
|
15
|
+
['prod', 0], ['int', 0], ['iint', 0], ['oint', 0], ['lim', 0], ['infty', 0], ['partial', 0], ['nabla', 0],
|
|
16
|
+
['cdot', 0], ['cdots', 0], ['ldots', 0], ['dots', 0], ['times', 0], ['leq', 0], ['geq', 0], ['neq', 0],
|
|
17
|
+
['approx', 0], ['equiv', 0], ['sim', 0], ['propto', 0], ['in', 0], ['notin', 0], ['subset', 0], ['subseteq', 0],
|
|
18
|
+
['cup', 0], ['cap', 0], ['forall', 0], ['exists', 0], ['rightarrow', 0], ['leftarrow', 0], ['Rightarrow', 0],
|
|
19
|
+
['Leftrightarrow', 0], ['mapsto', 0], ['to', 0], ['alpha', 0], ['beta', 0], ['gamma', 0], ['delta', 0],
|
|
20
|
+
['epsilon', 0], ['varepsilon', 0], ['zeta', 0], ['eta', 0], ['theta', 0], ['vartheta', 0], ['iota', 0],
|
|
21
|
+
['kappa', 0], ['lambda', 0], ['mu', 0], ['nu', 0], ['xi', 0], ['pi', 0], ['rho', 0], ['sigma', 0], ['tau', 0],
|
|
22
|
+
['upsilon', 0], ['phi', 0], ['varphi', 0], ['chi', 0], ['psi', 0], ['omega', 0], ['Gamma', 0], ['Delta', 0],
|
|
23
|
+
['Theta', 0], ['Lambda', 0], ['Xi', 0], ['Pi', 0], ['Sigma', 0], ['Phi', 0], ['Psi', 0], ['Omega', 0],
|
|
24
|
+
['begin', 1], ['end', 1], ['item', 0], ['includegraphics', 1], ['caption', 1], ['centering', 0], ['input', 1],
|
|
25
|
+
['include', 1], ['includeonly', 1], ['usepackage', 1], ['documentclass', 1], ['newcommand', 2],
|
|
26
|
+
['renewcommand', 2], ['DeclareMathOperator', 2], ['title', 1], ['author', 1], ['date', 1], ['maketitle', 0],
|
|
27
|
+
['tableofcontents', 0], ['listoffigures', 0], ['listoftables', 0], ['bibliography', 1],
|
|
28
|
+
['bibliographystyle', 1], ['printbibliography', 0], ['addbibresource', 1], ['appendix', 0], ['clearpage', 0],
|
|
29
|
+
['newpage', 0], ['noindent', 0], ['vspace', 1], ['hspace', 1], ['quad', 0], ['qquad', 0], ['hline', 0],
|
|
30
|
+
['toprule', 0], ['midrule', 0], ['bottomrule', 0], ['multicolumn', 3], ['multirow', 3], ['textwidth', 0],
|
|
31
|
+
['linewidth', 0], ['small', 0], ['footnotesize', 0], ['large', 0], ['Large', 0], ['todo', 1], ['verb', 0],
|
|
32
|
+
];
|
|
33
|
+
const ENVS = ['itemize', 'enumerate', 'description', 'figure', 'figure*', 'table', 'table*', 'tabular', 'tabularx',
|
|
34
|
+
'equation', 'equation*', 'align', 'align*', 'gather', 'gather*', 'multline', 'multline*', 'split', 'cases',
|
|
35
|
+
'matrix', 'pmatrix', 'bmatrix', 'vmatrix', 'array', 'center', 'flushleft', 'flushright', 'quote', 'quotation',
|
|
36
|
+
'verbatim', 'minipage', 'abstract', 'theorem', 'lemma', 'proof', 'definition', 'corollary', 'proposition',
|
|
37
|
+
'remark', 'example', 'frame', 'columns', 'column', 'block', 'tikzpicture', 'lstlisting', 'minted', 'subfigure',
|
|
38
|
+
'algorithm', 'algorithmic', 'thebibliography', 'document', 'appendices', 'landscape'];
|
|
39
|
+
const IMAGE = /\.(pdf|png|jpe?g|eps|svg)$/i;
|
|
40
|
+
|
|
41
|
+
let data = { labels: [], bib: [], commands: [] };
|
|
42
|
+
export async function refreshCompletions() { const r = await api('/api/labels'); if (r.ok) data = r; }
|
|
43
|
+
|
|
44
|
+
// What can be completed at the cursor: { kind, token, from } or null.
|
|
45
|
+
function context(cm) {
|
|
46
|
+
const cur = cm.getCursor(), before = cm.getLine(cur.line).slice(0, cur.ch);
|
|
47
|
+
const at = (kind, token, extra) => ({ kind, token, from: cur.ch - token.length, ...extra });
|
|
48
|
+
const last = s => s.slice(s.lastIndexOf(',') + 1).trimStart();
|
|
49
|
+
let m;
|
|
50
|
+
if ((m = before.match(/\\(?:[a-zA-Z]*ref|[cC]ref|vref|autoref|nameref|eqref|pageref|labelcref|cpageref)\*?\{([^{}]*)$/))) return at('ref', last(m[1]));
|
|
51
|
+
if ((m = before.match(/\\(?:[a-zA-Z]*cite[a-zA-Z]*|nocite)\*?(?:\[[^\]]*\]){0,2}\{([^{}]*)$/))) return at('cite', last(m[1]));
|
|
52
|
+
if ((m = before.match(/\\(begin|end)\{([a-zA-Z*]*)$/))) return at(m[1], m[2]);
|
|
53
|
+
if ((m = before.match(/\\(input|include|subfile|includegraphics|bibliography|addbibresource|includeonly)(?:\[[^\]]*\])?\{([^{}]*)$/))) {
|
|
54
|
+
const cmd = m[1], token = cmd === 'bibliography' || cmd === 'includeonly' ? last(m[2]) : m[2];
|
|
55
|
+
let files;
|
|
56
|
+
if (cmd === 'includegraphics') files = project.assets.filter(f => IMAGE.test(f));
|
|
57
|
+
else if (cmd === 'bibliography') files = project.files.filter(f => f.endsWith('.bib')).map(f => f.slice(0, -4));
|
|
58
|
+
else if (cmd === 'addbibresource') files = project.files.filter(f => f.endsWith('.bib'));
|
|
59
|
+
else if (cmd === 'input') files = project.files.filter(f => /\.(tex|tikz)$/.test(f));
|
|
60
|
+
else files = project.files.filter(f => f.endsWith('.tex')).map(f => f.slice(0, -4));
|
|
61
|
+
return at('file', token, { files });
|
|
62
|
+
}
|
|
63
|
+
if ((m = before.match(/\\([a-zA-Z@]*\*?)$/))) return at('cmd', m[1]);
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function candidates(ctx) {
|
|
68
|
+
let all;
|
|
69
|
+
if (ctx.kind === 'ref') all = data.labels.map(l => ({ text: l.key, detail: l.context || `${l.file}:${l.line}` }));
|
|
70
|
+
else if (ctx.kind === 'cite') all = data.bib.map(b => ({ text: b.key, detail: [b.author.split(/\s+and\s+/)[0], b.year, b.title].filter(Boolean).join(' · ') }));
|
|
71
|
+
else if (ctx.kind === 'begin' || ctx.kind === 'end') all = [...new Set([...ENVS, ...data.commands.filter(c => c.env).map(c => c.name)])].map(text => ({ text }));
|
|
72
|
+
else if (ctx.kind === 'file') all = ctx.files.map(text => ({ text }));
|
|
73
|
+
else {
|
|
74
|
+
const own = data.commands.filter(c => !c.env).map(c => ({ text: c.name, args: c.args, detail: `defined in ${c.file}` }));
|
|
75
|
+
const seen = new Set(own.map(c => c.text));
|
|
76
|
+
all = [...own, ...BUILTIN.filter(([n]) => !seen.has(n)).map(([text, args]) => ({ text, args }))];
|
|
77
|
+
}
|
|
78
|
+
const t = ctx.token.toLowerCase(), out = [];
|
|
79
|
+
for (const it of all) {
|
|
80
|
+
const i = it.text.toLowerCase().indexOf(t);
|
|
81
|
+
// citations also match on author and title
|
|
82
|
+
const rank = i === 0 ? 0 : i > 0 ? 1 : ctx.kind === 'cite' && t && it.detail.toLowerCase().includes(t) ? 2 : -1;
|
|
83
|
+
if (rank >= 0 && !(ctx.kind === 'cmd' && it.text === ctx.token)) out.push([rank, it.text.length, it]);
|
|
84
|
+
}
|
|
85
|
+
return out.sort((a, b) => a[0] - b[0] || a[1] - b[1] || a[2].text.localeCompare(b[2].text)).slice(0, 200).map(x => x[2]);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// ---------- the dropdown ----------
|
|
89
|
+
let box = null, active = null; // active: { ctx, list, sel, line }
|
|
90
|
+
const keys = {
|
|
91
|
+
Up: () => move(-1), Down: () => move(1), PageUp: () => move(-8), PageDown: () => move(8),
|
|
92
|
+
Enter: () => accept(), Tab: () => accept(), Esc: () => close(),
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
function render() {
|
|
96
|
+
box.replaceChildren(...active.list.map((it, i) => el('li', {
|
|
97
|
+
className: i === active.sel ? 'on' : '', role: 'option', onmousedown: e => { e.preventDefault(); active.sel = i; accept(); },
|
|
98
|
+
}, el('span', {}, it.text), it.detail ? el('span', { className: 'd' }, it.detail) : null)));
|
|
99
|
+
box.children[active.sel]?.scrollIntoView({ block: 'nearest' });
|
|
100
|
+
}
|
|
101
|
+
function move(d) { active.sel = Math.max(0, Math.min(active.list.length - 1, active.sel + d)); render(); }
|
|
102
|
+
|
|
103
|
+
export function close() {
|
|
104
|
+
if (!active) return;
|
|
105
|
+
box.hidden = true; app.cm.removeKeyMap(keys); active = null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// explicit: Ctrl-Space (show even with nothing typed); otherwise only when the context is worth a popup.
|
|
109
|
+
export function complete(explicit = false) {
|
|
110
|
+
const cm = app.cm, ctx = context(cm);
|
|
111
|
+
if (!ctx || (!explicit && ctx.kind === 'cmd' && ctx.token.length < 2)) return close();
|
|
112
|
+
const list = candidates(ctx);
|
|
113
|
+
if (!list.length) return close();
|
|
114
|
+
if (!box) box = document.body.appendChild(el('ul', { className: 'complete', role: 'listbox' }));
|
|
115
|
+
const wasOpen = !!active;
|
|
116
|
+
active = { ctx, list, sel: 0, line: cm.getCursor().line };
|
|
117
|
+
if (!wasOpen) cm.addKeyMap(keys);
|
|
118
|
+
box.hidden = false; render();
|
|
119
|
+
const pos = cm.cursorCoords({ line: active.line, ch: ctx.from }, 'window');
|
|
120
|
+
box.style.left = Math.min(pos.left, innerWidth - box.offsetWidth - 8) + 'px';
|
|
121
|
+
box.style.top = (pos.bottom + box.offsetHeight + 4 > innerHeight ? pos.top - box.offsetHeight - 2 : pos.bottom + 2) + 'px';
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function accept() {
|
|
125
|
+
const cm = app.cm, it = active.list[active.sel], ctx = active.ctx, cur = cm.getCursor(), line = cm.getLine(cur.line);
|
|
126
|
+
const word = ctx.kind === 'cmd' ? /[a-zA-Z@*]/ : /[^\s,{}]/;
|
|
127
|
+
let to = cur.ch; while (to < line.length && word.test(line[to])) to++;
|
|
128
|
+
const from = { line: cur.line, ch: ctx.from };
|
|
129
|
+
close();
|
|
130
|
+
if (ctx.kind === 'cmd') {
|
|
131
|
+
cm.replaceRange(it.text + '{}'.repeat(it.args || 0), from, { line: cur.line, ch: to });
|
|
132
|
+
if (it.args) cm.setCursor({ line: cur.line, ch: ctx.from + it.text.length + 1 });
|
|
133
|
+
if (it.text === 'begin') setTimeout(() => complete(true), 0);
|
|
134
|
+
} else if (ctx.kind === 'begin') {
|
|
135
|
+
const indent = line.match(/^\s*/)[0], end = to + (line[to] === '}' ? 1 : 0);
|
|
136
|
+
cm.replaceRange(`${it.text}}\n${indent} \n${indent}\\end{${it.text}}`, from, { line: cur.line, ch: end });
|
|
137
|
+
cm.setCursor({ line: cur.line + 1, ch: indent.length + 2 });
|
|
138
|
+
} else {
|
|
139
|
+
const closing = line[to] === '}' || line[to] === ',' ? '' : '}';
|
|
140
|
+
cm.replaceRange(it.text + closing, from, { line: cur.line, ch: to });
|
|
141
|
+
}
|
|
142
|
+
cm.focus();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Typing keeps the list up to date, and opens it after "\ref{", "\cite{", "\begin{", a "," in a key list, or two
|
|
146
|
+
// letters of a command.
|
|
147
|
+
app.cm.on('inputRead', (cm, change) => {
|
|
148
|
+
if (change.origin !== '+input' && change.origin !== '+delete') return;
|
|
149
|
+
const ch = change.text.join('');
|
|
150
|
+
if (active || /[{,]$/.test(ch) || /[a-zA-Z]$/.test(ch)) complete(false);
|
|
151
|
+
});
|
|
152
|
+
app.cm.on('cursorActivity', cm => {
|
|
153
|
+
if (!active) return;
|
|
154
|
+
const ctx = context(cm);
|
|
155
|
+
if (!ctx || cm.getCursor().line !== active.line || ctx.kind !== active.ctx.kind) close(); else complete(true);
|
|
156
|
+
});
|
|
157
|
+
app.cm.on('blur', () => setTimeout(close, 100));
|
|
158
|
+
|
|
159
|
+
Object.assign(app, { complete, refreshCompletions, closeComplete: close });
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// The overlay over the editor that shows a git diff, a commit, or the source changes in the latest compile.
|
|
2
|
+
import { $, el, app, api } from './util.js';
|
|
3
|
+
|
|
4
|
+
let diffPath = null, showingChanges = false;
|
|
5
|
+
|
|
6
|
+
function open(title, canOpen) {
|
|
7
|
+
$('diffTitle').textContent = title; $('diffOpen').hidden = !canOpen;
|
|
8
|
+
$('diffView').hidden = false; $('diffBody').scrollTop = 0;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function renderDiff(text) {
|
|
12
|
+
$('diffBody').replaceChildren(...text.split('\n').map(l => el('div', {
|
|
13
|
+
className: l.startsWith('@@') ? 'hunk'
|
|
14
|
+
: /^(---$|diff |index |--- |\+\+\+ |new file|deleted file|similarity|rename |commit |Author:|Date:)/.test(l) ? 'meta'
|
|
15
|
+
: l.startsWith('+') ? 'add' : l.startsWith('-') ? 'del' : '',
|
|
16
|
+
}, l || ' ')));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// A path relative to the git top level -> the editor's path, or null when it is outside the project.
|
|
20
|
+
const editorPath = p => {
|
|
21
|
+
const g = app.git; if (!g || !g.prefix) return p;
|
|
22
|
+
return p.startsWith(g.prefix + '/') ? p.slice(g.prefix.length + 1) : null;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export async function showDiff(path, staged) {
|
|
26
|
+
const r = await api(`/api/git/diff?path=${encodeURIComponent(path)}&staged=${staged ? 1 : 0}`);
|
|
27
|
+
if (!r.ok) return app.gitOut(r.error, 'err');
|
|
28
|
+
diffPath = path; showingChanges = false;
|
|
29
|
+
renderDiff(r.diff); open(`${path} — ${staged ? 'staged' : 'working tree'}`, !!editorPath(path));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function showCommit(rev, subject) {
|
|
33
|
+
const r = await api('/api/git/show?rev=' + encodeURIComponent(rev));
|
|
34
|
+
if (!r.ok) return app.gitOut(r.error, 'err');
|
|
35
|
+
diffPath = null; showingChanges = false;
|
|
36
|
+
renderDiff(r.diff); open(`${rev} ${subject}`, false);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Word-level diff of the sources between the last two compiles that differ.
|
|
40
|
+
export async function showChanges() {
|
|
41
|
+
const r = await api('/api/changes');
|
|
42
|
+
if (!r.ok) return;
|
|
43
|
+
diffPath = null; showingChanges = true;
|
|
44
|
+
const body = $('diffBody'), when = t => new Date(t * 1000).toLocaleString(), rows = [];
|
|
45
|
+
const line = (cls, text) => { const d = el('div', { className: cls }, text); rows.push(d); return d; };
|
|
46
|
+
let title = 'Changes in the latest compile';
|
|
47
|
+
if (!r.baseline) line('meta', 'No earlier compile to compare with yet. Changes appear after the next compile that changes the source.');
|
|
48
|
+
else {
|
|
49
|
+
title += ` (${when(r.to)}, vs ${when(r.from)})`;
|
|
50
|
+
if (!r.files.length) line('meta', 'No source changes.');
|
|
51
|
+
r.files.forEach(f => {
|
|
52
|
+
line('cfile', `${f.path}${f.status === 'modified' ? '' : ' (' + f.status + ')'}`);
|
|
53
|
+
f.hunks.forEach(h => {
|
|
54
|
+
const go = () => { if (f.status !== 'deleted') { closeDiff(); app.openFile(f.path, h.line, { flash: true }); } };
|
|
55
|
+
line('hunk chunk', `line ${h.line}`).onclick = go;
|
|
56
|
+
const d = line('cbody chunk', ''); d.onclick = go;
|
|
57
|
+
h.segs.forEach(([kind, text]) => d.append(el('span', { className: kind === 'eq' ? '' : kind === 'add' ? 'ins' : 'rem' }, text)));
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
body.replaceChildren(...rows);
|
|
62
|
+
open(title, false);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function closeDiff() { $('diffView').hidden = true; diffPath = null; showingChanges = false; app.cm.refresh(); }
|
|
66
|
+
const refreshChangesIfOpen = () => { if (showingChanges && !$('diffView').hidden) showChanges(); };
|
|
67
|
+
|
|
68
|
+
$('changesBtn').onclick = showChanges;
|
|
69
|
+
$('diffClose').onclick = closeDiff;
|
|
70
|
+
$('diffOpen').onclick = () => { const p = editorPath(diffPath); closeDiff(); if (p) app.openFile(p); };
|
|
71
|
+
|
|
72
|
+
Object.assign(app, { showDiff, showCommit, showChanges, closeDiff, refreshChangesIfOpen, isDiffOpen: () => !$('diffView').hidden });
|