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

Feature/react managed undo #1135

Merged

Conversation

tomrule007
Copy link
Contributor

Updates #1125

what

Manage undo/redo state for <MdInput/> component (the comment input box) inside of react and bind hotkeys.

why

Using a controlled react input component only preserves native undo/redo functionality when the component is updated with the onChange event handler from the controlled component itself.

Adding more advanced features like

  • Auto closing brackets
  • List continuation on return
  • Markdown style buttons

requires manualing updating the state which in turn wipes out the native undo/redo functionality.

how

  • Adds internal state to MdInput to track undo/redo history with 3rd party package useUndo
    • * I chose a separate internal state to not making it any more difficult to use the component or have this abstraction leak outside the component itself.
  • Creates hotkeyListener utility to bind new undo/redo functionality over the native key bindings and prevent defaults

Checklist:

  • Tests
  • Typescript definitions updated
  • Ready to be merged

(PS: i took this simple PR template from testing-library/react-testing-library)

@vercel
Copy link

vercel bot commented Sep 30, 2021

@tomrule007 is attempting to deploy a commit to a Personal Account owned by @garageScript on Vercel.

@garageScript first needs to authorize it.

@vercel
Copy link

vercel bot commented Sep 30, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/c0d3/c0d3-app/7gyjj3Z3MoDYPEwcuUpDstbmA83K
✅ Preview: https://c0d3-app-git-fork-tomrule007-feature-react-managed-undo-c0d3.vercel.app

@codecov
Copy link

codecov bot commented Sep 30, 2021

Codecov Report

Merging #1135 (a23f51c) into master (9df2d24) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master     #1135   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          139       141    +2     
  Lines         2223      2263   +40     
  Branches       551       559    +8     
=========================================
+ Hits          2223      2263   +40     
Impacted Files Coverage Δ
components/MdInput.tsx 100.00% <100.00%> (ø)
helpers/hotkeyListener.ts 100.00% <100.00%> (ø)
components/AppNav.tsx 100.00% <0.00%> (ø)
components/LogoutContainer.tsx 100.00% <0.00%> (ø)

@tomrule007 tomrule007 merged commit 40e13f7 into garageScript:master Oct 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants