Skip to content

Commit

Permalink
Merge branch 'master' into visual/dynamic-layout
Browse files Browse the repository at this point in the history
  • Loading branch information
yeze322 committed Feb 21, 2020
2 parents fefd425 + b58fa5b commit a0c7c94
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const KeyNameByModifierAttr = {
const overriddenKeyCodes = ['Tab', 'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'];

interface KeyboardZoneProps {
when: string;
onCommand: (action, e: KeyboardEvent) => object | void;
}

Expand All @@ -35,7 +34,7 @@ const buildModifierKeyPrefix = (e: KeyboardEvent): string => {
return prefix;
};

export const KeyboardZone: FC<KeyboardZoneProps> = ({ when, onCommand, children }): JSX.Element => {
export const KeyboardZone: FC<KeyboardZoneProps> = ({ onCommand, children }): JSX.Element => {
const handleKeyDown = e => {
if (overriddenKeyCodes.includes(e.key)) {
e.preventDefault();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,22 +182,12 @@ export const ObiEditor: FC<ObiEditorProps> = ({
selectedIds: [],
});

const [keyboardStatus, setKeyBoardStatus] = useState('normal');

useEffect((): void => {
// Notify container at every selection change.
onSelect(selectionContext.selectedIds.length ? selectionContext.selectedIds : focusedId ? [focusedId] : []);
}, [focusedId, selectionContext]);

useEffect((): void => {
if (selectionContext.selectedIds.length > 0) {
setKeyBoardStatus('selected');
} else if (focusedId) {
setKeyBoardStatus('focused');
} else {
setKeyBoardStatus('normal');
}

selection.setItems(nodeIndexGenerator.current.getItemList());
});

Expand Down Expand Up @@ -296,7 +286,7 @@ export const ObiEditor: FC<ObiEditorProps> = ({
if (!data) return renderFallbackContent();
return (
<SelectionContext.Provider value={selectionContext}>
<KeyboardZone onCommand={handleKeyboardCommand} when={keyboardStatus}>
<KeyboardZone onCommand={handleKeyboardCommand}>
<MarqueeSelection selection={selection} css={{ width: '100%', height: '100%' }}>
<div
tabIndex={0}
Expand Down

0 comments on commit a0c7c94

Please sign in to comment.