Repository navigation
Lint #5845
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
Lint #5845
Changes from all commits
f1c7e3e
84861d6
9b4a4ce
0666f3f
a79b437
c8867d7
552536a
445c397
5474375
49ffbb5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,30 +76,19 @@ async function restoreFile(progress: (message: string) => void, menuItem: Elemen | |
| } | ||
| } | ||
|
|
||
| const filesRestored = new WeakSet<HTMLButtonElement>(); | ||
| async function handleRestoreFileClick(event: DelegateEvent<MouseEvent, HTMLButtonElement>): Promise<void> { | ||
| const menuItem = event.delegateTarget; | ||
|
|
||
| // Only allow one click | ||
| if (filesRestored.has(menuItem)) { | ||
| return; | ||
| } | ||
|
|
||
| filesRestored.add(menuItem); | ||
|
|
||
| try { | ||
| await showToast(async progress => { | ||
|
Member
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.
|
||
| const filePath = menuItem.closest<HTMLDivElement>('[data-path]')!.dataset.path!; | ||
| // Show toast while restoring | ||
| await showToast(async progress => restoreFile(progress!, menuItem, filePath), { | ||
| message: 'Restoring…', | ||
| doneMessage: 'Restored!', | ||
| }); | ||
|
|
||
| // Hide file from view | ||
| menuItem.closest('.file')!.remove(); | ||
| } catch (error) { | ||
| features.log.error(import.meta.url, error); | ||
| } | ||
| return restoreFile(progress!, menuItem, filePath); | ||
| }, { | ||
| message: 'Restoring…', | ||
| doneMessage: 'Restored!', | ||
| }); | ||
|
|
||
| // Hide file from view | ||
| menuItem.closest('.file')!.remove(); | ||
| } | ||
|
|
||
| function handleMenuOpening({delegateTarget: dropdown}: DelegateEvent): void { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import React from 'dom-chef'; | ||
|
|
||
| export function registerHotkey(hotkey: string, action: VoidFunction | string): Deinit { | ||
| const element = typeof action === 'string' | ||
| ? <a hidden href={action} data-hotkey={hotkey}/> | ||
|
Member
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. I also added support for strings, but haven't found any use for it where it would simplify the code.
Member
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. What if we treat this string as a selector and do To emulate link behavior, just pass an action of
Member
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.
addHotkey already does that: registerHotkey('ctrl-a', 'a[blah]') // Your suggestion
addHotkey(select('a[blah]'), 'ctrl-a') // Already-possible solution
There's no substitute for real links (which can be handled by Turbo as well). I do see two possible improvements here:
|
||
| : <button hidden type="button" data-hotkey={hotkey} onClick={action}/>; | ||
|
|
||
| document.body.append(element); | ||
|
|
||
| return () => { | ||
| element.remove(); | ||
| }; | ||
| } | ||
|
|
||
| /** Safely add a hotkey to an element, preserving any existing ones and avoiding duplicates */ | ||
| export const addHotkey = (button: HTMLAnchorElement | HTMLButtonElement | undefined, hotkey: string): void => { | ||
| if (button) { | ||
| const hotkeys = new Set(button.dataset.hotkey?.split(',')); | ||
| hotkeys.add(hotkey); | ||
| button.dataset.hotkey = [...hotkeys].join(','); | ||
| } | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import {test, assert} from 'vitest'; | ||
|
|
||
| import { | ||
| addHotkey, | ||
| } from './hotkey'; | ||
|
|
||
| const testAddHotkey = (existing: string | undefined, added: string, final: string): void => { | ||
| const link = document.createElement('a'); | ||
| if (existing) { | ||
| link.setAttribute('data-hotkey', existing); | ||
| } | ||
|
|
||
| addHotkey(link, added); | ||
| assert.equal(link.dataset.hotkey, final); | ||
| }; | ||
|
|
||
| test('addHotkey if one is specified', testAddHotkey.bind(null, | ||
| 'T-REX', | ||
| 'CHICKEN', | ||
| 'T-REX,CHICKEN', | ||
| )); | ||
| test('addHotkey if the same is already specified', testAddHotkey.bind(null, | ||
| 'CHICKEN', | ||
| 'CHICKEN', | ||
| 'CHICKEN', | ||
| )); | ||
| test('addHotkey when none are specified', testAddHotkey.bind(null, | ||
| undefined, | ||
| 'CHICKEN', | ||
| 'CHICKEN', | ||
| )); |
This file was deleted.
This file was deleted.
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.
This was needed because we kept the dropdown open, I think. Since the dropdown now closes on click, the user cannot double click. By the time they manage to open the menu and click again, it's probably done and the file is gone.