Fossil

Check-in [f0984389ba]
Login

Check-in [f0984389ba]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Style improvements. Hooked up the buttons but they don't yet fetch anything.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | diff-js-refactoring
Files: files | file ages | folders
SHA3-256: f0984389baa138b60a386cfdc121077c7549e4f2fbb28a1322dfb6348935a483
User & Date: stephan 2021-09-09 20:03:55.447
Context
2021-09-09
21:36
Implemented fetching and injection of chunks which are smaller than the configured load size, but the results do not play well with our scrolling workaround and need to be revisited after some sleep, perhaps appending/prepending the results directly to the previous/next TR instead of injecting a new one. ... (check-in: da8a0f82b5 user: stephan tags: diff-js-refactoring)
20:03
Style improvements. Hooked up the buttons but they don't yet fetch anything. ... (check-in: f0984389ba user: stephan tags: diff-js-refactoring)
18:50
More jchunk button style tweaks. ... (check-in: 7cc651c87f user: stephan tags: diff-js-refactoring)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/default.css.
533
534
535
536
537
538
539


540
541
542
543
544
545
546
547
548
549
550
551






552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582








583
584
585
586
587
588
589
590
591
592
593
594


595

596

597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
}

/* Rules governing diff layout and colors */
table.diff {
  width: 100%;
  border-spacing: 0;
  border: 1px solid black;


  padding: 0 0.5em;
}
table.diff td {
  vertical-align: top;
}
table.diff pre {
  margin: 0 0 0 0;
}
tr.diffskip.jchunk:hover {
  /* jchunk gets added from JS to diffskip rows when they are
     plugged into the /jchunk route and removed after that data
     is fetched. */






}
tr.diffskip.jchunk:hover {
  /*background-color: rgba(127,127,127,0.5);
  cursor: pointer;*/
}
tr.diffskip > td.chunkctrl {
  text-align: left;
  font-family: monospace;
  /* Border is only for visibility during development. Remove it when done. */
  border-width: 1px;
  border-style: dotted;
}
tr.diffskip > td.chunkctrl > div {
  /* Exists solely for layout purposes. */
}
tr.diffskip > td.chunkctrl > div > .button {
  min-width: 2.5em;
  max-width: 2.5em;
  text-align: center;
  display: inline-block;
  padding: 0.1em 1em;
  margin: 0 1em 0 0;
  background-color: rgba(127,127,127,0.2);
  border-style: outset;
  border-width: 0;
  /*border-width: 1px;
  border-color: rgba(0,0,0,0);*/
  border-radius: 0.5em;
  opacity: 0.7;
  /*filter: drop-shadow(0.08em 0.08em 0.08em black);*/
}








tr.diffskip > td.chunkctrl > div > .button > span {
  /* In order to increase the glyph size w/o increasing the em-based
     button size or border-radius, we need an extra layer of DOM
     element for the glyph. */
  font-size: 150%;
}
tr.diffskip > td.chunkctrl > div > .button.up:not(.down){
  /* Simulate an arrow pointing up */
  border-radius: 3em 3em 0.25em 0.25em;
}
tr.diffskip > td.chunkctrl > div > .button.down:not(.up){
  /* Simulate an arrow pointing down */


  border-radius: 0.25em 0.25em 3em 3em;

}

tr.diffskip > td.chunkctrl > div > .button:hover {
  /*border-color: rgba(75,75,75,1);*/
  cursor: pointer;
  opacity: 1;
  filter: contrast(3);
}
td.diffln {
  width: 1px;
  text-align: right;
  padding: 0 1em 0 0;
}
td.difflne {
  padding-bottom: 0.4em;
}
td.diffsep {
  width: 1px;
  padding: 0 0.3em 0 1em;
}
td.difftxt pre {
  overflow-x: auto;
}
td.diffln ins {
  background-color: #a0e4b2;
  text-decoration: none;







>
>
|







|



>
>
>
>
>
>








<
<
<




|















>
>
>
>
>
>
>
>
|





|
|
<

|
<
>
>
|
>

>
|















|







533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567



568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603

604
605

606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
}

