From 540bad94df96f8bf8b018796d940b52795bb37b0 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Sat, 28 Dec 2024 00:42:16 +0100 Subject: 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 --- src/plain.cc | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src') 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. -- cgit v1.2.3