Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Changes line-numbered output to make line numbers selectable, as discussed in [https://fossil-scm.org/forum/forumpost/dc3da10590]. A couple decisions are needed before deciding whether to merge. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | line-number-selection |
| Files: | files | file ages | folders |
| SHA3-256: |
ec73edd4d09dc7c9f2f3e766d2fa4274 |
| User & Date: | stephan 2020-08-14 11:53:44.797 |
Context
|
2020-08-14
| ||
| 12:21 | Added optional filename parameter to output_text_with_line_numbers() so that it can add the language-X class to the CODE element. ... (check-in: 0b3919f3e1 user: stephan tags: line-number-selection) | |
| 11:53 | Changes line-numbered output to make line numbers selectable, as discussed in [https://fossil-scm.org/forum/forumpost/dc3da10590]. A couple decisions are needed before deciding whether to merge. ... (check-in: ec73edd4d0 user: stephan tags: line-number-selection) | |
|
2020-08-13
| ||
| 11:49 | Re-enabled the discard-all-edits button in wikiedit and made it look the same in both wikiedit and fileedit. ... (check-in: 39a5289b9b user: stephan tags: trunk) | |
Changes
Changes to src/ajax.c.
| ︙ | ︙ | |||
128 129 130 131 132 133 134 |
case AJAX_RENDER_WIKI:
safe_html_context(DOCSRC_FILE);
wiki_render_by_mimetype(pContent, zMime);
break;
default:{
const char *zContent = blob_str(pContent);
if(AJAX_PREVIEW_LINE_NUMBERS & flags){
| | > | 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
case AJAX_RENDER_WIKI:
safe_html_context(DOCSRC_FILE);
wiki_render_by_mimetype(pContent, zMime);
break;
default:{
const char *zContent = blob_str(pContent);
if(AJAX_PREVIEW_LINE_NUMBERS & flags){
output_text_with_line_numbers(zContent,
blob_size(pContent), "on");
}else{
const char *zExt = strrchr(zName,'.');
if(zExt && zExt[1]){
CX("<pre><code class='language-%s'>%h</code></pre>",
zExt+1, zContent);
}else{
CX("<pre>%h</pre>", zContent);
|
| ︙ | ︙ |
Changes to src/attach.c.
| ︙ | ︙ | |||
615 616 617 618 619 620 621 |
blob_zero(&attach);
if( fShowContent ){
const char *z;
content_get(ridSrc, &attach);
blob_to_utf8_no_bom(&attach, 0);
z = blob_str(&attach);
if( zLn ){
| | | 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 |
blob_zero(&attach);
if( fShowContent ){
const char *z;
content_get(ridSrc, &attach);
blob_to_utf8_no_bom(&attach, 0);
z = blob_str(&attach);
if( zLn ){
output_text_with_line_numbers(z, blob_size(&attach), zLn);
}else{
@ <pre>
@ %h(z)
@ </pre>
}
}else if( strncmp(zMime, "image/", 6)==0 ){
int sz = db_int(0, "SELECT size FROM blob WHERE rid=%d", ridSrc);
|
| ︙ | ︙ |
Changes to src/default.css.
| ︙ | ︙ | |||
443 444 445 446 447 448 449 450 451 452 453 454 455 456 |
content:"'";
}
div.selectedText {
font-weight: bold;
color: blue;
background-color: #d5d5ff;
border: 1px blue solid;
}
p.missingPriv {
color: blue;
}
span.wikiruleHead {
font-weight: bold;
}
| > > | 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 |
content:"'";
}
div.selectedText {
font-weight: bold;
color: blue;
background-color: #d5d5ff;
border: 1px blue solid;
border-top: none;
border-bottom: none;
}
p.missingPriv {
color: blue;
}
span.wikiruleHead {
font-weight: bold;
}
|
| ︙ | ︙ | |||
1136 1137 1138 1139 1140 1141 1142 |
vertical-align: sub;
}
.input-with-label > label {
font-weight: initial;
margin: 0 0.25em 0 0.25em;
vertical-align: middle;
}
| > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 |
vertical-align: sub;
}
.input-with-label > label {
font-weight: initial;
margin: 0 0.25em 0 0.25em;
vertical-align: middle;
}
table.numbered-lines td {
font-family: monospace;
line-height: 2.8ex;
white-space: pre;
margin: 0;
white-space: nowrap;
vertical-align: top;
padding: 1em 0 0 0 /*prevents slight overlap at top */;
}
table.numbered-lines td:nth-of-type(1) > span {
display: block;
margin: 0;
padding: 0;
line-height: inherit;
font-size: inherit;
font-family: inherit;
cursor: pointer;
white-space: pre;
}
table.numbered-lines td:nth-of-type(1) > span:hover {
background-color: #777;
opacity: 0.25;
}
table.numbered-lines td:nth-of-type(2) {
padding-left: 1em;
}
table.numbered-lines td:nth-of-type(2) > pre {
margin: 0;
padding: 0;
overflow-x: auto;
overflow-y: hidden /* apparently not needed, but eases my mind */;
padding: 0 0 1em 0 /*prevents a slight underlap at bottom from triggering a scrollar */;
}
table.numbered-lines td:nth-of-type(2) > pre > code {
margin: 0;
padding: 0;
white-space: pre;
line-height: inherit;
font-size: inherit;
font-family: inherit;
}
table.numbered-lines td:nth-of-type(2) > pre > code > * {
box-sizing: border-box;
}
/* if div.selectedText has a top/bottom border, we need to subtract those
from the top margin here... */
/*table.numbered-lines td:nth-of-type(2) > pre > code > div.selectedText {
margin-top: -2px;
}*/
|
Changes to src/diff.c.
| ︙ | ︙ | |||
123 124 125 126 127 128 129 | /* ** Count the number of lines in the input string. Include the last line ** in the count even if it lacks the \n terminator. If an empty string ** is specified, the number of lines is zero. For the purposes of this ** function, a string is considered empty if it contains no characters ** -OR- it contains only NUL characters. */ | | | 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
/*
** Count the number of lines in the input string. Include the last line
** in the count even if it lacks the \n terminator. If an empty string
** is specified, the number of lines is zero. For the purposes of this
** function, a string is considered empty if it contains no characters
** -OR- it contains only NUL characters.
*/
int count_lines(
const char *z,
int n,
int *pnLine
){
int nLine;
const char *zNL, *z2;
for(nLine=0, z2=z; (zNL = strchr(z2,'\n'))!=0; z2=zNL+1, nLine++){}
|
| ︙ | ︙ |
Added src/fossil.numbered-lines.js.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
(function callee(arg){
/* JS counterpart of info.c:output_text_with_line_numbers()
which ties an event handler to the line numbers to allow
selection of individual lines or ranges. */
var tbl = arg || document.querySelectorAll('table.numbered-lines');
if(!tbl) return;
else if(tbl.length>1){
tbl.forEach( (t)=>callee(t) );
return;
}else{
tbl = tbl[0];
}
const tdLn = tbl.querySelector('td'),
urlArgs = (window.location.search||'').replace(/&?\bln=[^&]*/,'');
console.debug("urlArgs =",urlArgs);
tdLn.addEventListener('click', function f(ev){
if(!f.selectedRange){
f.selectedRange = [0,0];
f.mode = 0 /*0=none selected, 1=1 selected, 2=2 selected*/;
}
if('SPAN'===ev.target.tagName){
const rng = f.selectedRange;
const ln = +ev.target.innerText;
if(2===f.mode){/*reset selection*/
f.mode = 0;
//rng[0] = rng[1] = 0;
}
if(0===f.mode){
rng[1] = 0;
rng[0] = ln;
//console.debug("Selected line #"+ln);
history.pushState(undefined,'',urlArgs+'&ln='+ln);
f.mode = 1;
}else if(1===f.mode){
if(ln === rng[0]){/*unselect line*/
//console.debug("Unselected line #"+ln);
history.pushState(undefined,'',urlArgs+'&ln=on');
rng[0] = 0;
f.mode = 0;
}else{
if(ln<rng[0]){
rng[1] = rng[0];
rng[0] = ln;
}else{
rng[1] = ln;
}
//console.debug("Selected range: ",rng);
history.pushState(undefined,'',urlArgs+'&ln='+rng.join('-'));
f.mode = 2;
}
}
}
}, false);
})();
|
Changes to src/info.c.
| ︙ | ︙ | |||
2009 2010 2011 2012 2013 2014 2015 |
}
}
manifest_destroy(pManifest);
return rid;
}
/*
| | > | > > | 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 |
}
}
manifest_destroy(pManifest);
return rid;
}
/*
** The "z" argument is a string that contains the text of a source
** code file and nZ is its length in bytes. This routine appends that
** text to the HTTP reply with line numbering.
**
** zLn is the ?ln= parameter for the HTTP query. If there is an argument,
** then highlight that line number and scroll to it once the page loads.
** If there are two line numbers, highlight the range of lines.
** Multiple ranges can be highlighed by adding additional line numbers
** separated by a non-digit character (also not one of [-,.]).
*/
void output_text_with_line_numbers(
const char *z,
int nZ,
const char *zLn
){
int iStart, iEnd; /* Start and end of region to highlight */
int n = 0; /* Current line number */
int i = 0; /* Loop index */
int iTop = 0; /* Scroll so that this line is on top of screen. */
int nLine = 0;
Stmt q;
iStart = iEnd = atoi(zLn);
db_multi_exec(
"CREATE TEMP TABLE lnos(iStart INTEGER PRIMARY KEY, iEnd INTEGER)");
if( iStart>0 ){
do{
|
| ︙ | ︙ | |||
2056 2057 2058 2059 2060 2061 2062 |
if( db_step(&q)==SQLITE_ROW ){
iStart = db_column_int(&q, 0);
iEnd = db_column_int(&q, 1);
iTop = iStart - 15 + (iEnd-iStart)/4;
if( iTop>iStart - 2 ) iTop = iStart-2;
}
db_finalize(&q);
| > > > > > | > < | > > > > > > > > > > > > > > > > > > > > > > > > > > | 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 |
if( db_step(&q)==SQLITE_ROW ){
iStart = db_column_int(&q, 0);
iEnd = db_column_int(&q, 1);
iTop = iStart - 15 + (iEnd-iStart)/4;
if( iTop>iStart - 2 ) iTop = iStart-2;
}
db_finalize(&q);
CX("<table class='numbered-lines'><tbody><tr><td>");
count_lines(z, nZ, &nLine);
for(i=0; i < nLine; ++i){
CX("<span>%6d</span>", i+1);
}
CX("</td><td><pre><code>");
assert(!n);
while( z[0] ){
n++;
db_prepare(&q,
"SELECT min(iStart), max(iEnd) FROM lnos"
" WHERE iStart <= %d AND iEnd >= %d", n, n);
if( db_step(&q)==SQLITE_ROW ){
iStart = db_column_int(&q, 0);
iEnd = db_column_int(&q, 1);
}
db_finalize(&q);
for(i=0; z[i] && z[i]!='\n'; i++){}
if( n==iTop ) cgi_append_content("<span id=\"scrollToMe\">", -1);
if( n==iStart ){
cgi_append_content("<div class=\"selectedText\">",-1);
}
if( i>0 ){
char *zHtml = htmlize(z, i);
cgi_append_content(zHtml, -1);
fossil_free(zHtml);
}
if( n==iTop ) cgi_append_content("</span>", -1);
if( n==iEnd ) cgi_append_content("</div>", -1);
else cgi_append_content("\n", 1);
z += i;
if( z[0]=='\n' ) z++;
}
if( n<iEnd ) cgi_printf("</div>");
CX("</code></pre></td></tr></tbody></table>\n");
if( db_int(0, "SELECT EXISTS(SELECT 1 FROM lnos)") ){
builtin_request_js("scroll.js");
}
builtin_request_js("fossil.numbered-lines.js");
}
/*
** COMMAND: test-line-numbers
**
** Usage: %fossil test-line-numbers FILE ?LN-SPEC?
**
*/
void cmd_test_line_numbers(void){
Blob content = empty_blob;
const char * zLn = "";
const char * zFilename = 0;
if(g.argc < 3){
usage("FILE");
}else if(g.argc>3){
zLn = g.argv[3];
}
db_find_and_open_repository(0,0);
zFilename = g.argv[2];
fossil_print("%s %s\n", zFilename, zLn);
blob_read_from_file(&content, zFilename, ExtFILE);
output_text_with_line_numbers(blob_str(&content), blob_size(&content), zLn);
blob_reset(&content);
fossil_print("%b\n", cgi_output_blob());
}
/*
** WEBPAGE: artifact
** WEBPAGE: file
** WEBPAGE: whatis
**
** Typical usage:
|
| ︙ | ︙ | |||
2396 2397 2398 2399 2400 2401 2402 |
zFileName = db_text(0,
"SELECT name FROM mlink, filename"
" WHERE filename.fnid=mlink.fnid"
" AND mlink.fid=%d",
rid);
zExt = zFileName ? strrchr(zFileName, '.') : 0;
if( zLn ){
| | | 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 |
zFileName = db_text(0,
"SELECT name FROM mlink, filename"
" WHERE filename.fnid=mlink.fnid"
" AND mlink.fid=%d",
rid);
zExt = zFileName ? strrchr(zFileName, '.') : 0;
if( zLn ){
output_text_with_line_numbers(z, blob_size(&content), zLn);
}else if( zExt && zExt[1] ){
@ <pre>
@ <code class="language-%s(zExt+1)">%h(z)</code>
@ </pre>
}else{
@ <pre>
@ %h(z)
|
| ︙ | ︙ |
Changes to src/main.mk.
| ︙ | ︙ | |||
223 224 225 226 227 228 229 230 231 232 233 234 235 236 | $(SRCDIR)/default.css \ $(SRCDIR)/diff.tcl \ $(SRCDIR)/forum.js \ $(SRCDIR)/fossil.bootstrap.js \ $(SRCDIR)/fossil.confirmer.js \ $(SRCDIR)/fossil.dom.js \ $(SRCDIR)/fossil.fetch.js \ $(SRCDIR)/fossil.page.fileedit.js \ $(SRCDIR)/fossil.page.forumpost.js \ $(SRCDIR)/fossil.page.wikiedit.js \ $(SRCDIR)/fossil.storage.js \ $(SRCDIR)/fossil.tabs.js \ $(SRCDIR)/graph.js \ $(SRCDIR)/href.js \ | > | 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | $(SRCDIR)/default.css \ $(SRCDIR)/diff.tcl \ $(SRCDIR)/forum.js \ $(SRCDIR)/fossil.bootstrap.js \ $(SRCDIR)/fossil.confirmer.js \ $(SRCDIR)/fossil.dom.js \ $(SRCDIR)/fossil.fetch.js \ $(SRCDIR)/fossil.numbered-lines.js \ $(SRCDIR)/fossil.page.fileedit.js \ $(SRCDIR)/fossil.page.forumpost.js \ $(SRCDIR)/fossil.page.wikiedit.js \ $(SRCDIR)/fossil.storage.js \ $(SRCDIR)/fossil.tabs.js \ $(SRCDIR)/graph.js \ $(SRCDIR)/href.js \ |
| ︙ | ︙ |
Changes to src/scroll.js.
1 | /* Cause the page to scroll so that the #scrollToMe is visible */ | | | 1 2 |
/* Cause the page to scroll so that the #scrollToMe is visible */
(document.getElementById('scrollToMe')||document.body).scrollIntoView(true);
|
Changes to win/Makefile.mingw.
| ︙ | ︙ | |||
635 636 637 638 639 640 641 642 643 644 645 646 647 648 | $(SRCDIR)/default.css \ $(SRCDIR)/diff.tcl \ $(SRCDIR)/forum.js \ $(SRCDIR)/fossil.bootstrap.js \ $(SRCDIR)/fossil.confirmer.js \ $(SRCDIR)/fossil.dom.js \ $(SRCDIR)/fossil.fetch.js \ $(SRCDIR)/fossil.page.fileedit.js \ $(SRCDIR)/fossil.page.forumpost.js \ $(SRCDIR)/fossil.page.wikiedit.js \ $(SRCDIR)/fossil.storage.js \ $(SRCDIR)/fossil.tabs.js \ $(SRCDIR)/graph.js \ $(SRCDIR)/href.js \ | > | 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 | $(SRCDIR)/default.css \ $(SRCDIR)/diff.tcl \ $(SRCDIR)/forum.js \ $(SRCDIR)/fossil.bootstrap.js \ $(SRCDIR)/fossil.confirmer.js \ $(SRCDIR)/fossil.dom.js \ $(SRCDIR)/fossil.fetch.js \ $(SRCDIR)/fossil.numbered-lines.js \ $(SRCDIR)/fossil.page.fileedit.js \ $(SRCDIR)/fossil.page.forumpost.js \ $(SRCDIR)/fossil.page.wikiedit.js \ $(SRCDIR)/fossil.storage.js \ $(SRCDIR)/fossil.tabs.js \ $(SRCDIR)/graph.js \ $(SRCDIR)/href.js \ |
| ︙ | ︙ |
Changes to win/Makefile.msc.
| ︙ | ︙ | |||
556 557 558 559 560 561 562 563 564 565 566 567 568 569 |
"$(SRCDIR)\default.css" \
"$(SRCDIR)\diff.tcl" \
"$(SRCDIR)\forum.js" \
"$(SRCDIR)\fossil.bootstrap.js" \
"$(SRCDIR)\fossil.confirmer.js" \
"$(SRCDIR)\fossil.dom.js" \
"$(SRCDIR)\fossil.fetch.js" \
"$(SRCDIR)\fossil.page.fileedit.js" \
"$(SRCDIR)\fossil.page.forumpost.js" \
"$(SRCDIR)\fossil.page.wikiedit.js" \
"$(SRCDIR)\fossil.storage.js" \
"$(SRCDIR)\fossil.tabs.js" \
"$(SRCDIR)\graph.js" \
"$(SRCDIR)\href.js" \
| > | 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 |
"$(SRCDIR)\default.css" \
"$(SRCDIR)\diff.tcl" \
"$(SRCDIR)\forum.js" \
"$(SRCDIR)\fossil.bootstrap.js" \
"$(SRCDIR)\fossil.confirmer.js" \
"$(SRCDIR)\fossil.dom.js" \
"$(SRCDIR)\fossil.fetch.js" \
"$(SRCDIR)\fossil.numbered-lines.js" \
"$(SRCDIR)\fossil.page.fileedit.js" \
"$(SRCDIR)\fossil.page.forumpost.js" \
"$(SRCDIR)\fossil.page.wikiedit.js" \
"$(SRCDIR)\fossil.storage.js" \
"$(SRCDIR)\fossil.tabs.js" \
"$(SRCDIR)\graph.js" \
"$(SRCDIR)\href.js" \
|
| ︙ | ︙ | |||
1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 | echo "$(SRCDIR)\default.css" >> $@ echo "$(SRCDIR)\diff.tcl" >> $@ echo "$(SRCDIR)\forum.js" >> $@ echo "$(SRCDIR)\fossil.bootstrap.js" >> $@ echo "$(SRCDIR)\fossil.confirmer.js" >> $@ echo "$(SRCDIR)\fossil.dom.js" >> $@ echo "$(SRCDIR)\fossil.fetch.js" >> $@ echo "$(SRCDIR)\fossil.page.fileedit.js" >> $@ echo "$(SRCDIR)\fossil.page.forumpost.js" >> $@ echo "$(SRCDIR)\fossil.page.wikiedit.js" >> $@ echo "$(SRCDIR)\fossil.storage.js" >> $@ echo "$(SRCDIR)\fossil.tabs.js" >> $@ echo "$(SRCDIR)\graph.js" >> $@ echo "$(SRCDIR)\href.js" >> $@ | > | 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 | echo "$(SRCDIR)\default.css" >> $@ echo "$(SRCDIR)\diff.tcl" >> $@ echo "$(SRCDIR)\forum.js" >> $@ echo "$(SRCDIR)\fossil.bootstrap.js" >> $@ echo "$(SRCDIR)\fossil.confirmer.js" >> $@ echo "$(SRCDIR)\fossil.dom.js" >> $@ echo "$(SRCDIR)\fossil.fetch.js" >> $@ echo "$(SRCDIR)\fossil.numbered-lines.js" >> $@ echo "$(SRCDIR)\fossil.page.fileedit.js" >> $@ echo "$(SRCDIR)\fossil.page.forumpost.js" >> $@ echo "$(SRCDIR)\fossil.page.wikiedit.js" >> $@ echo "$(SRCDIR)\fossil.storage.js" >> $@ echo "$(SRCDIR)\fossil.tabs.js" >> $@ echo "$(SRCDIR)\graph.js" >> $@ echo "$(SRCDIR)\href.js" >> $@ |
| ︙ | ︙ |