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: shortcut added for reopening last closed tab #1963

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

therealrinku
Copy link
Contributor

@therealrinku therealrinku commented Feb 20, 2024

addressing: #1768

added Ctrl+Shift+T shortcut to re-open recently closed tab

Copy link
Collaborator

@rathboma rathboma left a comment

Choose a reason for hiding this comment

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

Thank you so much for contributing this! I think your logic is sound, but I've added a few pointers to help us do this in the right place.

apps/studio/src/components/CoreTabs.vue Show resolved Hide resolved
Copy link
Collaborator

@rathboma rathboma left a comment

Choose a reason for hiding this comment

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

Almost perfect!

apps/studio/src/store/modules/TabModule.ts Outdated Show resolved Hide resolved
apps/studio/src/store/modules/TabModule.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@rathboma rathboma left a comment

Choose a reason for hiding this comment

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

Hey! This still needs one more change to account for the fact that the original tab was deleted from the database.

apps/studio/src/store/modules/TabModule.ts Outdated Show resolved Hide resolved
apps/studio/src/store/modules/TabModule.ts Outdated Show resolved Hide resolved
@therealrinku
Copy link
Contributor Author

Hi @rathboma
thanks for the review. I think it's already been added to the database when we call reopenLastClosedTab

here is the video. Let me know if it's okay or I'm missing something here

Screencast.from.2024-04-05.15-16-25.mp4

@rathboma
Copy link
Collaborator

Hey, it will work, but when you close and re-open Beekeeper Studio those tabs will be missing, because they were deleted from the database. That's why the tabs need to go through the sequence I described.

@rathboma
Copy link
Collaborator

@azmy60 this doesn't require much to fix for merging, see the comments above. You should be able to commit directly to this branch.

@azmy60 azmy60 requested a review from rathboma May 8, 2024 17:27
Copy link
Collaborator

@rathboma rathboma left a comment

Choose a reason for hiding this comment

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

def still needs some work

apps/studio/src/store/modules/TabModule.ts Outdated Show resolved Hide resolved
async reopenLastClosedTab(context) {
for (let i = context.state.lastClosedTabs.length - 1; i >= 0; i--) {
const tab = context.state.lastClosedTabs[i]
// Does this tab belong to the current connection?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you also have to check workspace id?

Copy link
Collaborator

Choose a reason for hiding this comment

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

The OpenTab here has still been removed from the database and doesn't have an ID, so it still needs saving.

Also -- what happens with the position of the tab? Does it go back to the right place?

Copy link
Contributor

@azmy60 azmy60 May 9, 2024

Choose a reason for hiding this comment

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

I was under the impression that we want this to behave like vscode, so no need to save lastClosedTabs to database. But I just realized that chrome persists the closed tabs even though I exit the program. I'll take a look on that.

Copy link
Contributor

@azmy60 azmy60 May 9, 2024

Choose a reason for hiding this comment

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

Should we even not remove tabs from database and just mark it as "closed"? like soft delete.

apps/studio/src/store/modules/TabModule.ts Outdated Show resolved Hide resolved
apps/studio/src/store/modules/TabModule.ts Outdated Show resolved Hide resolved
@@ -78,6 +86,18 @@ export const TabModule: Module<State, RootState> = {
context.commit('set', [])
context.commit('setActive', null)
},
async reopenLastClosedTab(context) {
for (let i = context.state.lastClosedTabs.length - 1; i >= 0; i--) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are we looping here? We only want the very last item in the lastClosedTabs array.

Copy link
Contributor

@azmy60 azmy60 May 9, 2024

Choose a reason for hiding this comment

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

This is to avoid opening a tab that's from a different connection.

Using array.pop would get the last item, but that item could be from a different connectionId.

An example to this case is:

  1. close tabs in connection A
  2. disconnect from A and connect to B
  3. press ctrl+shift+T
  4. tabs that were in connection A are now in B

Another solution to this is I was thinking if we should just wipe out the stack so it's empty whenever we connect to a new connection, but maybe it's better to do the first one since we can?

EDIT: This implementation will probably change to using array.pop if I save the closed tabs to database.

azmy60 added 2 commits May 9, 2024 23:21
It's hard to restore closed tabs in the right position, when all
positions of tabs were always `99`.
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.

None yet

3 participants