Author Topic: mouse wheel scroll should scrol buffer as is (not from location of cursor)  (Read 1986 times)

jcelle

  • Senior Community Member
  • Posts: 253
  • Hero Points: 5
Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
« Reply #15 on: September 21, 2022, 04:42:16 PM »
OK this time it works though it is not really what I am looking for.
Upon xretrace_scroll_xx cursor starts going up or down, only when it reaches the first or last visible line do we have a proper buffer scroll (with cursor maintained visible).
Using the wheel or the scrollbar should be exactly like using the keyboard (ctrl+up/down).
For the wheel I am happy by binding to scroll-up/down.
Only problem is when you use the scrollbar: the behavior is different... it shouldn't be, it is not consistent.
At last I am glad to see I had already inquired about this even though I had forgotten.

Graeme

  • Senior Community Member
  • Posts: 2796
  • Hero Points: 347
Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
« Reply #16 on: September 21, 2022, 09:20:59 PM »
What do you have bound to ctrl+up/down keys?

jcelle

  • Senior Community Member
  • Posts: 253
  • Hero Points: 5
Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
« Reply #17 on: September 21, 2022, 10:22:03 PM »
scroll-up & scroll-down

Graeme

  • Senior Community Member
  • Posts: 2796
  • Hero Points: 347
Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
« Reply #18 on: September 21, 2022, 10:49:47 PM »
Not sure if this is useful to you but I have replaced the calls to cursor-up/down to scroll-up/down and it seems to do what you described.  Just replace this function if you want to use it.


Code: [Select]
static void xscroll(bool is_up)
{
   int k;
   bool xrs = false;
   bool try_call_key = false;
   _str ev;
   if ( block_scroll_flag ) {
      return;
   }

   if ( find_index('xretrace_delete_scrollbar_windows', COMMAND_TYPE) != 0 ) {
      xrs = true;
   }

   if ( xretrace_def_scroll_up_with_cursor && !_IsKeyDown(SHIFT) || _IsKeyDown(CTRL) ) {
      if ( p_window_id != null && _iswindow_valid(p_window_id) && p_window_id._isEditorCtl()) {

         if ( substr(p_window_id.p_buf_name, 1, 1) == "." ) {
            fast_scroll();
            return;
         }
         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;

         int p2;
         save_pos(p2);

         if ( _IsKeyDown(CTRL) )
         {
            if ( is_up )
               for ( k = 0; k < 8; ++k ) {
                  scroll_up();
               }
            else
               for ( k = 0; k < 8; ++k ) {
                  scroll_down();
               }
         }
         else
         {
            if ( is_up )
               scroll_up();
            else
               scroll_down();
         }

         mou_mode(2);
         mou_capture();

         while ( 1 ) {
            ev = get_event('k');
            //say(event2name(ev));
            if ( xrs )
               check_update_xretrace_scrollbar();
            switch( ev ) {
            default:
               try_call_key = true;
               break;
            case RBUTTON_DOWN :
               xretrace_toggle_xscroll();
               break;
            case ESC :
               restore_pos(p2);
               break;
            case ON_KEYSTATECHANGE :
            case MOUSE_MOVE :
               continue;
            case WHEEL_UP :
               if ( _IsKeyDown(CTRL) )
                  for ( k = 0; k < 8; ++k ) {
                     scroll_up();
                  }
               else
                  scroll_up();
               continue;

            case WHEEL_DOWN :
               if ( _IsKeyDown(CTRL) )
                  for ( k = 0; k < 8; ++k ) {
                     scroll_down();
                  }
               else
                  scroll_down();
               continue;

            }
            mou_mode(0);
            mou_release();
            break;
         }
         //center_line();
         block_scroll_flag = true;
         _set_timer(500, xretrace_scroll_callback);
         if ( try_call_key ) {
            call_key(ev);
         }
         return;
      }
   }
   fast_scroll();
}

jcelle

  • Senior Community Member
  • Posts: 253
  • Hero Points: 5
Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
« Reply #19 on: September 22, 2022, 05:44:22 AM »
Thanks Graeme.
I get some errors if I replace this function only :
- Some variable does not have the same name : [xretrace_]def_scroll_up_with_cursor (I could fix that one I guess)
- xretrace_scroll_callback not defined

