ref: c92ddf3fb5efe2e37ac9e3b1a1129f82de1bf837
parent: e4048c13805a3d4bd5377985232a778604b9e8b8
author: cinap_lenrek <cinap_lenrek@centraldogma>
date: Thu Oct 13 09:49:29 EDT 2011
mothra: support fragment urls
--- a/sys/src/cmd/mothra/mothra.c
+++ b/sys/src/cmd/mothra/mothra.c
@@ -481,14 +481,29 @@
return buf;
}
+void scrollto(char *tag){
+ Rtext *tp;
+ Action *ap;
+ if(current == nil || text == nil)
+ return;
+ if(tag && tag[0]){
+ for(tp=current->text;tp;tp=tp->next){
+ ap=tp->user;
+ if(ap && ap->name && strcmp(ap->name, tag)==0){
+ current->yoffs=tp->topy;
+ break;
+ }
+ }
+ }
+ plsetpostextview(text, current->yoffs);
+ flushimage(display, 1);
+}
+
/*
* selected text should be a url.
- * get the document, scroll to the given tag
*/
void setcurrent(int index, char *tag){
Www *new;
- Rtext *tp;
- Action *ap;
int i;
new=www(index);
if(new==current && (tag==0 || tag[0]==0)) return;
@@ -500,18 +515,8 @@
plinitlabel(cururl, PACKE|EXPAND, current->url->fullname);
if(defdisplay) pldraw(cururl, screen);
plinittextview(text, PACKE|EXPAND, Pt(0, 0), current->text, dolink);
- if(tag && tag[0]){
- for(tp=current->text;tp;tp=tp->next){
- ap=tp->user;
- if(ap && ap->name && strcmp(ap->name, tag)==0){
- current->yoffs=tp->topy;
- break;
- }
- }
- }
- plsetpostextview(text, current->yoffs);
+ scrollto(tag);
donecurs();
- flushimage(display, 1);
}
char *arg(char *s){
do ++s; while(*s==' ' || *s=='\t');
@@ -694,7 +699,12 @@
}
void hiturl(int buttons, char *url, int map){
switch(buttons){
- case 1: geturl(url, GET, 0, 0, map); break;
+ case 1:
+ if(*url == '#')
+ scrollto(url+1);
+ else
+ geturl(url, GET, 0, 0, map);
+ break;
case 2: selurl(url); break;
case 4: message("Button 3 hit on url can't happen!"); break;
}
--- a/sys/src/cmd/mothra/rdhtml.c
+++ b/sys/src/cmd/mothra/rdhtml.c
@@ -628,6 +628,14 @@
pl_pushstate(&g, g.tag);
break;
}
+ if(str=pl_getattr(g.attr, "id")){
+ char swap[NNAME];
+
+ strncpy(swap, g.state->name, sizeof(swap));
+ strncpy(g.state->name, str, sizeof(g.state->name));
+ pl_htmloutput(&g, 0, "", 0);
+ strncpy(g.state->name, swap, sizeof(g.state->name));
+ }
switch(g.tag){
default:
htmlerror(g.name, g.lineno,