Menu

#1451 Support horizontal scrolling via SHIFT key and WM_MOUSEWHEEL on Windows

Duplicate
closed
nobody
5
2022-10-12
2022-09-22
No

As a follow-up on our discussion of feature request 1450, I've updated merge request 35 to support horizontal scrolling by holding down the shift key while using the vertical mouse wheel.

Related

Feature Requests: #749

Discussion

  • Zufu Liu

    Zufu Liu - 2022-09-22

    Following is the code that I currently use, horizontal scrolling does nothing when word wrap is enabled or user disabled that in system settings.

    void ScintillaWin::GetIntelliMouseParameters() noexcept {
        // This retrieves the number of lines per scroll as configured in the Mouse Properties sheet in Control Panel
        ::SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &linesPerScroll, 0);
        ::SystemParametersInfo(SPI_GETWHEELSCROLLCHARS, 0, &charsPerScroll, 0);
    }
    
    // https://github.com/zufuliu/notepad2/blob/main/scintilla/win32/ScintillaWin.cxx#L1737
    if (wParam & MK_SHIFT) {
        if (vs.wrap.state != Wrap::None || charsPerScroll == 0) {
            return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
        }
    }
    
    // Either SCROLL or ZOOM. We handle the wheel steppings calculation
    wheelDelta -= GET_WHEEL_DELTA_WPARAM(wParam);
    if (std::abs(wheelDelta) < WHEEL_DELTA) {
        return 0;
    }
    if (wParam & MK_SHIFT) {
        int charsToScroll = charsPerScroll;
        if (charsPerScroll == WHEEL_PAGESCROLL) {
            const PRectangle rcText = GetTextRectangle();
            const int pageWidth = static_cast<int>(rcText.Width() * 2 / 3);
            charsToScroll = pageWidth;
        } else {
            charsToScroll = 1 + static_cast<int>(std::max(charsToScroll, 1) * vs.aveCharWidth);
        }
        charsToScroll *= (wheelDelta / WHEEL_DELTA);
        if (wheelDelta >= 0) {
            wheelDelta = wheelDelta % WHEEL_DELTA;
        } else {
            wheelDelta = -(-wheelDelta % WHEEL_DELTA);
        }
        HorizontalScrollTo(xOffset + charsToScroll);
    } else if (linesPerScroll > 0) {
    }
    
     
  • Markus Nißl

    Markus Nißl - 2022-09-22

    My feature request here is about triggering horizontal scrolling in a different manner.

    Respecting user defined system settings certainly enhances usability and hence the user experience. I suppose Neil welcomes a patch from your side in this regard.

     
  • Neil Hodgson

    Neil Hodgson - 2022-09-22

    if (charsPerScroll == WHEEL_PAGESCROLL) {

    There is no page option for horizontal movement:
    Mouse Properties

     
  • Zufu Liu

    Zufu Liu - 2022-09-22

    Patch removed copy & pasted WHEEL_PAGESCROLL handling.

     
  • Neil Hodgson

    Neil Hodgson - 2022-09-22

    There is duplicated code for extracting the whole portion and remainder from wheelDelta. The unusual modulo code in particular could be hoisted out.

    To be picky, there should be a second wheelDelta for WM_MOUSEHWHEEL (but not MK_SHIFT + WM_MOUSEWHEEL) to accumulate partial movements from the two sensors independently. However, I have never seen a high resolution mouse wheel and they may not exist.
    https://devblogs.microsoft.com/oldnewthing/20130123-00/?p=5473

     
  • Markus Nißl

    Markus Nißl - 2022-09-23

    Neil, if you approve of my updated merge request 35, could that be committed please?

    Zufu Liu's remark is basically hijacking this thread, having the discussion no longer match the subject while it deserves its own feature request: "Mouse wheel action respects user system settings on Windows".

     
    • Neil Hodgson

      Neil Hodgson - 2022-09-24

      The patches above from Zufu Liu do implement the subject of this feature request although they also change some other things. The other changes appear to have some merit and it would be better to not commit some code then rewrite it again soon after.

      Scrolling horizontally by 120 pixels per wheel click seems excessive with other applications scrolling much less: VS Code seems to be around 40 pixels.

       
  • Zufu Liu

    Zufu Liu - 2022-09-23
    • labels: --> scintilla, win32, scrolling
     
  • Zufu Liu

    Zufu Liu - 2022-09-23

    OK, I can put my patch into [feature-requests:#749].

     

    Related

    Feature Requests: #749

  • Neil Hodgson

    Neil Hodgson - 2022-09-29
    • Group: Initial --> Duplicate
     
  • Neil Hodgson

    Neil Hodgson - 2022-10-12
    • status: open --> closed
     

Log in to post a comment.