Skip to content

Commit

Permalink
fix(config-editor): fix insert 0
Browse files Browse the repository at this point in the history
  • Loading branch information
jersou committed Apr 17, 2023
1 parent ffbda1c commit 8590d1f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ cargo build --release

### Medium

* Shape event use also the screen edges/corners : adapt the filter or the GUI (
bug or feature ?)
* create ~/.config if it doesn't exist
* fix exec cmd
error `Err(Os { code: 2, kind: NotFound, message: "No such file or directory" })`
Expand Down
43 changes: 23 additions & 20 deletions config-editor/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,29 +98,26 @@ export default function App() {
const addBinding = useCallback(
(binding?: BindingType) => {
setConfig((prevConfig) => {
const index = binding
? prevConfig?.bindings.findIndex((b) => b.uid === binding.uid)
: undefined;
const index = prevConfig?.bindings.findIndex(
(b) => b.uid === binding?.uid
);

const newConfig: ConfigType = {
shape_button: prevConfig?.shape_button || "Right",
bindings: [...(prevConfig?.bindings || [])],
};
newConfig.bindings?.splice(
(index || newConfig.bindings.length) + 1,
0,
{
uid: self.crypto.randomUUID(),
cmd: ["TODO"],
comment: "TODO",
event: {
button: "Right",
event_type: "Click",
edges: ["Top"],
modifiers: [],
shapes_xy: [],
},
}
);
newConfig.bindings?.splice((index ?? -1) + 1, 0, {
uid: self.crypto.randomUUID(),
cmd: ["TODO"],
comment: "TODO",
event: {
button: "Right",
event_type: "Click",
edges: ["Top"],
modifiers: [],
shapes_xy: [],
},
});
return newConfig;
});
},
Expand Down Expand Up @@ -212,7 +209,13 @@ export default function App() {
justifyContent: "center",
}}
>
<Button variant="contained" size="small" onClick={() => addBinding()}>
<Button
variant="contained"
size="small"
onClick={() =>
addBinding(config?.bindings[config.bindings.length - 1])
}
>
<AddIcon /> Add a binding
</Button>
</div>
Expand Down

0 comments on commit 8590d1f

Please sign in to comment.