-
Couldn't load subscription status.
- Fork 39
Undo shortcut #47
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
Undo shortcut #47
Conversation
| function TodoApp(props: TodoAppProps) { | ||
| const { defaultItems = [], onChange } = props; | ||
| const [items, setItems] = useState<TodoItem[]>(defaultItems); | ||
| const [undo, setUndo] = useState<TodoItem[]>(defaultItems); |
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 should be an array right?
In this implementation undo will only work for single undo but multiple undo should also work.
|
|
||
| }; | ||
| const handleKeyPress = (event: any) => { | ||
| if (`${event.key}` == 'z' && `${event.key.control}`) { |
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.
The name of the function is misleading as keypress is another event. Also please use type for event instead of any.
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.
i used " keyboardEvent" but throw error and shortcuts don't work
Type '(event: KeyboardEvent) => void' is not assignable to type 'EventListener'.
Types of parameters 'event' and 'evt' are incompatible.
Type 'Event' is missing the following properties from type 'KeyboardEvent': altKey, charCode, ctrlKey, code, and 15 more
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.
okay. You can ignore the type issue. Please fix the undo behavier for a textfield and outside text field as mentioned in this comment.
#47 (comment)
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.
@kamalkishor1991 while focus on item undo work on text otherwise on multiple items
but i have problem when i passing props from todo to item
"i am not good with typscript"
|
@AnasMansy thanks for the pull request. Overall approach looks good to me. I think we should store full item state in the undo stack and priodically push state into the stack on change and update the whole state from the stack on pressing undo. |
|
@kamalkishor1991, I wonder if it's a duplicate one then should be closed. I think we have covered this functionality on this Pull Request |
for undo using "ctrl + z "
I've added support for undo using shortcuts implement undo functions.