To match what I expect, your xscroll_up/down macros should check for cursor position and put it back in view before doing the scroll (to compensate any scroll being done by moving the scrollbar before), or start scrolling from current visible position, not from cursor position. Is this what you had in mind ?

Note I gave a look to VS Code : it is even worse, so no need to worry too much, I think I'll be happy to extra click somewhere in the buffer after having moved the scrollbar  ;)
« Last Edit: September 22, 2022, 05:51:59 AM by jcelle »

Graeme

  • Senior Community Member
  • Posts: 2796
  • Hero Points: 347
Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
« Reply #20 on: September 22, 2022, 05:53:38 AM »
ok, I assumed that you had taken the second  of the two pieces of code from the other page  - so try this.  Not sure what you mean about compensating.

Code: [Select]
int xretrace_def_scroll_up_with_cursor;

static int scroll_up_with_cursor_key_bindings;
static bool block_scroll_flag;

void xretrace_scroll_callback()
{
   block_scroll_flag = false;
}


static void xscroll(bool is_up)
{
   int k;
   bool xrs = false;
   bool try_call_key = false;
   _str ev;
   if ( block_scroll_flag ) {
      return;
   }

   if ( find_index('xretrace_delete_scrollbar_windows', COMMAND_TYPE) != 0 ) {
      xrs = true;
   }

   if ( xretrace_def_scroll_up_with_cursor && !_IsKeyDown(SHIFT) || _IsKeyDown(CTRL) ) {
      if ( p_window_id != null && _iswindow_valid(p_window_id) && p_window_id._isEditorCtl()) {

         if ( substr(p_window_id.p_buf_name, 1, 1) == "." ) {
            fast_scroll();
            return;
         }
         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;

         int p2;
         save_pos(p2);

         if ( _IsKeyDown(CTRL) )
         {
            if ( is_up )
               for ( k = 0; k < 8; ++k ) {
                  scroll_up();
               }
            else
               for ( k = 0; k < 8; ++k ) {
                  scroll_down();
               }
         }
         else
         {
            if ( is_up )
               scroll_up();
            else
               scroll_down();
         }

         mou_mode(2);
         mou_capture();

         while ( 1 ) {
            ev = get_event('k');
            //say(event2name(ev));
            if ( xrs )
               check_update_xretrace_scrollbar();
            switch( ev ) {
            default:
               try_call_key = true;
               break;
            case RBUTTON_DOWN :
               xretrace_toggle_xscroll();
               break;
            case ESC :
               restore_pos(p2);
               break;
            case ON_KEYSTATECHANGE :
            case MOUSE_MOVE :
               continue;
            case WHEEL_UP :
               if ( _IsKeyDown(CTRL) )
                  for ( k = 0; k < 8; ++k ) {
                     scroll_up();
                  }
               else
                  scroll_up();
               continue;

            case WHEEL_DOWN :
               if ( _IsKeyDown(CTRL) )
                  for ( k = 0; k < 8; ++k ) {
                     scroll_down();
                  }
               else
                  scroll_down();
               continue;

            }
            mou_mode(0);
            mou_release();
            break;
         }
         //center_line();
         block_scroll_flag = true;
         _set_timer(500, xretrace_scroll_callback);
         if ( try_call_key ) {
            call_key(ev);
         }
         return;
      }
   }
   fast_scroll();
}

_command void xretrace_scroll_up() name_info(','VSARG2_READ_ONLY|VSARG2_REQUIRES_EDITORCTL)
{
   xscroll(true);
}


_command void xretrace_scroll_down() name_info(','VSARG2_READ_ONLY|VSARG2_REQUIRES_EDITORCTL)
{
   xscroll(false);
}

// https://devdocs.io/cpp/

// http://www.google.com/search?q=memcmp&as_sitesearch=cplusplus.com&btnI



_command void xretrace_toggle_xscroll(bool force_xscroll_off = false) name_info(',')
{
   if ( force_xscroll_off ) {
      execute('bind-to-key -r fast_scroll 'event2index(name2event('WHEEL-UP')),"");
      execute('bind-to-key -r fast_scroll 'event2index(name2event('WHEEL-DOWN')),"");
      return;
   }
   if ( xretrace_def_scroll_up_with_cursor == 0 ) {
      if (_message_box('Enable scroll with cursor', "", MB_YESNO) != IDYES)  {
         message("Cursor scrolling is disabled");
         return;
      }
      // xretrace_def_scroll_up_with_cursor is don't care if the keybindings
      xretrace_def_scroll_up_with_cursor = 1;
      scroll_up_with_cursor_key_bindings = 1;  // bind to xscroll
   }
   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 xretrace_scroll_up 'event2index(name2event('WHEEL-UP')),"");
      execute('bind-to-key -r xretrace_scroll_down 'event2index(name2event('WHEEL-DOWN')),"");
      message("Bind to xscroll");
   }
}

jcelle

  • Senior Community Member
  • Posts: 253
  • Hero Points: 5
Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
« Reply #21 on: September 22, 2022, 11:42:19 AM »
ah sorry, me too ! I thought I had taken  the second part - I confused things then (I am testing vs beta on 2 machines...)
So now it works with wheel-xx bound to xretrace_scroll_xx; behavior is same as if it was bound to scroll-xx.
I still have the problem when I manipulate the scrollbar to scroll: cursor vanishes and any keyboard or mouse wheel scrolls back the buffer to the cursor position.
It would be good for me to bind the scrollbar events to scroll-xx functions : they must be bound to fast-scroll.

Graeme

  • Senior Community Member
  • Posts: 2796
  • Hero Points: 347
Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
« Reply #22 on: September 22, 2022, 12:29:38 PM »
I've added some code so that if the shift key is down it scrolls more quickly - might be an alternative to the scrollbar.  Hold the ctrl key down it also scrolls faster but not as fast as shift down.

I suggest you check what happens if  you run the diff command when you have non default bindings to the wheel-xx events.


Code: [Select]
int xretrace_def_scroll_up_with_cursor;

static int scroll_up_with_cursor_key_bindings;
static bool block_scroll_flag;

void xretrace_scroll_callback()
{
   block_scroll_flag = false;
}


static void xscroll(bool is_up)
{
   bool xrs = false;
   bool try_call_key = false;
   _str ev;
   if ( block_scroll_flag ) {
      return;
   }

   if ( find_index('xretrace_delete_scrollbar_windows', COMMAND_TYPE) != 0 ) {
      xrs = true;
   }

   if ( xretrace_def_scroll_up_with_cursor ) {
      if ( p_window_id != null && _iswindow_valid(p_window_id) && p_window_id._isEditorCtl()) {

         if ( substr(p_window_id.p_buf_name, 1, 1) == "." ) {
            fast_scroll();
            return;
         }
         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;

         int p2;
         save_pos(p2);
         if ( _IsKeyDown(CTRL) )
         {
            if ( is_up )
               cursor_up(8);
            else
               cursor_down(8);
         }
         else
         {
            if ( is_up )
               cursor_up();
            else
               cursor_down();
         }

         mou_mode(2);
         mou_capture();

         while ( 1 ) {
            ev = get_event('k');
            //say(event2name(ev));
            if ( xrs )
               check_update_xretrace_scrollbar();
            switch( ev ) {
            default:
               try_call_key = true;
               break;
            case RBUTTON_DOWN :
               xretrace_toggle_xscroll();
               break;
            case ESC :
               restore_pos(p2);
               break;
            case ON_KEYSTATECHANGE :
            case MOUSE_MOVE :
               continue;
            case WHEEL_UP :
               if ( _IsKeyDown(CTRL) )
                  cursor_up(8);
               else if ( _IsKeyDown(SHIFT) )
                  cursor_up(p_window_id.p_Noflines/24);
               else
                  cursor_up();
               continue;

            case WHEEL_DOWN :
               if ( _IsKeyDown(CTRL) )
                  cursor_down(8);
               else if ( _IsKeyDown(SHIFT) )
                  cursor_down(p_window_id.p_Noflines/24);
               else
                  cursor_down();
               continue;

            }
            mou_mode(0);
            mou_release();
            break;
         }
         //center_line();
         block_scroll_flag = true;
         _set_timer(500, xretrace_scroll_callback);
         if ( try_call_key ) {
            call_key(ev);
         }
         return;
      }
   }
   fast_scroll();
}