/* Rules governing diff layout and colors */
table.diff {
  width: 100%;
  border-spacing: 0;
  border: 1px solid black;
}
table.diff td.diffln{
  padding: 0 0.25em 0 0.5em;
}
table.diff td {
  vertical-align: top;
}
table.diff pre {
  margin: 0 0 0 0;
}
tr.diffskip.jchunk {
  /* jchunk gets added from JS to diffskip rows when they are
     plugged into the /jchunk route and removed after that data
     is fetched. */
  background-color: aliceblue;
  padding: 0;
}
tr.diffskip.jchunk > td {
  padding: 0.25em 0.5em;
  margin: 0;
}
tr.diffskip.jchunk:hover {
  /*background-color: rgba(127,127,127,0.5);
  cursor: pointer;*/
}
tr.diffskip > td.chunkctrl {
  text-align: left;
  font-family: monospace;



}
tr.diffskip > td.chunkctrl > div {
  /* Exists solely for layout purposes. */
}
tr.diffskip > td.chunkctrl .button {
  min-width: 2.5em;
  max-width: 2.5em;
  text-align: center;
  display: inline-block;
  padding: 0.1em 1em;
  margin: 0 1em 0 0;
  background-color: rgba(127,127,127,0.2);
  border-style: outset;
  border-width: 0;
  /*border-width: 1px;
  border-color: rgba(0,0,0,0);*/
  border-radius: 0.5em;
  opacity: 0.7;
  /*filter: drop-shadow(0.08em 0.08em 0.08em black);*/
}
tr.diffskip > td.chunkctrl .button.up:not(.down){
  /* Simulate an arrow pointing up */
  border-radius: 3em 3em 0.25em 0.25em;
}
tr.diffskip > td.chunkctrl .button.down:not(.up){
  /* Simulate an arrow pointing down */
  border-radius: 0.25em 0.25em 3em 3em;
}
tr.diffskip > td.chunkctrl .button > span {
  /* In order to increase the glyph size w/o increasing the em-based
     button size or border-radius, we need an extra layer of DOM
     element for the glyph. */
  font-size: 150%;
}
tr.diffskip > td.chunkctrl .button.up:not(.down) > span::before {
  content: '⇡';

}
tr.diffskip > td.chunkctrl .button.down:not(.up) > span::before {

  content: '⇣';
}
tr.diffskip > td.chunkctrl .button.up.down > span::before {
  content: '⇡⇣';
}

