Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | /jchunk code lines are now injected into the diff view but the line numbers are still TODO. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | diff-js-refactoring |
Files: | files | file ages | folders |
SHA3-256: |
49a60a580de9f3c278a5262f2add9935 |
User & Date: | stephan 2021-09-09 04:58:26 |
Context
2021-09-09
| ||
05:31 | TR-click event handling simplification. ... (check-in: c7f3d042 user: stephan tags: diff-js-refactoring) | |
04:58 | /jchunk code lines are now injected into the diff view but the line numbers are still TODO. ... (check-in: 49a60a58 user: stephan tags: diff-js-refactoring) | |
03:23 | Fetching of /jchunk lines by clicking on the '...' separator of a diff is now working but the fetched lines still need to be integrated into the UI. ... (check-in: 41ef416e user: stephan tags: diff-js-refactoring) | |
Changes
Changes to src/diff.js.
︙ | ︙ | |||
9 10 11 12 13 14 15 | */ window.addEventListener('load',function(){ var SCROLL_LEN = 25; function initDiff(diff){ var txtCols = diff.querySelectorAll('td.difftxt'); var txtPres = diff.querySelectorAll('td.difftxt pre'); var width = 0; | > | > | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | */ window.addEventListener('load',function(){ var SCROLL_LEN = 25; function initDiff(diff){ var txtCols = diff.querySelectorAll('td.difftxt'); var txtPres = diff.querySelectorAll('td.difftxt pre'); var width = 0; if(txtPres.length>=2){ width = Math.max(txtPres[0].scrollWidth, txtPres[1].scrollWidth); } var i; for(i=0; i<txtCols.length; i++){ txtCols[i].style.width = width + 'px'; txtPres[i].style.maxWidth = width + 'px'; txtPres[i].style.width = width + 'px'; txtPres[i].onscroll = function(e){ for(var j=0; j<txtPres.length; j++) txtPres[j].scrollLeft = this.scrollLeft; |
︙ | ︙ |
Changes to src/fossil.diff.js.
︙ | ︙ | |||
19 20 21 22 23 24 25 26 27 28 29 30 31 32 | }; document.querySelectorAll('table.diff').forEach(addToggle); }); window.fossil.onPageLoad(function(){ const F = window.fossil, D = F.dom; const Diff = F.diff = { config: { chunkLoadLines: 20, chunkFetch: { /* Default callack handlers for Diff.fetchArtifactChunk(), unless overridden by options passeed to that function. */ beforesend: function(){}, aftersend: function(){}, | > | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | }; document.querySelectorAll('table.diff').forEach(addToggle); }); window.fossil.onPageLoad(function(){ const F = window.fossil, D = F.dom; const Diff = F.diff = { e:{/*certain cached DOM elements*/}, config: { chunkLoadLines: 20, chunkFetch: { /* Default callack handlers for Diff.fetchArtifactChunk(), unless overridden by options passeed to that function. */ beforesend: function(){}, aftersend: function(){}, |
︙ | ︙ | |||
107 108 109 110 111 112 113 | aftersend: function(){ delete tr.dataset.xfer; Diff.config.chunkFetch.aftersend.apply( this, Array.prototype.slice.call(arguments,0) ); }, onload: function(result){ | | > > > > > > > | > > > > > | > > > | > | > | 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | aftersend: function(){ delete tr.dataset.xfer; Diff.config.chunkFetch.aftersend.apply( this, Array.prototype.slice.call(arguments,0) ); }, onload: function(result){ //console.debug("Chunk result: ",result); D.clearElement(tr); const cols = [], pre = [D.pre()]; if(isSbs){ cols.push(D.addClass(D.td(tr), 'diffln', 'difflnl')); cols.push(D.addClass(D.td(tr), 'difftxt', 'difftxtl')); cols.push(D.addClass(D.td(tr), 'diffsep')); cols.push(D.addClass(D.td(tr), 'diffln', 'difflnr')); cols.push(D.addClass(D.td(tr), 'difftxt', 'difftxtr')); D.append(cols[1], pre[0]); pre.push(D.pre()); D.append(cols[4], pre[1]); }else{ cols.push(D.addClass(D.td(tr), 'diffln', 'difflnl')); cols.push(D.addClass(D.td(tr), 'diffln', 'difflnr')); cols.push(D.addClass(D.td(tr), 'diffsep')); cols.push(D.addClass(D.td(tr), 'difftxt', 'difftxtu')); D.append(cols[3], pre[0]); } const code = result.join('\n')+'\n'; pre.forEach((e)=>e.innerText = code); //console.debug("Updated TR",tr); Diff.initTableDiff(table).checkTableWidth(true); /* At this point we need to: - Read the previous TR, if any, to get the preceeding LHS/RHS line numbers so that we know where to start counting. - If there is no previous TR, we're at the top and we |
︙ | ︙ | |||
138 139 140 141 142 143 144 | (need /\n+/ instead of '\n' b/c of INS/DEL elements) Noting that the result array will end with an empty element due to the trailing \n character, so a call to pop() will be needed. SBS diff col layout: | | | | | | | | | | > > > > > > > | | | < < < < < < < < < < < < < < < < < < < < < < < | < < < < < < | | | | | | | | | | | | | > > > | > > > > > > > > > > > > > > > > > > > > > > > > | > > > > | > > > > > > > > > > > > > > > > | | | 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 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 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 301 302 303 304 305 306 307 308 309 310 311 | (need /\n+/ instead of '\n' b/c of INS/DEL elements) Noting that the result array will end with an empty element due to the trailing \n character, so a call to pop() will be needed. SBS diff col layout: <td.diffln.difflnl><pre>...LHS line numbers...</pre></td> <td.difftxt.difftxtl><pre>...code lines...</pre></td> <td.diffsep>empty for this case (common lines)</td> <td.diffln.difflnr><pre>...RHS line numbers...</pre></td> <td.difftxt.difftxtr><pre>...dupe of col 2</pre></td> Unified diff col layout: <td.diffln.difflnl><pre>LHS line numbers</pre></td> <td.diffln.difflnr><pre>RHS line numbers</pre></td> <td.diffsep>empty in this case (common lines)</td> <td.difftxt.difftxtu><pre>code line</pre></td> C-side TODOs: - If we have that data readily available, it would be a big help (simplify our line calculations) if we stored the line number ranges in the (td.diffln pre) elements as data-startln and data-endln. */ } }); }; Diff.addDiffSkipHandlers = function(){ const tables = document.querySelectorAll('table.diff[data-lefthash]'); if(!tables.length) return F; const addDiffSkipToTr = function f(tr){ D.addClass(tr, 'jchunk'); if(!f._handler){ f._handler = function ff(event){ var e = event.target; while(e && 'TR' !== e.tagName) e = e.parentElement; if(!e){ console.error("Internal event-handling error: didn't find TR target."); return; } e.removeEventListener('click',ff); D.removeClass(e, 'jchunk', 'diffskip'); //console.debug("addDiffSkipToTr() Event:",e, event); fetchTrChunk(e); }; } tr.addEventListener('click', f._handler, false); }; tables.forEach(function(t){ t.querySelectorAll('tr.diffskip[data-startln]').forEach(addDiffSkipToTr); }); }; 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. */ /* Refinements to the display of unified and side-by-side diffs. ** ** In all cases, the table columns tagged with "difftxt" are expanded, ** where possible, to fill the width of the screen. ** ** For a side-by-side diff, if either column is two wide to fit on the ** display, scrollbars are added. The scrollbars are linked, so that ** both sides scroll together. Left and right arrows also scroll. */ window.fossil.onPageLoad(function(){ const SCROLL_LEN = 25; const F = window.fossil, D = F.dom, Diff = F.diff; Diff.checkTableWidth = function f(force){ if(undefined === f.lastWidth){ f.lastWidth = 0; } if( !force && document.body.clientWidth===f.lastWidth ) return this; f.lastWidth = document.body.clientWidth; let w = f.lastWidth*0.5 - 100; if(force || !f.colsL){ f.colsL = document.querySelectorAll('td.difftxtl pre'); } f.colsL.forEach(function(e){ e.style.width = w + "px"; e.style.maxWidth = w + "px"; }); if(force || !f.colsR){ f.colsR = document.querySelectorAll('td.difftxtr pre'); } f.colsR.forEach(function(e){ e.style.width = w + "px"; e.style.maxWidth = w + "px"; }); if(!f.allDiffs){ f.allDiffs = document.querySelectorAll('table.diff'); } w = f.lastWidth; f.allDiffs.forEach((e)=>e.style.maxWidth = w + "px"); return this; }; const scrollLeft = function(event){ //console.debug("scrollLeft",this,event); const table = this.parentElement/*TD*/.parentElement/*TR*/. parentElement/*TBODY*/.parentElement/*TABLE*/; table.$txtPres.forEach((e)=>e.scrollLeft = this.scrollLeft); return false; }; Diff.initTableDiff = function f(diff){ if(!diff){ let i, diffs = document.querySelectorAll('table.splitdiff'); for(i=0; i<diffs.length; ++i){ f.call(this, diffs[i]); } return this; } diff.$txtCols = diff.querySelectorAll('td.difftxt'); diff.$txtPres = diff.querySelectorAll('td.difftxt pre'); var width = 0; diff.$txtPres.forEach(function(e){ if(width < e.scrollWidth) width = e.scrollWidth; }); //console.debug("diff.$txtPres =",diff.$txtPres); diff.$txtCols.forEach((e)=>e.style.width = width + 'px'); diff.$txtPres.forEach(function(e){ e.style.maxWidth = width + 'px'; e.style.width = width + 'px'; if(!e.classList.contains('scroller')){ D.addClass(e, 'scroller'); e.addEventListener('scroll', scrollLeft, false); } }); diff.tabIndex = 0; if(!diff.classList.contains('scroller')){ D.addClass(diff, 'scroller'); diff.addEventListener('keydown', function(e){ e = e || event; const len = {37: -SCROLL_LEN, 39: SCROLL_LEN}[e.keyCode]; if( !len ) return; diff.$txtCols[0].scrollLeft += len; return false; }, false); } return this; } window.fossil.page.tweakSbsDiffs = function(){ document.querySelectorAll('table.splitdiff').forEach((e)=>Diff.initTableDiff); }; Diff.initTableDiff().checkTableWidth(); window.addEventListener('resize', ()=>Diff.checkTableWidth()); }, false); |
Changes to src/info.c.
︙ | ︙ | |||
1913 1914 1915 1916 1917 1918 1919 | Blob line; Blob *pOut; if(0){ ajax_route_error(400, "Just testing client-side error handling."); return; } | | | 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 | Blob line; Blob *pOut; if(0){ ajax_route_error(400, "Just testing client-side error handling."); return; } login_check_credentials(); if( !g.perm.Read ){ ajax_route_error(403, "Access requires Read permissions."); return; } #if 0 /* Re-enable this block once this code is integrated somewhere into |
︙ | ︙ |