Skip to content

Commit

Permalink
Fix undo shortcut triggering in places it shouldn't be (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyec committed May 24, 2023
1 parent 813906a commit 0c89fe6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/popup/components/context_menu/index.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React, { useEffect, useLayoutEffect, useRef, useState } from 'react';

import { clamp } from '../../lib/clamp';

import './context_menu.css';

const PADDING = 5;
Expand Down Expand Up @@ -117,6 +115,10 @@ export default function ContextMenu({

useEffect(() => {
const handleKeyDown = (event) => {
if (event.code === 'KeyZ' && event.metaKey) {
dismiss();
}

if (executingAction) {
return;
}
Expand Down
8 changes: 8 additions & 0 deletions src/popup/components/text_field/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ export default function TextField({
}) {
const [value, setValue] = useState(defaultValue);

const handleKeyDown = (event) => {
if (event.code === 'KeyZ' && event.metaKey) {
// Prevent undo hook from happening, but allow undo in the textfield.
event.stopPropagation();
}
};

// When `defaultValue` prop changes, change the local state with that value.
useEffect(() => {
setValue(defaultValue);
Expand All @@ -26,6 +33,7 @@ export default function TextField({
className="text-field__input"
type="text"
value={value}
onKeyDown={handleKeyDown}
onChange={handleOnChange}
/>
</div>
Expand Down

0 comments on commit 0c89fe6

Please sign in to comment.