diff --git a/lib/hypertextview.vala b/lib/hypertextview.vala index ffb2c64..d5c3695 100644 --- a/lib/hypertextview.vala +++ b/lib/hypertextview.vala @@ -266,6 +266,12 @@ namespace Xnp { if (!start.backward_chars (6) || start.get_text(location).down () != "http:/") return; + if (!start.backward_chars (7) || start.get_text(location).down () != "https:/") + return; + + if (!start.backward_chars (5) || start.get_text(location).down () != "ftp:/") + return; + tag_timeout_init (); } @@ -275,7 +281,7 @@ namespace Xnp { } /* Text contains links */ - else if (len > 1 && text.contains ("http://")) { + else if (len > 1 && ( text.contains ("ftp://") || text.contains ("httpsp://") || text.contains ("http://") ) { tag_timeout_init (); } } @@ -403,6 +409,52 @@ namespace Xnp { this.buffer.get_iter_at_offset (out iter, 0); + while (iter.forward_search ("ftp://", Gtk.TextSearchFlags.TEXT_ONLY, out start, out end, null)) { + iter = end; + + if (start.begins_tag (this.tag_link)) + continue; + + if (!iter.forward_search (" ", Gtk.TextSearchFlags.TEXT_ONLY, out end, null, null)) { + if (!iter.forward_search ("\n", Gtk.TextSearchFlags.TEXT_ONLY, out end, null, null)) { + this.buffer.get_iter_at_offset (out end, -1); + } + } + else if (iter.forward_search ("\n", Gtk.TextSearchFlags.TEXT_ONLY, out tmp, null, null)) { + if (tmp.get_offset () < end.get_offset ()) { + end = tmp; + } + } + + if (end.get_offset () - start.get_offset () >= 7) + this.buffer.apply_tag (this.tag_link, start, end); + } + + this.buffer.get_iter_at_offset (out iter, 0); + + while (iter.forward_search ("https://", Gtk.TextSearchFlags.TEXT_ONLY, out start, out end, null)) { + iter = end; + + if (start.begins_tag (this.tag_link)) + continue; + + if (!iter.forward_search (" ", Gtk.TextSearchFlags.TEXT_ONLY, out end, null, null)) { + if (!iter.forward_search ("\n", Gtk.TextSearchFlags.TEXT_ONLY, out end, null, null)) { + this.buffer.get_iter_at_offset (out end, -1); + } + } + else if (iter.forward_search ("\n", Gtk.TextSearchFlags.TEXT_ONLY, out tmp, null, null)) { + if (tmp.get_offset () < end.get_offset ()) { + end = tmp; + } + } + + if (end.get_offset () - start.get_offset () >= 7) + this.buffer.apply_tag (this.tag_link, start, end); + } + + this.buffer.get_iter_at_offset (out iter, 0); + while (iter.forward_search ("http://", Gtk.TextSearchFlags.TEXT_ONLY, out start, out end, null)) { iter = end;