Quantcast

Cursor anomoly: apparent and actual positions differ

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Cursor anomoly: apparent and actual positions differ

Michael Henry-5
All,

I've noticed some strange cursor behavior when following one of
the Wiki tips.  Below is a 26-line-long file to describe and
demonstrate the problem.

" ----------- start of "cursor-pos-anomoly.txt" ------------------
" To show anomoly, launch Vim as:
"   vim -u NONE cursor-pos-anomoly.txt "+source %"
"
" This demonstrates a cursor anomoly (apparent vs. actual position).
"
set nocp | set hls | /^" \(Start\|End\)
"
" From http://vim.wikia.com/wiki/Avoid_scrolling_when_switch_buffers:
" When switching buffers, preserve window view.
if v:version >= 700
  au BufLeave * let b:winview = winsaveview()
  au BufEnter * if exists('b:winview') | call winrestview(b:winview) | endif
endif
"
" You should initially find the cursor on the following line:
" Start on this line
"
" End seemingly on this line after running the two commands below:
"
"   :copen
"   CTRL-W CTRL-W
"
" But you're actually still on the "Start" line, which you can see by
" pressing one of these three keys, for example:  C D j
" ------------- end of "cursor-pos-anomoly.txt" ------------------

The fact that the cursor appears to be on one line but is
functionally on another seems like a bug to me.

As a separate issue, I don't see anything wrong with the logic
in the wiki tip, but perhaps someone has a better suggestion to
achieve the tip's goal.

Thanks,
Michael Henry

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Cursor anomoly: apparent and actual positions differ

John Beckett-2
I confirm there is a bug (Vim 7.3.509 on Windows).

I slightly simplified the example to show the minimum that
demonstrates the problem, as below:

" ----------- start bug.txt ------------------
" To show anomaly, launch Vim as:
"   vim -N -u NONE bug.txt
" and enter:
"   :so %
"   :13
"
if v:version >= 700
  au BufLeave * let b:winview = winsaveview()
  au BufEnter * if exists('b:winview') | call winrestview(b:winview) | endif
endif
"
" Now enter:
"   :copen
"   CTRL-W CTRL-W
" Stop and see where cursor is, then press j
" which shows that cursor was NOT where it appeared to be.
" First pressing Ctrl-L or entering :redraw do not help.
" ----------- end bug.txt --------------------

There is no problem if use ':new' or ':rightbelow new' instead
of ':copen'. Seems the quickfix window is part of problem.

I can also see the problem if start Vim normally, then just yank
the two au commands and use :@" to source them, then enter
:copen Ctrl-W w. I have seen the cursor end up in the tildes
after end-of-file.

Using ':echo b:winview' shows:
    {'lnum': 13, 'leftcol': 0, 'col': 0, 'topfill': 0,
    'topline': 11, 'coladd': 0, 'skipcol': 0, 'curswant': 0}

It looks like topline is wrong.

John

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Cursor anomoly: apparent and actual positions differ

Christian Brabandt
Hi John!

On Mo, 30 Apr 2012, John Beckett wrote:

> I confirm there is a bug (Vim 7.3.509 on Windows).
>
> I slightly simplified the example to show the minimum that
> demonstrates the problem, as below:
>
> " ----------- start bug.txt ------------------
> " To show anomaly, launch Vim as:
> "   vim -N -u NONE bug.txt
> " and enter:
> "   :so %
> "   :13
> "
> if v:version >= 700
>   au BufLeave * let b:winview = winsaveview()
>   au BufEnter * if exists('b:winview') | call winrestview(b:winview) | endif
> endif
> "
> " Now enter:
> "   :copen
> "   CTRL-W CTRL-W
> " Stop and see where cursor is, then press j
> " which shows that cursor was NOT where it appeared to be.
> " First pressing Ctrl-L or entering :redraw do not help.
> " ----------- end bug.txt --------------------
>
> There is no problem if use ':new' or ':rightbelow new' instead
> of ':copen'. Seems the quickfix window is part of problem.
>
> I can also see the problem if start Vim normally, then just yank
> the two au commands and use :@" to source them, then enter
> :copen Ctrl-W w. I have seen the cursor end up in the tildes
> after end-of-file.
>
> Using ':echo b:winview' shows:
>     {'lnum': 13, 'leftcol': 0, 'col': 0, 'topfill': 0,
>     'topline': 11, 'coladd': 0, 'skipcol': 0, 'curswant': 0}
>
> It looks like topline is wrong.

Looks like a redraw issue to me. This fixes it for me:
diff --git a/src/eval.c b/src/eval.c
--- a/src/eval.c
+++ b/src/eval.c
@@ -18507,7 +18507,7 @@
        check_cursor();
        changed_cline_bef_curs();
        invalidate_botline();
-       redraw_later(VALID);
+       redraw_later(NOT_VALID);
 
        if (curwin->w_topline == 0)
            curwin->w_topline = 1;


regards,
Christian

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Cursor anomoly: apparent and actual positions differ

Bram Moolenaar

Christian Brabandt wrote:

