Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support callback on scrollLines #4842

Open
unional opened this issue Oct 12, 2023 · 2 comments
Open

Support callback on scrollLines #4842

unional opened this issue Oct 12, 2023 · 2 comments

Comments

@unional
Copy link
Contributor

unional commented Oct 12, 2023

I tried to implement cursor based navigation.

When trying to handle CursorUp at the top of the buffer when there are scroll (i.e. buffer.active.viewportY and buffer.active.baseY > 0), I tried to do:

xterm.scrollLines(-1)
xterm.write('\x1B[A') // cursorUp

But that doesn't work probably becuase buffer.active.Y is already 0.

Or maybe scrollLines() didn't update the buffer.active.viewportY/baseY (I saw that they remain unchanged after the scroll happens.

@Tyriar
Copy link
Member

Tyriar commented Oct 12, 2023

scrollLines should update synchronously:

public scrollLines(disp: number, suppressScrollEvent?: boolean, source?: ScrollSource): void {
const buffer = this.buffer;
if (disp < 0) {
if (buffer.ydisp === 0) {
return;
}
this.isUserScrolling = true;
} else if (disp + buffer.ydisp >= buffer.ybase) {
this.isUserScrolling = false;
}
const oldYdisp = buffer.ydisp;
buffer.ydisp = Math.max(Math.min(buffer.ydisp + disp, buffer.ybase), 0);
// No change occurred, don't trigger scroll/refresh
if (oldYdisp === buffer.ydisp) {
return;
}
if (!suppressScrollEvent) {
this._onScroll.fire(buffer.ydisp);
}
}

It will update viewportY, not baseY. It might be doing something different from what you want, it seems to work as expected for me?

Recording 2023-10-12 at 13 48 59

@unional
Copy link
Contributor Author

unional commented Oct 12, 2023

My case seems to be an edge case. When the buffer.active.y is 0.

i.e. at the top of the viewport.

I tried doing the same thing when y is not 0 and it is working correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants