TriliumNext / Notes

Build your personal knowledge base with TriliumNext Notes
https://triliumnext.github.io/Docs/
GNU Affero General Public License v3.0
853 stars 46 forks source link

(Feature request) Allow scrolling when the cursor is in the margins of a note #453

Open dousha opened 3 weeks ago

dousha commented 3 weeks ago

Describe feature

In the current implementation, when the mouse cursor is in the margins of a note, scrolling with the mouse wheel has no effect. (Margins are the blank spaces on either side of a note, as marked in the picture below with red boxes.) However, if you start scrolling, you can then move the mouse cursor into the margin and keep scrolling. It would be more intuitive if the user could start scrolling without having to move the cursor into the note.

figure-1

Additional Information

No response

SiriusXT commented 3 weeks ago

The idea is good, I implemented this function with a simple widget and provided it to those who need it:

let shiftPressed = false; // Used to determine horizontal scrolling
$(document).ready(function () {
    $(document).on('keydown', function (event) {
        if (event.shiftKey) {
            shiftPressed = true;
        }
    });
    $(document).on('keyup', function (event) {
        if (event.key === 'Shift') {
            shiftPressed = false;
        }
    });
});

class noteSplitScroll extends api.NoteContextAwareWidget {
    get position() {
        return 100;
    }
    get parentWidget() {
        return 'center-pane';
    }
    doRender() {
        this.$widget = $(``);
        return this.$widget;
    }
    async refreshWithNote() {
        const $noteSplit = $(`.note-split[data-ntx-id="${this.noteContext.ntxId}"]`);
        const $scrollingContainer = $noteSplit.children('.scrolling-container');
        const $splitNoteContainerWidget = $noteSplit.parent()
        $splitNoteContainerWidget.on('wheel', function (event) {
            if ($(event.target).is($splitNoteContainerWidget)) {
                if (shiftPressed) {
                    $scrollingContainer.scrollLeft($scrollingContainer.scrollLeft() + event.originalEvent.deltaY);
                } else {
                    $scrollingContainer.scrollTop($scrollingContainer.scrollTop() + event.originalEvent.deltaY);
                }
            }

        });
    }
}

module.exports = new noteSplitScroll();