summaryrefslogtreecommitdiff
path: root/sys/src
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@centraldogma>2011-10-13 13:49:29 +0200
committercinap_lenrek <cinap_lenrek@centraldogma>2011-10-13 13:49:29 +0200
commitc92ddf3fb5efe2e37ac9e3b1a1129f82de1bf837 (patch)
treeb5b063c654e7ed078495ab6cfde48657bcb472c6 /sys/src
parente4048c13805a3d4bd5377985232a778604b9e8b8 (diff)
mothra: support fragment urls
Diffstat (limited to 'sys/src')
-rw-r--r--sys/src/cmd/mothra/mothra.c40
-rw-r--r--sys/src/cmd/mothra/rdhtml.c8
2 files changed, 33 insertions, 15 deletions
diff --git a/sys/src/cmd/mothra/mothra.c b/sys/src/cmd/mothra/mothra.c
index ec64ee444..a3cd22088 100644
--- a/sys/src/cmd/mothra/mothra.c
+++ b/sys/src/cmd/mothra/mothra.c
@@ -481,14 +481,29 @@ char *genwww(Panel *, int index){
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 @@ void setcurrent(int index, char *tag){
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 docmd(Panel *p, char *s){
}
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;
}
diff --git a/sys/src/cmd/mothra/rdhtml.c b/sys/src/cmd/mothra/rdhtml.c
index 6a8343f34..96407ac04 100644
--- a/sys/src/cmd/mothra/rdhtml.c
+++ b/sys/src/cmd/mothra/rdhtml.c
@@ -628,6 +628,14 @@ void plrdhtml(char *name, int fd, Www *dst){
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,