Skip to content

Fix prompt input model to preserve trailing whitespace after window reload #260747

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

Closed
wants to merge 5 commits into from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 9, 2025

When using ${shellPromptInput} in terminal tab descriptions, trailing whitespace is lost after reloading the window. For example:

Before window reload:

  • User types: ls (command with trailing space)
  • Terminal tab shows: ls | (space visible before cursor)

After window reload:

  • Terminal tab shows: ls| (trailing space lost)

Root Cause

The issue occurs because PromptInputModel.deserialize() was calling _sync() which recalculates trailing whitespace from the current terminal buffer state. During window reload, the terminal buffer may not yet reflect the saved state, causing the correctly serialized trailing whitespace to be overwritten with incorrect data.

Solution

Updated PromptInputModel.deserialize() to:

  • Fire _onDidChangeInput event to notify UI components (like terminal tabs) that state has been restored
  • Remove the _sync() call that was overwriting the correctly serialized trailing whitespace

The fix preserves the originally saved trailing whitespace while ensuring UI components are notified of the state restoration.

Testing

Added a comprehensive test that validates:

  • Serialization captures trailing whitespace correctly
  • Deserialization fires the change event to ensure UI updates
  • State is properly restored with trailing whitespace preserved

Fixes #260746.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] Prompt input model should use cursor position after reloading window Fix prompt input model to preserve trailing whitespace after window reload Aug 9, 2025
@Copilot Copilot AI requested a review from Tyriar August 9, 2025 11:50
Copilot finished work on behalf of Tyriar August 9, 2025 11:50
Comment on lines 201 to 206

// Fire change event to notify listeners that the state has been restored
this._onDidChangeInput.fire(this._createStateObject());

// Sync to ensure state is consistent with current terminal buffer
this._sync();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to fix the issue

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue was that calling _sync() during deserialization was overwriting the correctly saved trailing whitespace. The _sync() method calculates trailing whitespace from the current terminal buffer state, but during window reload the buffer may not yet reflect the saved state. The fix now only fires the change event to notify UI components (like terminal tabs) that the state has been restored, while preserving the originally serialized trailing whitespace. (a257427)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by removing the _sync() call that was overwriting the correctly serialized trailing whitespace with potentially stale terminal buffer data during window reload. Now only fires the change event needed for UI updates. (a257427)

@Tyriar Tyriar added this to the August 2025 milestone Aug 10, 2025
Comment on lines 201 to 206

// Fire change event to notify listeners that the state has been restored
this._onDidChangeInput.fire(this._createStateObject());

// Sync to ensure state is consistent with current terminal buffer
this._sync();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Copilot AI commented Aug 10, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • electronjs.org
    • Triggering command: node-gyp (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@Copilot Copilot AI requested a review from Tyriar August 10, 2025 11:00
Copilot finished work on behalf of Tyriar August 10, 2025 11:00
@Tyriar
Copy link
Member

Tyriar commented Aug 10, 2025

Not the right fix.

@Tyriar Tyriar closed this Aug 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prompt input model should use cursor position after reloading window
2 participants