Skip to content

Integrated terminal resets scroll position to top when emacs is closed #84145

Closed

Description

@mjbvz

Issue Type: Bug

Reopening of #62329

steps

  1. In the intergrated terminal.
  2. Run a command that generates more than one screen of content: ls -alF /dev/
  3. Scroll to bottom
  4. Now run emacs and then close emacs using ctrl+c ctrl+x

Bug
Terminal scroll position is sometimes reset to top of buffer

Nov-07-2019 10-24-45

VS Code version: Code - Insiders 1.40.0-insider (86405ea, 2019-11-06T16:56:25.487Z)
OS version: Darwin x64 18.7.0

System Info
Item Value
CPUs Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz (8 x 2200)
GPU Status 2d_canvas: enabled
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
oop_rasterization: disabled_off
protected_video_decode: unavailable_off
rasterization: enabled
skia_renderer: disabled_off
surface_control: disabled_off
surface_synchronization: enabled_on
video_decode: enabled
viz_display_compositor: enabled_on
viz_hit_test_surface_layer: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) 2, 2, 2
Memory (System) 16.00GB (0.02GB free)
Process Argv -psn_0_1614218
Screen Reader no
VM 22%

Activity

  1. Tyriar commented on Nov 8, 2019

    @Tyriar
    Contributor

    Can't repro 🙁 some things that might help diagnose:

  2. added
    bug
    terminal
    on Nov 8, 2019
  3. added this to the Backlog milestone on Nov 8, 2019
  4. mjbvz commented on Nov 8, 2019

    @mjbvz
    ContributorAuthor

    Seems to happen most reliably when I run emacs as the git editor, but as the screenshot shows it can also happen for normal runs.

    From debugging:

    Normal case

    • scroll called with undefined
    • _onScroll called twice with _ignoreNextScrollEvent == true
    • scrollLines not called by _onScroll

    Bugged case

    • scroll called with undefined
    • _onScroll called with _ignoreNextScrollEvent == true
    • _onScroll called again _ignoreNextScrollEvent == false
    • scrollLines called by _onScroll with -3145
  5. Tyriar commented on Nov 8, 2019

    @Tyriar
    Contributor

    _onScroll called again _ignoreNextScrollEvent == false
    scrollLines called by _onScroll with -3145

    That's definitely the problem, could you get the stacktrace for both of those?

  6. mjbvz commented on Nov 8, 2019

    @mjbvz
    ContributorAuthor

    Stacks look the same. Here _onScroll called with _ignoreNextScrollEvent === true:

    Screen Shot 2019-11-08 at 3 07 03 PM
    `:

    And with _ignoreNextScrollEvent === false:

    Screen Shot 2019-11-08 at 3 07 38 PM


    It seems like a timing issue. Between the call to _innerRefresh which sets _ignoreNextScrollEvent = true and _scroll, someone else is setting _ignoreNextScrollEvent = false. Here's one possible call sequences I see opening emacs in the bad case (true/false is the value of _ignoreNextScrollEvent ):

    Screen Shot 2019-11-08 at 3 20 05 PM

    And from the good case:

    Screen Shot 2019-11-08 at 3 21 23 PM

    For what it's worth, I also currently see this more often in insiders (vs OSS)

  7. added
    help wanted
    on Nov 18, 2019
  8. Yanpas commented on Nov 19, 2019

    @Yanpas
    Contributor

    I don't use emacs or something, just run some tests which output a lot of stuff, then hide and unhide terminal - after a couple of moments I am on top of terminal. Scrolling it with a scrollbar to the bottom doesn't bring me to the last line, so I press enter

  9. rianquinn commented on Dec 15, 2019

    @rianquinn

    Yeah, I have to press enter to get to the bottom of the terminal. I can confirm that this is an issue with Linux and Windows (I see this on both), so it doesn't appear to be specific to any OS. This also happens with both native and remote development, so it is not specific to remote development (which I use a lot). For me, it starts happening after about an hour of use, and then becomes really frequent (almost every time I open the terminal). Its causing me to form a habitual response to just always press enter when I open the terminal ☹️

  10. Tyriar commented on Dec 27, 2019

    @Tyriar
    Contributor

    Another repro: #87477

  11. Olovan commented on Jan 5, 2020

    @Olovan
    Contributor

    The #87477 case seems to be a symptom of the TerminalPanel onDidChangeVisibility callback not triggering a setVisible call on the active terminal instance.

    this._register(this.onDidChangeVisibility(visible => {
    if (visible) {
    if (this._terminalService.terminalInstances.length > 0) {
    this._updateFont();
    this._updateTheme();
    } else {
    // Check if instances were already restored as part of workbench restore
    if (this._terminalService.terminalInstances.length === 0) {
    this._terminalService.createTerminal();
    }
    if (this._terminalService.terminalInstances.length > 0) {
    this._updateFont();
    this._updateTheme();
    }
    }
    }
    }));

    The code to re-sync the the Terminal viewport and scrollbar is in the TerminalInstance setVisible method.

    public setVisible(visible: boolean): void {
    this._isVisible = visible;
    if (this._wrapperElement) {
    dom.toggleClass(this._wrapperElement, 'active', visible);
    }
    if (visible && this._xterm && this._xtermCore) {
    // Trigger a manual scroll event which will sync the viewport and scroll bar. This is
    // necessary if the number of rows in the terminal has decreased while it was in the
    // background since scrollTop changes take no effect but the terminal's position does
    // change since the number of visible rows decreases.
    // This can likely be removed after https://github.com/xtermjs/xterm.js/issues/291 is
    // fixed upstream.
    this._xtermCore._onScroll.fire(this._xterm.buffer.viewportY);
    if (this._container && this._container.parentElement) {
    // Force a layout when the instance becomes invisible. This is particularly important
    // for ensuring that terminals that are created in the background by an extension will
    // correctly get correct character measurements in order to render to the screen (see
    // #34554).
    const computedStyle = window.getComputedStyle(this._container.parentElement);
    const width = parseInt(computedStyle.getPropertyValue('width').replace('px', ''), 10);
    const height = parseInt(computedStyle.getPropertyValue('height').replace('px', ''), 10);
    this.layout(new dom.Dimension(width, height));
    // HACK: Trigger another async layout to ensure xterm's CharMeasure is ready to use,
    // this hack can be removed when https://github.com/xtermjs/xterm.js/issues/702 is
    // supported.
    setTimeout(() => this.layout(new dom.Dimension(width, height)), 0);
    }
    }

    I'm not sure if it's the same issue as the Emacs variation of the bug.

  12. added a commit that references this issue on Jan 6, 2020
    1b17e36
  13. jcsagrero commented on Jan 25, 2020

    @jcsagrero

    I'm also having this issue. When I toggle open the terminal on WSL and PowerShell, the terminal is scrolled to the top, even with all extensions disabled. I'm not using emacs - it happens reliably regardless of the type of content in the terminal. Just focusing on the terminal doesn't have this behavior, only toggling it does.

  14. jcsagrero commented on Jan 25, 2020

    @jcsagrero

    Update: for anyone looking for a temporary fix, I used the extension "multi-command" and set up a shortcut to scroll the terminal to the bottom when opening it. Since I needed to first focus the terminal after opening it, I had to set up two cases, toggling when it's closed and toggling when it's already open:

    ` "multiCommand.commands": [
    {
    "command": "multiCommand.toggleTermClosed",
    "sequence": [
    "workbench.action.terminal.toggleTerminal",
    "workbench.action.terminal.focus",
    "workbench.action.terminal.scrollToBottom",

            ]
        },
        {
            "command": "multiCommand.toggleTermOpen",
            "sequence": [
                "workbench.action.terminal.toggleTerminal",
            ]
        }
    ]`
    
  15. aeschli commented on Jan 30, 2020

    @aeschli
    Contributor

    verified with steps from #87477

  16. locked and limited conversation to collaborators on Feb 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bughelp wantedterminalverified

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions