@@ -161,16 +161,21 @@ const path_type_to_class = {
161
161
// Fetches the file tree from the server and schedules a continuation
162
162
// that displays the file selector dropdown(s).
163
163
async function renderPage ( ) {
164
- initDrag ( 'initial' ) ;
164
+ setSplitterDragActions ( 'initial' ) ;
165
165
// TODO: figure out new proportional height from resize
166
- window . onresize = ( ) => initDrag ( 'resize' ) ;
166
+ window . onresize = ( ) => setSplitterDragActions ( 'resize' ) ;
167
167
await fetchFromServer ( { src_file_tree : '' } ,
168
168
file_tree_from_server => setFileTree (
169
169
file_tree_from_server ,
170
170
SourceItem . newFromSearch ( ) ) ) ;
171
171
}
172
172
173
- function initDrag ( debug_reason ) {
173
+ // Set the mouse action (down,move,up) callbacks. When the mouse-down
174
+ // happens, record the location (in variable `md`, which becomes the
175
+ // context for the mouse actions; when the mouse-move happens, set the
176
+ // splitter location based on the initial mouse location (`md`) and
177
+ // where the mouse is now.
178
+ function setSplitterDragActions ( debug_reason ) {
174
179
const src_elem = document . getElementById ( 'src' ) ;
175
180
const splitter_elem = document . getElementById ( 'splitter' ) ;
176
181
const xref_elem = document . getElementById ( 'xref' ) ;
@@ -202,12 +207,7 @@ function initDrag(debug_reason) {
202
207
} ) ;
203
208
}
204
209
205
- document . onmouseup = ( ) => {
206
- document . onmousemove = null ;
207
- document . onmouseup = null ;
208
- }
209
-
210
- document . onmousemove = ( e ) => {
210
+ function adjustSplitterLocation ( e ) {
211
211
var delta_y = e . clientY - md . e . clientY ;
212
212
213
213
// Prevent negative-sized elements.
@@ -216,6 +216,8 @@ function initDrag(debug_reason) {
216
216
// units such as pt or cm to px, but by experiment, 20
217
217
// seems a reasonable amount to leave.
218
218
219
+ const negative_space_buffer = 20 ;
220
+
219
221
// TODO: The following isn't quite right at the bottom: if
220
222
// you move the splitter as far as possible,
221
223
// mouse-up, then move it again, you can make the
@@ -227,18 +229,28 @@ function initDrag(debug_reason) {
227
229
// const scrollbarWidth = window.innerWidth - document.body.clientWidth
228
230
// https://destroytoday.com/blog/100vw-and-the-horizontal-overflow-you-probably-didnt-know-about
229
231
230
- if ( md . srcHeight + delta_y < 20 ) {
231
- delta_y = md . srcTop - md . splitterTop + 20 ;
232
+ if ( md . srcHeight + delta_y < negative_space_buffer ) {
233
+ delta_y = md . srcTop - md . splitterTop + negative_space_buffer ;
232
234
}
233
- if ( md . xrefHeight - delta_y < 20 ) {
234
- delta_y = md . splitterHeight + md . xrefHeight - 20 ;
235
+ if ( md . xrefHeight - delta_y < negative_space_buffer ) {
236
+ delta_y = md . splitterHeight + md . xrefHeight - negative_space_buffer ;
235
237
}
236
238
237
239
src_elem . style . height = ( md . srcHeight + delta_y ) + 'px' ;
238
240
splitter_elem . style . top = ( md . splitterTop + delta_y ) + 'px' ;
239
241
xref_elem . style . height = ( md . xrefHeight - delta_y ) + 'px' ;
240
242
xref_elem . style . top = ( md . xrefTop + delta_y ) + 'px' ; // Not needed for grid layout?
241
243
}
244
+
245
+ document . onmouseup = ( e ) => {
246
+ adjustSplitterLocation ( e ) ;
247
+ document . onmousemove = null ;
248
+ document . onmouseup = null ;
249
+ }
250
+
251
+ document . onmousemove = ( e ) => {
252
+ adjustSplitterLocation ( e ) ;
253
+ }
242
254
}
243
255
}
244
256
@@ -371,7 +383,7 @@ async function displayNewSrcFile(source_item) {
371
383
if ( ! isNaN ( source_item . src_height ) ) { // isNan(null) is true
372
384
// const src = document.getElementById('src');
373
385
// const xref = document.getElementById('xref');
374
- // TODO: see initDrag for how to set the various heights/tops
386
+ // TODO: see setSplitterDragActions() for how to set the various heights/tops
375
387
}
376
388
updateBrowserUrl ( source_item ) ;
377
389
let progress = document . createElement ( 'span' ) ;
0 commit comments