Skip to content

Commit 9b41000

Browse files
committed
fix: Selection state fixes.
* Reset layer and key position selections on connection changes. * Properly handle displaying layer picker with an invalid selected layer.
1 parent ffd42ee commit 9b41000

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/keyboard/Keyboard.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ export default function Keyboard() {
180180
const conn = useContext(ConnectionContext);
181181
const undoRedo = useContext(UndoRedoContext);
182182

183+
useEffect(() => {
184+
setSelectedLayerIndex(0);
185+
setSelectedKeyPosition(undefined);
186+
}, [conn]);
187+
183188
useEffect(() => {
184189
async function performSetRequest() {
185190
if (!conn.conn || !layouts) {

src/keyboard/LayerPicker.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ interface LayerPickerProps {
3131
onLayerNameChanged?: (
3232
id: number,
3333
oldName: string,
34-
newName: string,
34+
newName: string
3535
) => void | Promise<void>;
3636
}
3737

@@ -52,7 +52,7 @@ const EditLabelModal = ({
5252
handleSaveNewLabel: (
5353
id: number,
5454
oldName: string,
55-
newName: string | null,
55+
newName: string | null
5656
) => void;
5757
}) => {
5858
const ref = useModalRef(open);
@@ -114,7 +114,7 @@ export const LayerPicker = ({
114114
...props
115115
}: LayerPickerProps) => {
116116
const [editLabelData, setEditLabelData] = useState<EditLabelData | null>(
117-
null,
117+
null
118118
);
119119

120120
const layer_items = useMemo(() => {
@@ -134,7 +134,7 @@ export const LayerPicker = ({
134134

135135
onLayerClicked?.(layer_items.findIndex((l) => s.has(l.id)));
136136
},
137-
[onLayerClicked, layer_items],
137+
[onLayerClicked, layer_items]
138138
);
139139

140140
let { dragAndDropHooks } = useDragAndDrop({
@@ -161,7 +161,7 @@ export const LayerPicker = ({
161161
onLayerNameChanged?.(id, oldName, newName);
162162
}
163163
},
164-
[onLayerNameChanged],
164+
[onLayerNameChanged]
165165
);
166166

167167
return (
@@ -202,7 +202,11 @@ export const LayerPicker = ({
202202
selectionMode="single"
203203
items={layer_items}
204204
disallowEmptySelection={true}
205-
selectedKeys={[layer_items[selectedLayerIndex].id]}
205+
selectedKeys={
206+
layer_items[selectedLayerIndex]
207+
? [layer_items[selectedLayerIndex].id]
208+
: []
209+
}
206210
className="ml-2 items-center justify-center cursor-pointer"
207211
onSelectionChange={selectionChanged}
208212
dragAndDropHooks={dragAndDropHooks}

0 commit comments

Comments
 (0)