Author Topic: How can I force cursor to remain visible when I scroll  (Read 1095 times)

jcelle

  • Community Member
  • Posts: 56
  • Hero Points: 3
How can I force cursor to remain visible when I scroll
« on: November 07, 2018, 02:27:34 pm »
Hello,
I could not find any option for this. I would like that the cursor remains visible when I scroll a buffer.
It should move normally upon scrolling but gets blocked on first or last line when it reaches one of these points.

Some steps to visualize:
- place your cursor anywhere in your buffer
- use your mouse wheel to scroll the buffer, up or down
- you will see your cursor move as you scroll
- if you scroll enough your cursor will go out of sight : this is what I would like to avoid and have the cursor remain on the last visible line (which is the top or bottom one, depending in which direction you scrolled).

I can't remember any other editor I used that was not doing this. Slickedit is the only one that "loses" your cursor. Maybe some people find this convenient.

Thanks for any hint.
« Last Edit: November 09, 2018, 03:42:51 pm by jcelle »

Graeme

  • Senior Community Member
  • Posts: 2323
  • Hero Points: 305
Re: How can I force cursor to remain visible when I scroll
« Reply #1 on: November 11, 2018, 11:03:58 am »
Here's a kind of hacked solution you could try.  You can bind wheel-up and wheel-down to the my_scroll_up and my_scroll_down functions below.  If you want the CTRL key to have an effect you need to unbind the Ctrl-wheel events from wfont-zoom-in and out.
Normally, wheel-up and wheel-down should be bound to the fast-scroll function.

Code: [Select]
#include "slick.sh"

#pragma option(strictsemicolons,on)
#pragma option(strict,on)
#pragma option(autodecl,off)
#pragma option(strictparens,on)

int def_scroll_up_with_cursor;

_command void my_scroll_up() name_info(',')
{
   if ( def_scroll_up_with_cursor && !_IsKeyDown(SHIFT) ) {
      if ( p_window_id != _get_focus() ) {
         p_window_id._set_focus();
      }

      if (p_window_id.p_scroll_left_edge >= 0)
          p_window_id.p_scroll_left_edge = -1;

      if ( _IsKeyDown(CTRL) ) {
         cursor_up(4);
      }
      else {
         cursor_up();
      }
      center_line();
   }
   else
   {
      fast_scroll();
   }
}

_command void my_scroll_down() name_info(',')
{
   if ( def_scroll_up_with_cursor && !_IsKeyDown(SHIFT)) {

      if ( p_window_id != _get_focus() ) {
         p_window_id._set_focus();
      }

      if (p_window_id.p_scroll_left_edge >= 0)
          p_window_id.p_scroll_left_edge = -1;

      if ( _IsKeyDown(CTRL) ) {
         cursor_down(4);
      }
      else {
         cursor_down();
      }
      center_line();
   }
   else
   {
      fast_scroll();
   }
}


Graeme

  • Senior Community Member
  • Posts: 2323
  • Hero Points: 305
Re: How can I force cursor to remain visible when I scroll
« Reply #2 on: November 12, 2018, 09:17:40 am »
Here's a slightly improved version.
If you scroll the mouse wheel in an edit window that doesn't have the focus, it will give focus (steal it) to the edit window  - which might not always be what you want.
If you hold down the CTRL key it will scroll slightly faster.  If you hold down the SHIFT key it will do fast-scroll  - which is what it normally does.
If you hold down both CTRL and SHIFT, nothing happens... for me anyway, but you could change the code below if you want.
When trying to bind CTRL plus WheelUp/ Down, in the little key binding window, hold down the Ctrl key then scroll the mouse.
To enable it you need to set def_scroll_up_with_cursor to one using the "set macro variable" command in the macro menu.
I think I will use this myself because it's better for my xretrace vertical scrollbar  - which is here in case you're interested.  I have to write some better info about it.
https://community.slickedit.com/index.php/topic,16598.0.html

Code: [Select]
int def_scroll_up_with_cursor;

_command void my_scroll_up() name_info(',')
{
   if ( def_scroll_up_with_cursor && !_IsKeyDown(SHIFT) ) {
      if ( p_window_id != null && _iswindow_valid(p_window_id) && p_window_id._isEditorCtl()) {
         if ( p_window_id != _get_focus() ) {
            p_window_id._set_focus();
         }

         if (p_window_id.p_scroll_left_edge >= 0)
             p_window_id.p_scroll_left_edge = -1;

         if ( _IsKeyDown(CTRL) )
            cursor_up(8);
         else
            cursor_up();

         //center_line();
         return;
      }
   }
   fast_scroll();
}


