-
-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Desktop: Fixes #11805: Add global shortcut to show/hide Joplin #15013
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
Open
Ashutoshx7
wants to merge
6
commits into
laurent22:dev
Choose a base branch
from
Ashutoshx7:fix-11805-global-hotkey
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d911778
Desktop: Fixes #11805: Add global shortcut to show/hide Joplin
Ashutoshx7 99d0d7f
Refactor GlobalHotkeyInput to reuse ShortcutRecorder, fix types, and …
8cda073
Fix lint errors in GlobalHotkeyInput and SettingComponent
ee89241
Fix review feedback: parens, validation, dead CSS, Wayland check
40d928c
Reuse ShortcutRecorder directly, drop custom display UI
Ashutoshx7 011eba7
Handle missing file gracefully in ExternalEditWatcher
Ashutoshx7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
packages/app-desktop/gui/ConfigScreen/controls/GlobalHotkeyInput.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import * as React from 'react'; | ||
| import { render, screen, fireEvent } from '@testing-library/react'; | ||
|
|
||
| import GlobalHotkeyInput from './GlobalHotkeyInput'; | ||
|
|
||
| describe('GlobalHotkeyInput', () => { | ||
| test('should render current value with Change and Clear buttons', () => { | ||
| const onChange = jest.fn(); | ||
| const { rerender } = render(<GlobalHotkeyInput value="" themeId={1} onChange={onChange} />); | ||
|
|
||
| // Empty state: shows "Not set", no Clear button | ||
| expect(screen.getByText('Not set')).toBeTruthy(); | ||
| expect(screen.getByText('Change')).toBeTruthy(); | ||
| expect(screen.queryByText('Clear')).toBeNull(); | ||
|
|
||
| // With value: shows shortcut and Clear button | ||
| rerender(<GlobalHotkeyInput value="CommandOrControl+Shift+J" themeId={1} onChange={onChange} />); | ||
| expect(screen.getByText('CommandOrControl+Shift+J')).toBeTruthy(); | ||
| expect(screen.getByText('Clear')).toBeTruthy(); | ||
| }); | ||
|
|
||
| test('should clear value when Clear is clicked', () => { | ||
| const onChange = jest.fn(); | ||
| render(<GlobalHotkeyInput value="CommandOrControl+Shift+J" themeId={1} onChange={onChange} />); | ||
|
|
||
| fireEvent.click(screen.getByText('Clear')); | ||
| expect(onChange).toHaveBeenCalledWith({ value: '' }); | ||
| }); | ||
|
|
||
| test('should show ShortcutRecorder when Change is clicked', () => { | ||
| const onChange = jest.fn(); | ||
| render(<GlobalHotkeyInput value="" themeId={1} onChange={onChange} />); | ||
|
|
||
| fireEvent.click(screen.getByText('Change')); | ||
| // ShortcutRecorder renders a Save button and a Cancel button | ||
| expect(screen.getByText('Save')).toBeTruthy(); | ||
| expect(screen.getByText('Cancel')).toBeTruthy(); | ||
| }); | ||
| }); | ||
85 changes: 85 additions & 0 deletions
85
packages/app-desktop/gui/ConfigScreen/controls/GlobalHotkeyInput.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import * as React from 'react'; | ||
| import { useState, useCallback } from 'react'; | ||
| import { ShortcutRecorder } from '../../KeymapConfig/ShortcutRecorder'; | ||
| import { _ } from '@joplin/lib/locale'; | ||
|
|
||
| interface OnChangeEvent { | ||
| value: string; | ||
| } | ||
|
|
||
| interface Props { | ||
| value: string; | ||
| themeId: number; | ||
| onChange: (event: OnChangeEvent)=> void; | ||
| } | ||
|
|
||
| // A thin wrapper around ShortcutRecorder for the global hotkey setting. | ||
| // Toggles between a display view and the existing ShortcutRecorder component. | ||
| export default function GlobalHotkeyInput(props: Props) { | ||
| const [editing, setEditing] = useState(false); | ||
| const value = props.value || ''; | ||
|
|
||
| const onSave = useCallback((event: { commandName: string; accelerator: string }) => { | ||
| // Normalize platform-specific modifiers to CommandOrControl for | ||
| // consistent cross-platform storage. | ||
| const accelerator = event.accelerator | ||
| .replace(/\bCmd\b/, 'CommandOrControl') | ||
| .replace(/\bCtrl\b/, 'CommandOrControl'); | ||
| props.onChange({ value: accelerator }); | ||
| setEditing(false); | ||
| }, [props.onChange]); | ||
|
|
||
| const onCancel = useCallback(() => { | ||
| setEditing(false); | ||
| }, []); | ||
|
|
||
| const onReset = useCallback(() => { | ||
| props.onChange({ value: '' }); | ||
| setEditing(false); | ||
| }, [props.onChange]); | ||
|
|
||
| // Validation errors aren't critical for global shortcuts — log only. | ||
| const onError = useCallback((_event: { recorderError: Error }) => { | ||
| // No-op: ShortcutRecorder validates against the keymap (command | ||
| // conflicts), which doesn't apply to global hotkeys. | ||
| }, []); | ||
|
|
||
| if (editing) { | ||
| return ( | ||
| <ShortcutRecorder | ||
| onSave={onSave} | ||
| onReset={onReset} | ||
| onCancel={onCancel} | ||
| onError={onError} | ||
| initialAccelerator={value} | ||
| commandName="globalHotkey" | ||
| themeId={props.themeId} | ||
| skipKeymapValidation | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <div className="global-hotkey-input"> | ||
| <span className="shortcut-display"> | ||
| {value || _('Not set')} | ||
| </span> | ||
| <button | ||
| className="record-btn" | ||
| onClick={() => setEditing(true)} | ||
| type="button" | ||
| > | ||
| {_('Change')} | ||
| </button> | ||
| {value && ( | ||
| <button | ||
| className="clear-btn" | ||
| onClick={() => props.onChange({ value: '' })} | ||
| type="button" | ||
| > | ||
| {_('Clear')} | ||
| </button> | ||
| )} | ||
| </div> | ||
| ); | ||
|
Comment on lines
+40
to
+52
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ShortcutRecorded already has these features. Is it not possible to use it for this too?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done:) |
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
packages/app-desktop/gui/ConfigScreen/styles/global-hotkey-input.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| .global-hotkey-input { | ||
| display: flex; | ||
| align-items: center; | ||
| gap: 8px; | ||
|
|
||
| > .shortcut-display { | ||
| font-family: var(--joplin-font-family); | ||
| font-size: var(--joplin-font-size); | ||
| color: var(--joplin-color); | ||
| background-color: var(--joplin-background-color); | ||
| border: 1px solid var(--joplin-border-color4); | ||
| border-radius: 3px; | ||
| padding: 4px 10px; | ||
| min-width: 180px; | ||
| min-height: 1.6em; | ||
| outline: none; | ||
| } | ||
|
|
||
| > .record-btn, | ||
| > .clear-btn { | ||
| font-family: var(--joplin-font-family); | ||
| font-size: calc(var(--joplin-font-size) * 0.9); | ||
| color: var(--joplin-color); | ||
| background-color: var(--joplin-background-color); | ||
| border: 1px solid var(--joplin-border-color4); | ||
| border-radius: 4px; | ||
| padding: 4px 10px; | ||
| cursor: pointer; | ||
|
|
||
| &:hover { | ||
| background-color: var(--joplin-background-color-hover3); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's too many tests, please reduce them to something more sensible