Skip to content

Commit

Permalink
Support command tracking from current scroll position
Browse files Browse the repository at this point in the history
Fixes #46729
  • Loading branch information
Tyriar committed Oct 23, 2019
1 parent de010f5 commit 215fa33
Showing 1 changed file with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,18 @@ export class CommandTrackerAddon implements ICommandTracker, ITerminalAddon {
}

let markerIndex;
if (this._currentMarker === Boundary.Bottom) {
const currentLineY = Math.min(this._getLine(this._terminal, this._currentMarker), this._terminal.buffer.baseY);
const viewportY = this._terminal.buffer.viewportY;
if (!retainSelection && currentLineY !== viewportY) {
// The user has scrolled, find the line based on the current scroll position. This only
// works when not retaining selection
const markersBelowViewport = this._terminal.markers.filter(e => e.line >= viewportY).length;
if (markersBelowViewport === 0) {
markerIndex = -1;
} else {
markerIndex = this._terminal.markers.length - markersBelowViewport - 1;
}
} else if (this._currentMarker === Boundary.Bottom) {
markerIndex = this._terminal.markers.length - 1;
} else if (this._currentMarker === Boundary.Top) {
markerIndex = -1;
Expand Down Expand Up @@ -95,7 +106,18 @@ export class CommandTrackerAddon implements ICommandTracker, ITerminalAddon {
}

let markerIndex;
if (this._currentMarker === Boundary.Bottom) {
const currentLineY = Math.min(this._getLine(this._terminal, this._currentMarker), this._terminal.buffer.baseY);
const viewportY = this._terminal.buffer.viewportY;
if (!retainSelection && currentLineY !== viewportY) {
// The user has scrolled, find the line based on the current scroll position. This only
// works when not retaining selection
const markersAboveViewport = this._terminal.markers.filter(e => e.line <= viewportY).length;
if (markersAboveViewport < this._terminal.markers.length) {
markerIndex = markersAboveViewport;
} else {
markerIndex = this._terminal.markers.length;
}
} else if (this._currentMarker === Boundary.Bottom) {
markerIndex = this._terminal.markers.length;
} else if (this._currentMarker === Boundary.Top) {
markerIndex = 0;
Expand Down

0 comments on commit 215fa33

Please sign in to comment.