Skip to content

Commit

Permalink
fix: multi select was not including the values
Browse files Browse the repository at this point in the history
  • Loading branch information
danielo515 committed Sep 15, 2023
1 parent 7425df1 commit 1885834
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/utils/array.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

/**
* Utility function to remove an element from an array in-place.
* I'm not a fan of this kind of practices, but Obsidian is higly OOP
* and relies in mutation heavily, as as Svelte (the used UI library).
* This is the simplest way to make sure the data in the UI represents
* the data in the app.
**/
export function remove_inplace<T>(arr: Array<T>, value: T): void {
const index = arr.indexOf(value);
if (index > -1) {
arr.splice(index, 1);
}
}
6 changes: 4 additions & 2 deletions src/views/components/MultiSelect.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import type { Setting } from "obsidian";
import { remove_inplace } from "../../utils/array";
import { MultiSuggest } from "../../suggesters/MultiSuggest";
export let selectedVales: string[] = [];
Expand All @@ -16,12 +17,13 @@
function createInput(element: HTMLInputElement) {
new MultiSuggest(element, remainingOptions, (selected) => {
selectedVales.push(selected);
selectedVales = [...new Set(selectedVales)];
remainingOptions.delete(selected);
selectedVales = selectedVales;
});
}
function reomoveValue(value: string) {
selectedVales = selectedVales.filter((v) => v !== value);
remove_inplace(selectedVales, value);
selectedVales = selectedVales;
remainingOptions.add(value);
}
</script>
Expand Down

0 comments on commit 1885834

Please sign in to comment.