summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRodrigo Arias Mallo <rodarima@gmail.com>2024-12-28 00:42:16 +0100
committerRodrigo Arias Mallo <rodarima@gmail.com>2024-12-28 00:48:35 +0100
commit540bad94df96f8bf8b018796d940b52795bb37b0 (patch)
treef25e3b65cf9f8db92e4e09a9d64b233f3dec4cb0 /src
parent140d9ebd912ed803dd916c6ab3783a79a2a724e3 (diff)
Support line fragments in plain text files
Line numbers can be referenced using the fragment L + line number. For example, file://foo/bar.txt#L42 will cause Dillo to scroll to line 42. Fixes: https://github.com/dillo-browser/dillo/issues/330
Diffstat (limited to 'src')
-rw-r--r--src/plain.cc6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/plain.cc b/src/plain.cc
index 8be30cb7..0f5d6a48 100644
--- a/src/plain.cc
+++ b/src/plain.cc
@@ -54,6 +54,7 @@ public:
style::Style *widgetStyle;
size_t Start_Ofs; /* Offset of where to start reading next */
int state;
+ long currentLine;
DilloPlain(BrowserWindow *bw);
~DilloPlain();
@@ -95,6 +96,7 @@ DilloPlain::DilloPlain(BrowserWindow *p_bw)
dw = new Textblock (prefs.limit_text_width);
Start_Ofs = 0;
state = ST_SeekingEol;
+ currentLine = 0L;
Layout *layout = (Layout*) bw->render_layout;
// TODO (1x) No URL?
@@ -142,6 +144,10 @@ void DilloPlain::addLine(char *Buf, uint_t BufSize)
char buf[129];
char *end = Buf + BufSize;
+ currentLine++; /* Start at 1 */
+ sprintf(buf, "L%ld", currentLine); /* Always fits */
+ DW2TB(dw)->addAnchor(buf, widgetStyle);
+
if (BufSize > 0) {
// Limit word length to avoid X11 coordinate
// overflow with extremely long lines.