_command void xretrace_scroll_up() name_info(','VSARG2_READ_ONLY|VSARG2_REQUIRES_EDITORCTL)
{
   xscroll(true);
}


_command void xretrace_scroll_down() name_info(','VSARG2_READ_ONLY|VSARG2_REQUIRES_EDITORCTL)
{
   xscroll(false);
}

// https://devdocs.io/cpp/

// http://www.google.com/search?q=memcmp&as_sitesearch=cplusplus.com&btnI



_command void xretrace_toggle_xscroll(bool force_xscroll_off = false) name_info(',')
{
   if ( force_xscroll_off ) {
      execute('bind-to-key -r fast_scroll 'event2index(name2event('WHEEL-UP')),"");
      execute('bind-to-key -r fast_scroll 'event2index(name2event('WHEEL-DOWN')),"");
      return;
   }
   if ( xretrace_def_scroll_up_with_cursor == 0 ) {
      if (_message_box('Enable scroll with cursor', "", MB_YESNO) != IDYES)  {
         message("Cursor scrolling is disabled");
         return;
      }
      // xretrace_def_scroll_up_with_cursor is don't care if the keybindings
      xretrace_def_scroll_up_with_cursor = 1;
      scroll_up_with_cursor_key_bindings = 1;  // bind to xscroll
   }
   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 xretrace_scroll_up 'event2index(name2event('WHEEL-UP')),"");
      execute('bind-to-key -r xretrace_scroll_down 'event2index(name2event('WHEEL-DOWN')),"");
      message("Bind to xscroll");
   }
}


jcelle

  • Senior Community Member
  • Posts: 253
  • Hero Points: 5
Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
« Reply #23 on: September 22, 2022, 03:56:42 PM »
I am not sure to understand what you mean with diff. If I do a diff of files, I get a window allowing side by side comparison of two files, and (now I start to understand) indeed using the wheel to scroll does not work : I get an error dialog box and I thought it was some kind of slickedit limitation and was more or less living with it...
Are we talking about the same thing ?

Graeme

  • Senior Community Member
  • Posts: 2796
  • Hero Points: 347
Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
« Reply #24 on: September 22, 2022, 08:44:11 PM »
yes, I wanted to see if you got that error  - so that's partly why I made that macro to swap the keybindings back (toggle) so you wouldn't get the error.

jcelle

  • Senior Community Member
  • Posts: 253
  • Hero Points: 5
Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
« Reply #25 on: September 22, 2022, 10:28:31 PM »
I'll look at your macro more in detail, though I am not a slick-c expert.
In any case the error upon wheeling in diff is what I call a bug or weird design.

Graeme

  • Senior Community Member
  • Posts: 2796
  • Hero Points: 347
Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
« Reply #26 on: September 22, 2022, 10:56:21 PM »
I guess it's because the diff window is a special environment where it's hard to allow user macros to execute and also that allowing the user to run a macro for wheel up/down is very unusual for an IDE to do.  Ideally the diff window would override user macros and use default behaviour for all the keys and mouse events that are part of the basic operation of the diff window.  e.g. as it stands, someone might write a macro for the right arrow key or the down arrow key and if they do, they won't be able to use those keys in the diff window.

It might be possible to write a macro that wraps the call to the diff tool with some code that swaps the keybindings over, before and after.  Let me know how you invoke the diff tool and I'll look into it if you want.

jcelle

  • Senior Community Member
  • Posts: 253
  • Hero Points: 5
Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
« Reply #27 on: September 23, 2022, 05:35:54 AM »
Got it better now !
So I bound the Wheelxx keys to fast-scroll with the "Diff mode" selected (so that is 2 sets of bindings for wheelxx) and it seems to work  :)

Graeme

  • Senior Community Member
  • Posts: 2796
  • Hero Points: 347
Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
« Reply #28 on: September 23, 2022, 05:49:42 AM »
Hey, you're the smart one!  :)

jcelle

  • Senior Community Member
  • Posts: 253
  • Hero Points: 5
Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
« Reply #29 on: September 23, 2022, 07:19:03 AM »
Well I would never had figured out without your comments !