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

@ -1615,7 +1615,7 @@ textsetorigin(Text *t, uint org, int exact)
Rune *r;
uint n;
if(org>0 && !exact){
if(org>0 && !exact && textreadc(t, org-1) != '\n'){
/* org is an estimate of the char posn; find a newline */
/* don't try harder than 256 chars */
for(i=0; i<256 && org<t->file->b.nc; i++){