mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
Fix issues with sometimes cause assignment of wrong position value
This commit is contained in:
parent
59c5ecd4fc
commit
9cc0d0a01c
3 changed files with 19 additions and 13 deletions
|
@ -41,15 +41,17 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
makeInterface(makeRegistration);
|
||||
|
||||
$: for (const [index, item] of $items.entries()) {
|
||||
item.position.update(() => {
|
||||
if ($items.length === 1) {
|
||||
item.position.set(ButtonPosition.Standalone);
|
||||
return ButtonPosition.Standalone;
|
||||
} else if (index === 0) {
|
||||
item.position.set(ButtonPosition.Leftmost);
|
||||
return ButtonPosition.Leftmost;
|
||||
} else if (index === $items.length - 1) {
|
||||
item.position.set(ButtonPosition.Rightmost);
|
||||
return ButtonPosition.Rightmost;
|
||||
} else {
|
||||
item.position.set(ButtonPosition.Center);
|
||||
return ButtonPosition.Center;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
setContext(buttonGroupKey, registerComponent);
|
||||
|
@ -99,7 +101,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
role="group"
|
||||
>
|
||||
<slot />
|
||||
{#each $dynamicItems as item}
|
||||
{#each $dynamicItems as item (item[0].id)}
|
||||
<ButtonGroupItem id={item[0].id} registration={item[1]}>
|
||||
<svelte:component this={item[0].component} {...item[0].props} />
|
||||
</ButtonGroupItem>
|
||||
|
|
|
@ -50,8 +50,11 @@ export function makeInterface<T extends Registration>(
|
|||
index: number = registrations.length,
|
||||
registration = makeRegistration()
|
||||
): T {
|
||||
items.update((registrations) => {
|
||||
registrations.splice(index, 0, registration);
|
||||
items.set(registrations);
|
||||
return registrations;
|
||||
});
|
||||
|
||||
return registration;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
import WithState from "components/WithState.svelte";
|
||||
|
||||
import * as contextKeys from "components/context-keys";
|
||||
import * as editorContextKeys from "./context-keys";
|
||||
|
||||
export const components = {
|
||||
IconButton,
|
||||
|
@ -17,6 +18,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
WithShortcut,
|
||||
WithContext,
|
||||
WithState,
|
||||
contextKeys,
|
||||
contextKeys: { ...contextKeys, ...editorContextKeys },
|
||||
};
|
||||
</script>
|
||||
|
|
Loading…
Reference in a new issue