_command void my_scroll_down() name_info(',')
{
   if ( def_scroll_up_with_cursor && !_IsKeyDown(SHIFT) ) {
      if ( p_window_id != null && _iswindow_valid(p_window_id) && p_window_id._isEditorCtl()) {
         if ( p_window_id != _get_focus() ) {
            p_window_id._set_focus();
         }

         if (p_window_id.p_scroll_left_edge >= 0)
             p_window_id.p_scroll_left_edge = -1;

         if ( _IsKeyDown(CTRL) )
            cursor_down(8);
         else
            cursor_down();

         //center_line();
         return;
      }
   }
   fast_scroll();
}

Graeme

  • Senior Community Member
  • Posts: 2323
  • Hero Points: 305
Re: How can I force cursor to remain visible when I scroll
« Reply #3 on: November 12, 2018, 09:33:07 am »
By the way, I tried Notepad++, Word, OneNote and Visual Studio and they all scroll the same way slickedit does.  That reminds me, I wonder if I can find a way to restore the cursor to where it was before the mouse wheel scroll moved it.

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 4743
  • Hero Points: 383
Re: How can I force cursor to remain visible when I scroll
« Reply #4 on: November 12, 2018, 02:17:24 pm »
There’s nothing automated for putting the cursor back. You might be able to try to hook into the back/forward stack.

jcelle

  • Community Member
  • Posts: 56
  • Hero Points: 3
Re: How can I force cursor to remain visible when I scroll
« Reply #5 on: November 12, 2018, 03:40:34 pm »
Thanks Graeme for taking the time answering me !
I am not familiar with slick-c but I'll give it a go.

Graeme

  • Senior Community Member
  • Posts: 2323
  • Hero Points: 305
Re: How can I force cursor to remain visible when I scroll
« Reply #6 on: November 12, 2018, 08:17:01 pm »
ok, to load the macro, save it to a file in your configuration folder e.g. myscroll.e and load it using the load module command in the macro menu.

jcelle

  • Community Member
  • Posts: 56
  • Hero Points: 3
Re: How can I force cursor to remain visible when I scroll
« Reply #7 on: November 13, 2018, 02:39:32 pm »
Graeme you are Great.
(In fact I have Standard edition and it was not so easy as only vusrmac.e is available to me: had to record a macro and paste your functions bodies)
I however managed to proceed and it worked ! That's awesome.
I will never thank you enough for this !

I have a subsidiary question:
When I move my cursor up or down (simple up and down arrow) I (now?) notice that when the cursor reaches top or bottom minus 3 lines, pressing up or down does not move the cursor any longer but scrolls the buffer !
Is this standard slickedit (I don't think I had this before) or is it a side effect ?
I'd rather have the buffer scroll on the very first or last line of the buffer, not 3 lines ahead.

Thanks again !
Cheers.

jcelle

  • Community Member
  • Posts: 56
  • Hero Points: 3
Re: How can I force cursor to remain visible when I scroll
« Reply #8 on: November 13, 2018, 02:48:41 pm »
oups... found the option :
Appearance / General / Scroll Style / Scroll When = 0 instead of 2
Strange it is not under
Editing / Cursor Movement
...

Graeme

  • Senior Community Member
  • Posts: 2323
  • Hero Points: 305
Re: How can I force cursor to remain visible when I scroll
« Reply #9 on: November 18, 2018, 06:19:12 am »
I found a problem with diff.  If you scroll with the mouse wheel, diff reports an error - command not allowed in diff mode.  You can use the command below to toggle the key bindings temporarily so that WheelUp and WheelDown bind to fast_scroll.

Code: [Select]
_command void toggle_scroll_with_cursor_keys() name_info(',')
{
   if ( def_scroll_up_with_cursor == 0 ) {
      if (_message_box('Enable scroll with cursor', "", MB_YESNO) != IDYES)  {
         message("Cursor scrolling is disabled");
         return;
      }
      def_scroll_up_with_cursor = 1;
      scroll_up_with_cursor_key_bindings = 1;
   }
   scroll_up_with_cursor_key_bindings = (int)!scroll_up_with_cursor_key_bindings;

   if ( scroll_up_with_cursor_key_bindings ) {
      execute('bind-to-key -r fast_scroll 'event2index(name2event('WHEEL-UP')),"");
      execute('bind-to-key -r fast_scroll 'event2index(name2event('WHEEL-DOWN')),"");
      message("Bind to fast-scroll");
   }
   else {
      execute('bind-to-key -r my_scroll_up 'event2index(name2event('WHEEL-UP')),"");
      execute('bind-to-key -r my_scroll_down 'event2index(name2event('WHEEL-DOWN')),"");
      message("Bind to my-scroll");
   }
}

jcelle

  • Community Member
  • Posts: 56
  • Hero Points: 3
Re: How can I force cursor to remain visible when I scroll
« Reply #10 on: November 18, 2018, 06:50:52 am »
 Thanks ! will update.

Graeme

  • Senior Community Member
  • Posts: 2323
  • Hero Points: 305