> On Mo, 30 Apr 2012, John Beckett wrote:
>
> > I confirm there is a bug (Vim 7.3.509 on Windows).
> >
> > I slightly simplified the example to show the minimum that
> > demonstrates the problem, as below:
> >
> > " ----------- start bug.txt ------------------
> > " To show anomaly, launch Vim as:
> > "   vim -N -u NONE bug.txt
> > " and enter:
> > "   :so %
> > "   :13
> > "
> > if v:version >= 700
> >   au BufLeave * let b:winview = winsaveview()
> >   au BufEnter * if exists('b:winview') | call winrestview(b:winview) | endif
> > endif
> > "
> > " Now enter:
> > "   :copen
> > "   CTRL-W CTRL-W
> > " Stop and see where cursor is, then press j
> > " which shows that cursor was NOT where it appeared to be.
> > " First pressing Ctrl-L or entering :redraw do not help.
> > " ----------- end bug.txt --------------------
> >
> > There is no problem if use ':new' or ':rightbelow new' instead
> > of ':copen'. Seems the quickfix window is part of problem.
> >
> > I can also see the problem if start Vim normally, then just yank
> > the two au commands and use :@" to source them, then enter
> > :copen Ctrl-W w. I have seen the cursor end up in the tildes
> > after end-of-file.
> >
> > Using ':echo b:winview' shows:
> >     {'lnum': 13, 'leftcol': 0, 'col': 0, 'topfill': 0,
> >     'topline': 11, 'coladd': 0, 'skipcol': 0, 'curswant': 0}
> >
> > It looks like topline is wrong.
>
> Looks like a redraw issue to me. This fixes it for me:
> diff --git a/src/eval.c b/src/eval.c
> --- a/src/eval.c
> +++ b/src/eval.c
> @@ -18507,7 +18507,7 @@
>         check_cursor();
>         changed_cline_bef_curs();
>         invalidate_botline();
> -       redraw_later(VALID);
> +       redraw_later(NOT_VALID);
>  
>         if (curwin->w_topline == 0)
>             curwin->w_topline = 1;

Perhaps this should call changed_window_setting() instead of the
individual items marked as changed?

--
Close your shells, or I'll kill -9 you
Tomorrow I'll quota you
Remember the disks'll always be full
And then while I'm away
I'll write ~ everyday
And I'll send-pr all my buggings to you.
    [ CVS log "Beatles style" for FreeBSD ports/INDEX, Satoshi Asami ]

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Cursor anomoly: apparent and actual positions differ

Christian Brabandt
Hi Bram!

On Mi, 02 Mai 2012, Bram Moolenaar wrote:

>
> Christian Brabandt wrote:
>
> > On Mo, 30 Apr 2012, John Beckett wrote:
> >
> > > I confirm there is a bug (Vim 7.3.509 on Windows).
> > >
> > > I slightly simplified the example to show the minimum that
> > > demonstrates the problem, as below:
> > >
> > > " ----------- start bug.txt ------------------
> > > " To show anomaly, launch Vim as:
> > > "   vim -N -u NONE bug.txt
> > > " and enter:
> > > "   :so %
> > > "   :13
> > > "
> > > if v:version >= 700
> > >   au BufLeave * let b:winview = winsaveview()
> > >   au BufEnter * if exists('b:winview') | call winrestview(b:winview) | endif
> > > endif
> > > "
> > > " Now enter:
> > > "   :copen
> > > "   CTRL-W CTRL-W
> > > " Stop and see where cursor is, then press j
> > > " which shows that cursor was NOT where it appeared to be.
> > > " First pressing Ctrl-L or entering :redraw do not help.
> > > " ----------- end bug.txt --------------------
> > >
> > > There is no problem if use ':new' or ':rightbelow new' instead
> > > of ':copen'. Seems the quickfix window is part of problem.
> > >
> > > I can also see the problem if start Vim normally, then just yank
> > > the two au commands and use :@" to source them, then enter
> > > :copen Ctrl-W w. I have seen the cursor end up in the tildes
> > > after end-of-file.
> > >
> > > Using ':echo b:winview' shows:
> > >     {'lnum': 13, 'leftcol': 0, 'col': 0, 'topfill': 0,
> > >     'topline': 11, 'coladd': 0, 'skipcol': 0, 'curswant': 0}
> > >
> > > It looks like topline is wrong.
> >
> > Looks like a redraw issue to me. This fixes it for me:
> > diff --git a/src/eval.c b/src/eval.c
> > --- a/src/eval.c
> > +++ b/src/eval.c
> > @@ -18507,7 +18507,7 @@
> >         check_cursor();
> >         changed_cline_bef_curs();
> >         invalidate_botline();
> > -       redraw_later(VALID);
> > +       redraw_later(NOT_VALID);
> >  
> >         if (curwin->w_topline == 0)
> >             curwin->w_topline = 1;
>
> Perhaps this should call changed_window_setting() instead of the
> individual items marked as changed?

Yes, this also seems to work.

regards,
Christian

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Loading...