acme: preserve window position and selection during Get

Before, executing Get in a file rewound the window offset and
selection to the start of the file.

After this CL, Get preserves the window offset and selection,
where preserve is defined as "the same line number and rune
offset within the line". So if the window started at line 10
before and the selection was line 13 chars 5-7, then that
will still be true after Get, provided the new content is large
enough.

This should help the common situation of plumbing a
compiler error, realizing the window is out of date,
clicking Get, and then losing the positioning from the
plumb operation.
This commit is contained in:
Russ Cox 2017-11-02 11:58:07 -04:00
parent 805d91d359
commit 3d6e5cb56a
5 changed files with 103 additions and 18 deletions

View file

@ -573,15 +573,27 @@ zeroxx(Text *et, Text *t, Text *_1, int _2, int _3, Rune *_4, int _5)
winunlock(t->w);
}
typedef struct TextAddr TextAddr;
struct TextAddr {
long lorigin; // line+rune for origin
long rorigin;
long lq0; // line+rune for q0
long rq0;
long lq1; // line+rune for q1
long rq1;
};
void
get(Text *et, Text *t, Text *argt, int flag1, int _0, Rune *arg, int narg)
{
char *name;
Rune *r;
int i, n, dirty, samename, isdir;
TextAddr *addr, *a;
Window *w;
Text *u;
Dir *d;
long q0, q1;
USED(_0);
@ -606,6 +618,14 @@ get(Text *et, Text *t, Text *argt, int flag1, int _0, Rune *arg, int narg)
return;
}
}
addr = emalloc((t->file->ntext)*sizeof(TextAddr));
for(i=0; i<t->file->ntext; i++) {
a = &addr[i];
u = t->file->text[i];
a->lorigin = nlcount(u, 0, u->org, &a->rorigin);
a->lq0 = nlcount(u, 0, u->q0, &a->rq0);
a->lq1 = nlcount(u, u->q0, u->q1, &a->rq1);
}
r = bytetorune(name, &n);
for(i=0; i<t->file->ntext; i++){
u = t->file->text[i];
@ -631,8 +651,18 @@ get(Text *et, Text *t, Text *argt, int flag1, int _0, Rune *arg, int narg)
for(i=0; i<t->file->ntext; i++){
u = t->file->text[i];
textsetselect(&u->w->tag, u->w->tag.file->b.nc, u->w->tag.file->b.nc);
if(samename) {
a = &addr[i];
// warning(nil, "%d %d %d %d %d %d\n", a->lorigin, a->rorigin, a->lq0, a->rq0, a->lq1, a->rq1);
q0 = nlcounttopos(u, 0, a->lq0, a->rq0);
q1 = nlcounttopos(u, q0, a->lq1, a->rq1);
textsetselect(u, q0, q1);
q0 = nlcounttopos(u, 0, a->lorigin, a->rorigin);
textsetorigin(u, q0, FALSE);
}
textscrdraw(u);
}
free(addr);
xfidlog(w, "get");
}