tr.diffskip > td.chunkctrl .button:hover {
  /*border-color: rgba(75,75,75,1);*/
  cursor: pointer;
  opacity: 1;
  filter: contrast(3);
}
td.diffln {
  width: 1px;
  text-align: right;
  padding: 0 1em 0 0;
}
td.difflne {
  padding-bottom: 0.4em;
}
td.diffsep {
  width: 1px;
  padding: 0 0.3em 0 0.5em;
}
td.difftxt pre {
  overflow-x: auto;
}
td.diffln ins {
  background-color: #a0e4b2;
  text-decoration: none;
Changes to src/fossil.diff.js.
203
204
205
206
207
208
209
210
211
212
213
214
215
216


217
218
219
220



221




222
223
224
225
226
227
228

229
230
231
232
233
234
235


236
237
238
239
240
241
242
243
244
245
246
247
248
         */
      }
    });
  };
  
  /**
     Installs chunk-loading controls into TR element tr. isSplit is true
     if the parent table is a split diff, else false.)


     The goal is to base these controls closely on github's, a good example
     of which, for use as a model, is:

     https://github.com/msteveb/autosetup/commit/235925e914a52a542


  */
  Diff.ChunkLoadControls = function(isSplit, tr){
    this.isSplit = isSplit;
    this.e = {/*DOM elements*/};



    this.pos = {




      start: +tr.dataset.startln,
      end: +tr.dataset.endln
    };
    tr.$chunker = this /* keep GC from reaping this */;
    this.e.tr = tr;
    D.clearElement(tr);
    this.e.td = D.addClass(

      D.attr(D.td(tr), 'colspan', isSplit ? 5 : 4),
      'chunkctrl'
    );
    this.e.btnWrapper = D.div();
    D.append(this.e.td, this.e.btnWrapper);
    /**
       Depending on various factors, we need one of:



       - A single button to load all lines then remove this control

       - A single button to load the initial chunk

       - Two buttons: one to load upwards, one to load downwards
    */
    if(tr.nextElementSibling){
      this.pos.next = {
        startLhs: extractLineNo(true, true, tr.nextElementSibling, isSplit),
        startRhs: extractLineNo(false, true, tr.nextElementSibling, isSplit)
      };
    }







|
<





>
>



|
>
>
>

>
>
>
>
|
|

<
<


>






|
>
>



|

|







203
204
205
206
207
208
209
210

211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232


233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
         */
      }
    });
  };
  
  /**
     Installs chunk-loading controls into TR element tr. isSplit is true
     if the parent table is a split diff, else false.


     The goal is to base these controls closely on github's, a good example
     of which, for use as a model, is:

     https://github.com/msteveb/autosetup/commit/235925e914a52a542

     Each instance corresponds to a single TR.diffskip element.
  */
  Diff.ChunkLoadControls = function(isSplit, tr){
    this.isSplit = isSplit;
    this.e = {/*DOM elements*/
      tr: tr
    };
    tr.$chunker = this /* keep GC from reaping this */;
    this.pos = {
      /* These line numbers correspond to the LHS file. Because the
         contents are common to both sides, we have the same number
         for the RHS, but need to extract those line numbers from the
         neighboring TR blocks */
      startLhs: +tr.dataset.startln,
      endLhs: +tr.dataset.endln
    };


    D.clearElement(tr);
    this.e.td = D.addClass(
      /* Holder for our UI controls */
      D.attr(D.td(tr), 'colspan', isSplit ? 5 : 4),
      'chunkctrl'
    );
    this.e.btnWrapper = D.div();
    D.append(this.e.td, this.e.btnWrapper);
    /**
       Depending on various factors, we need one or more of:

       - A single button to load the initial chunk incrementally

       - A single button to load all lines then remove this control

       - Two buttons: one to load upwards, one to load downwards

       - A single button to load the final chunk incrementally
    */
    if(tr.nextElementSibling){
      this.pos.next = {
        startLhs: extractLineNo(true, true, tr.nextElementSibling, isSplit),
        startRhs: extractLineNo(false, true, tr.nextElementSibling, isSplit)
      };
    }
257
258
259
260
261
262
263

264
265
266
267
268
269
270

271
272
273
274
275
276

277
278
279
280

281



282






283

284
285
286
287

288
289

290







291
292
293


294
295
296
297
298
299
300
       && ((this.pos.next.startLhs - this.pos.prev.endLhs)
           <= Diff.config.chunkLoadLines)){
      /* Place a single button to load the whole block, rather
         than separate up/down buttons. */
      btnDown = false;
      btnUp = D.append(
        D.addClass(D.span(), 'button', 'up', 'down'),

        D.append(D.span(), this.config.glyphDown, this.config.glyphUp)
      );
    }else{
      /* Figure out which chunk-load buttons to add... */
      if(this.pos.prev){
        btnDown = D.append(
          D.addClass(D.span(), 'button', 'down'),

          D.append(D.span(), this.config.glyphDown)
        );
      }
      if(this.pos.next){
        btnUp = D.append(
          D.addClass(D.span(), 'button', 'up'),

          D.append(D.span(), this.config.glyphUp)
        );
      }
    }

    if(btnDown) D.append(this.e.btnWrapper, btnDown);



    if(btnUp) D.append(this.e.btnWrapper, btnUp);






    D.append(this.e.btnWrapper, D.append(D.span(), JSON.stringify(this.pos)));

  };

  Diff.ChunkLoadControls.prototype = {
    config: {

      glyphUp: '⇡', //'&#uarr;',
      glyphDown: '⇣' //'&#darr;'

    },







    destroy: function(){
      delete this.tr.$chunker;
      D.remove(this.tr);


    },
    /**
       Creates and returns a new TR element, including its TD elements (depending
       on this.isSplit), but does not fill it with any information nor inject it
       into the table (it doesn't know where to do so).
    */
    newTR: function(){







>
|






>
|





>
|



>
|
>
>
>
|
>
>
>
>
>
>
|
>




>


>

>
>
>
>
>
>
>


|
>
>







266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
       && ((this.pos.next.startLhs - this.pos.prev.endLhs)
           <= Diff.config.chunkLoadLines)){
      /* Place a single button to load the whole block, rather
         than separate up/down buttons. */
      btnDown = false;
      btnUp = D.append(
        D.addClass(D.span(), 'button', 'up', 'down'),
        D.span(/*glyph holder*/)
        //D.append(D.span(), this.config.glyphDown, this.config.glyphUp)
      );
    }else{
      /* Figure out which chunk-load buttons to add... */
      if(this.pos.prev){
        btnDown = D.append(
          D.addClass(D.span(), 'button', 'down'),
          D.span(/*glyph holder*/)
          //D.append(D.span(), this.config.glyphDown)
        );
      }
      if(this.pos.next){
        btnUp = D.append(
          D.addClass(D.span(), 'button', 'up'),
          D.span(/*glyph holder*/)
          //D.append(D.span(), this.config.glyphUp)
        );
      }
    }
    if(btnDown){
      D.append(this.e.btnWrapper, btnDown);
      btnDown.addEventListener('click', ()=>this.fetchChunk(1),false);
    }
    if(btnUp){
      D.append(this.e.btnWrapper, btnUp);
      btnUp.addEventListener(
        'click', ()=>this.fetchChunk(btnUp.classList.contains('down') ? 0 : -1),
        false);
    }
    /* For debugging only... */
    this.e.posState = D.span();
    D.append(this.e.btnWrapper, this.e.posState);
    this.updatePosDebug();
  };

  Diff.ChunkLoadControls.prototype = {
    config: {
      /*
      glyphUp: '⇡', //'&#uarr;',
      glyphDown: '⇣' //'&#darr;'
      */
    },
    updatePosDebug: function(){
      if(this.e.posState){
        D.append(D.clearElement(this.e.posState), JSON.stringify(this.pos));
      }
      return this;
    },
    
    destroy: function(){
      delete this.tr.$chunker;
      D.remove(this.e.tr);
      delete this.e;
      delete this.pos;
    },
    /**
       Creates and returns a new TR element, including its TD elements (depending
       on this.isSplit), but does not fill it with any information nor inject it
       into the table (it doesn't know where to do so).
    */
    newTR: function(){
308
309
310
311
312
313
314

















315
316
317
318
319
320
321
322
323
324
325
326
327


328
329

330
331

332
333
334
335
336
337
338
339
340
      }else{
        D.append(D.addClass( D.td(tr), 'diffln', 'difflnl' ), D.pre());
        D.append(D.addClass( D.td(tr), 'diffln', 'difflnr' ), D.pre());
        D.addClass( D.td(tr), 'diffsep' );
        D.append(D.addClass( D.td(tr), 'difftxt', 'difftxtu' ), D.pre());
      }
      return tr;

















    }
  };

  Diff.addDiffSkipHandlers = function(){
    const tables = document.querySelectorAll('table.diff[data-lefthash]');
    if(!tables.length) return F;
    const addDiffSkipToTr = function f(isSplit, tr){
      D.addClass(tr, 'jchunk');
      //tr.addEventListener('click', f._handler, false);
      /* TODO/in progress... */
      new Diff.ChunkLoadControls(isSplit, tr);
    };
    tables.forEach(function(table){


      table.querySelectorAll('tr.diffskip[data-startln]').forEach(function(tr){
        addDiffSkipToTr(table.classList.contains('splitdiff')/*else udiff*/, tr);

      });
    });

  };

  Diff.addDiffSkipHandlers();
});

