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

feat: Set onbeforeunload to avoid losing the current terminal session with Ctrl+W #23

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

erikmd
Copy link

@erikmd erikmd commented Sep 14, 2024

Description

As an Emacs user (and co-maintainer of several packages), I extensively use Gitpod Terminal Browser in multiple occasions. Gitpod Terminal is a very nice tool!
— even if the README states that "it is not ready for production use", I guess it's pretty close 👍

Motivation of this PR: given the Ctrl+W is a very typical Emacs shortcut that must be avoided when using Gitpod (because it amounts to stopping the workspace and losing the ambient session), this small feature appears to be very important for Gitpod+Terminal users.

BTW I followed advice from https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event:

The dialog can be triggered in the following ways:

  • Calling the event object's preventDefault() method.
  • Setting the event object's returnValue property to a non-empty string value or any other truthy value.
  • Returning any truthy value from the event handler function, e.g. return "string". Note that this only works when the function is attached via the onbeforeunload property, not the addEventListener() method. This behavior is consistent across modern versions of Firefox, Safari, and Chrome.

The last two mechanisms are legacy features; best practice is to trigger the dialog by invoking preventDefault() on the event object, while also setting returnValue to support legacy cases.

Then tested the feature successfully on Firefox ESR (under Debian Stable).

Cc @filiptronicek @mustard-mh @loujaybee @axonasif WDYT?

Related Issue(s)

Fixes #gitpod-io/gitpod#18416

How to test

Documentation

/hold

erikmd added a commit to erikmd/xterm-web-ide that referenced this pull request Sep 14, 2024
`./validate.sh` currently fails on a fresh gitpod workspace with:

```
rm: cannot remove '/ide/xterm': Is a directory
ln: failed to create symbolic link '/ide/xterm/xterm': File exists
```
@axonasif
Copy link
Member

Thanks for the efforts @erikmd!

We'll take a look at this 👋

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.

2 participants