Thanks. This macro actually comes with xretrace so you probably don't need to load both of them. I changed some names slightly.
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 && !_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 )
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
cursor_up();
continue;
case WHEEL_DOWN :
if ( _IsKeyDown(CTRL) )
cursor_down(8);
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");
}
}