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: preview mode add keyboard shortcuts #12968

Merged
merged 3 commits into from Jun 29, 2023

Conversation

btea
Copy link
Collaborator

@btea btea commented Apr 24, 2023

Description

Add o and q shortcut keys for preview mode.

a

Additional context


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the PR Title Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@stackblitz
Copy link

stackblitz bot commented Apr 24, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@ArnaudBarre ArnaudBarre added p2-nice-to-have Not breaking anything but nice to have (priority) p2-to-be-discussed Enhancement under consideration (priority) labels May 27, 2023
@ArnaudBarre
Copy link
Member

Hi! Thanks for PR, we will discuss if we want to go forward with this feature in a coming meeting

Copy link
Member

@ArnaudBarre ArnaudBarre left a comment

Choose a reason for hiding this comment

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

We would like to include in Vite 4.4! I can take care of this refactor if you don't have time at the moment.

action: (server: PreviewServer) => void
}

export function bindPreviewShortcuts(server: PreviewServer): void {
Copy link
Member

Choose a reason for hiding this comment

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

Let's factorise this code a bit with something like that:

type CLIShortcut<Server> = {
  key: string
  description: string
  action: (server: Server) => void
}

function bindShortcuts<Server>(server: Server, shortcuts: CLIShortcut<Server>[]): void {
  // almost exactly this code below
}

export function bindPreviewShortcuts(server: PreviewServer): void {
  bindShortcuts(server, previewShortcuts)
}

type PreviewShortcut = CLIShortcut<PreviewServer>

And then rename the other usage in this file to add a dev prefix

@btea
Copy link
Collaborator Author

btea commented Jun 15, 2023

We would like to include in Vite 4.4! I can take care of this refactor if you don't have time at the moment.

It would be really nice if you could refactor it.

ArnaudBarre
ArnaudBarre previously approved these changes Jun 16, 2023
Copy link
Member

@ArnaudBarre ArnaudBarre left a comment

Choose a reason for hiding this comment

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

Change my mind, there is also the close function that differs.
Given that both are in the same file, I don't think other things will diverge. Factorisation starts at 3 they said.

We could also review the usage of setRawMode as suggested by @bluwy

@deot
Copy link
Contributor

deot commented Jun 29, 2023

When i use createServer(Node API), expect to use keyboard shortcuts. can it export?

node/index.ts

export { bindShortcuts, bindPreviewShortcuts } from './shortcuts'
  • example
import { createServer, bindShortcuts } from 'vite'

...
const server = await createServer(...);
await server.listen();
bindShortcuts(server)

@bluwy
Copy link
Member

bluwy commented Jun 29, 2023

@deot That sounds like something we can expose, but I don't think this is the right place to request for it. I'd suggest opening a feature request, or a PR directly.


@ArnaudBarre I wanted to merge this, but there's too many duplicated parts for me 😅 I went ahead and refactored it. Appreciate if you can review it again.

@bluwy bluwy merged commit 126e93e into vitejs:main Jun 29, 2023
13 checks passed
@btea btea deleted the feat/preview-shortcuts branch June 29, 2023 09:09
xinxinhe1810 pushed a commit to xinxinhe1810/vite that referenced this pull request Jul 4, 2023
Co-authored-by: bluwy <bjornlu.dev@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2-nice-to-have Not breaking anything but nice to have (priority) p2-to-be-discussed Enhancement under consideration (priority)
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

4 participants