-
Couldn't load subscription status.
- Fork 39
Feature/undo redo #56
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
Feature/undo redo #56
Conversation
shahanahmed86
commented
May 19, 2023
- listening to key-down events that'll trigger the undo or redo functionality.
- worked on some optimization like using memo/callback where needed.
- made update/remove callback on the Todo component and remove from deep down the tree to implement the undo/redo functionality
|
@shahanahmed86 thanks a lot for the pull request. I will review it in few days. |
@kamalkishor1991 this is my first contribution to the open-source community and I am not an expert on team collaboration and GITOPS things. If you found anything that I need to work on then please suggest me. |
src/components/Todo/Todo.tsx
Outdated
|
|
||
| useEffect(() => { | ||
| const onUndoOrRedo = ({ repeat, ctrlKey, key }: KeyboardEvent) => { | ||
| if (repeat || !ctrlKey) return; |
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.
we have to make sure this also works on mac, mobile and tablets etc. In Macbooks cmd + z is undo instead of ctrl + z
I think the right way to do this is to make a content editable div and listion for undo and redo events so that the right keyboard shortcuts are used accross all platforms.
You can explore more. One starting point is this stackoverflow question.
https://stackoverflow.com/questions/13319723/listen-to-undo-redo-event-in-contenteditable-div
Also for mobile and touch screens we can add undo and redo button at the top similar to google keep.
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 have visited the shared link but the InputEvent was not properly working with react, it triggers the callback too many times on a single key press. Instead, I've done my research on the KeyboardEvent and found that the metaKey boolean property gets true when:
- Command is pressed on Macbook
- Window is pressed on Linux/Windows
And I've tested it on Macbook it works like a charm. I have updated this pull request also
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 but the problem is that ⌘y is pressed it also opens the browser history and this is the browser behavior.
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.
@shahanahmed86 I think you should call event.preventDefault();
I tried google keep and it is able to handle cmd + y without opening browser history.
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, I've updated the pull request
…o merge/undo-redo-with-master
|
@kamalkishor1991, I've updated the pull request with all conflicts resolved and deployed the app on this URL. Please check the demo also before merging. |
|
@kamalkishor1991, The changes that you ask to fix are now updated in the last commit:
|
|
Thanks @shahanahmed86 for the PR and taking care of all the review comments. |