/**
   2021-09-07: refactoring the following for use in the higher-level
   fossil.*.js framework is pending. For now it's a copy/paste copy
   of diff.js.







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>




|
|
|
<
<
|
<
<

>
>

<
>


>

<







342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372


373


374
375
376
377

378
379
380
381
382

383
384
385
386
387
388
389
      }else{
        D.append(D.addClass( D.td(tr), 'diffln', 'difflnl' ), D.pre());
        D.append(D.addClass( D.td(tr), 'diffln', 'difflnr' ), D.pre());
        D.addClass( D.td(tr), 'diffsep' );
        D.append(D.addClass( D.td(tr), 'difftxt', 'difftxtu' ), D.pre());
      }
      return tr;
    },

    fetchChunk: function(direction/*-1=prev, 1=next, 0=both*/){
      /* Forewarning, this is a bit confusing: when fetching the
         previous lines, we're doing so on behalf of the *next* diff
         chunk (this.pos.next), and vice versa. */
      if(this.isFetching) return this;
      if(direction<0/*prev chunk*/ && !this.pos.next){
        console.error("Attempt to fetch previous diff lines but don't have any.");
        return this;
      }else if(direction>0/*next chunk*/ && !this.pos.prev){
        console.error("Attempt to fetch next diff lines but don't have any.");
        return this;
      }
      console.debug("Going to fetch in direction",direction);
      this.updatePosDebug();
      return this;
    }
  };

  Diff.addDiffSkipHandlers = function(){
    const tables = document.querySelectorAll('table.diff[data-lefthash]:not(.diffskipped)');
    /* Potential performance-related TODO: instead of installing all
       of these at once, install them as the corresponding TR is


       scrolled into view. */


    tables.forEach(function(table){
      D.addClass(table, 'diffskipped'/*avoid processing these more than once */);
      const isSplit = table.classList.contains('splitdiff')/*else udiff*/;
      table.querySelectorAll('tr.diffskip[data-startln]').forEach(function(tr){

        new Diff.ChunkLoadControls(isSplit, D.addClass(tr, 'jchunk'));
      });
    });
    return F;
  };

  Diff.addDiffSkipHandlers();
});

/**
   2021-09-07: refactoring the following for use in the higher-level
   fossil.*.js framework is pending. For now it's a copy/paste copy
   of diff.js.