SlickEdit Community

SlickEdit Product Discussion => SlickEdit® => Topic started by: jcelle on September 20, 2022, 01:01:50 pm

Title: mouse wheel scroll should scrol buffer as is (not from location of cursor)
Post by: jcelle on September 20, 2022, 01:01:50 pm
Hello there,
This is something I find really annoying since early versions of SE and I am wondering if this could be managed one way or another.
Steps:
- open a file, big enough to not be visible without scrolling
- scroll to the end of the file and place your cursor here
- use the mouse and scrollbar to scroll up so that the cursor is no longer visible
- here is the interesting part: place your mouse over the buffer and use the wheel to continue your action of scrolling up
Expected : the buffer continues to scroll up
Seen: the buffer is scrolled back to the part of the file where the cursor is located and then scroll starts from there.

It is very destabilizing...
So could there be a way to tune this ?
Thanks.
Title: Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
Post by: Clark on September 20, 2022, 01:31:27 pm
I can't reproduce this. For me, using the wheel to continue to scroll up does exactly that, it continues to scroll up. It does not start from the cursor position. There must be some extra magic needed for this to happen (config,mouse,mouse driver???).

Try a default config:
Code: [Select]
vs +new -sc c:\temp\new-config-dir
Title: Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
Post by: jcelle on September 20, 2022, 02:42:22 pm
Damned you are right, it works as I wish it would work !
Any idea of some setting that could alter this ?
I am thinking of any option to make the cursor remain visible while you scroll : it is how it behave if I scroll only with the wheel or with the keyboard.
Title: Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
Post by: Clark on September 20, 2022, 03:08:11 pm
I don't know of a setting for SlickEdit to keep the cursor visible when scrolling but SlickEdit has so many options that I could be wrong  ;D
Title: Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
Post by: jcelle on September 20, 2022, 03:35:06 pm
It does because the cursor vanishes upon scroll (with a brand new config as you suggested) and remains on first or last visible line with my config.
I am quite sure this is related.
Point is I can't either find this option back...
Title: Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
Post by: Clark on September 20, 2022, 03:58:30 pm
Please post your user.cfg.xml
Title: Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
Post by: jcelle on September 20, 2022, 04:28:32 pm
Here it is.
Title: Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
Post by: Clark on September 20, 2022, 04:49:16 pm
I've fixed your config. You changed your bindings for WHEEL-UP and WHEEL-DOWN to scroll-up and scroll-down which are intended to bound to keys and keep the cursor in view.
Title: Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
Post by: jcelle on September 20, 2022, 05:11:24 pm
Ah I would have never remembered...
Thanks so much for having investigated this.
Though it introduces a dual problem : now if I scroll with the wheel, the cursor vanishes, and if I press any key the whole buffer is scrolled back to where the cursor is. This is I think why I had remapped the wheel-up and wheel-down keys: I want the cursor to remain in view so that I can continue editing.
In both cases I have to click to put back the cursor in view : it would make sense to add an option to keep the cursor visible, whatever scrolling function you use.
I'll see meanwhile what extra click is the most acceptable for me.
Title: Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
Post by: Dennis on September 20, 2022, 05:42:53 pm
You could map Ctrl+Alt+WheelUp/Down to page-up/down (or scroll-up/down) so that you would have a way to scroll keeping the cursor in view when you want to.
Title: Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
Post by: jcelle on September 20, 2022, 07:00:40 pm
well, I think I always need to have the cursor remaining in view.
All scrolling mechanisms must be consistent.
I have set back wheelXXX to scroll-XXX and now I understand better my original problem: using the scrollbar is the only scrolling function that does not (yet?) keep the cursor in view.
Do you think there could be a way to change this ?
Could a macro listen to some scrolling event and move back the cursor in view ?
Interesting problem...
Title: Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
Post by: Dennis on September 20, 2022, 08:19:21 pm
If the document overview bar is visible, a quick double-click there will move the cursor to that scroll location (single-click will jump to any highlight, double-click will jump to any location on the document overview bar).
Title: Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
Post by: Graeme on September 20, 2022, 10:59:42 pm
I haven't read this thread properly so not sure what you're asking for but I recall writing this macro when you asked about it a few years ago
https://community.slickedit.com/index.php/topic,16973.msg65681.html#msg65681

It comes with xretrace/ xxutils but it looks like I haven't documented it properly - I'll add to my todo list
https://community.slickedit.com/index.php/topic,18320.0.html

Title: Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
Post by: jcelle on September 21, 2022, 05:54:11 am
Gee you are smart Graeme ! I had totally forgotten about this post I did (https://community.slickedit.com/index.php/topic,16659.0.html). Now I remember I had to give up as I was using Slickedit standard at that time and could not load macro files.
I am now using PRO and I could load your file (picked the latest in https://community.slickedit.com/index.php/topic,16973.msg65681.html#msg65681) and bind wheelxx keys to xscrollxx functions.
Using wheelxx scrolls the buffer as long as the cursor is visible: once the cursor goes out of view the buffer no longer scrolls.
Same behavior with CTRL key.
Scroll works with SHIFT, though cursor goes out of view.
Note I don't know anything about xtrace: do I need to load another file ?


Title: Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
Post by: Graeme on September 21, 2022, 09:47:02 am
You probably need to run the command xretrace_toggle_xscroll to swap the key bindings between the new ones and the normal ones.  It sets or clears the variable xretrace_def_scroll_up_with_cursor which is probably why it's not working for you.  You need to use this command to swap back to the normal key bindings before you use the diff tool, otherwise diff reports an error.

Title: Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
Post by: jcelle 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.
Title: Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
Post by: Graeme on September 21, 2022, 09:20:59 pm
What do you have bound to ctrl+up/down keys?
Title: Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
Post by: jcelle on September 21, 2022, 10:22:03 pm
scroll-up & scroll-down
Title: Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
Post by: Graeme 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();
}
Title: Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
Post by: jcelle 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  ;)
Title: Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
Post by: Graeme 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");
   }
}
Title: Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
Post by: jcelle 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.
Title: Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
Post by: Graeme 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");
   }
}

Title: Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
Post by: jcelle 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 ?
Title: Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
Post by: Graeme 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.
Title: Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
Post by: jcelle 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.
Title: Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
Post by: Graeme 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.
Title: Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
Post by: jcelle 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  :)
Title: Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
Post by: Graeme on September 23, 2022, 05:49:42 am
Hey, you're the smart one!  :)
Title: Re: mouse wheel scroll should scrol buffer as is (not from location of cursor)
Post by: jcelle on September 23, 2022, 07:19:03 am
Well I would never had figured out without your comments !