Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(soup): shift click multi select (#253)

Seamus60f984cc0a1f
diff --git a/js/app/packages/app/component/UnifiedListView.tsx b/js/app/packages/app/component/UnifiedListView.tsx
index c0c31bbac5..306d1de5af 100644
--- a/js/app/packages/app/component/UnifiedListView.tsx
+++ b/js/app/packages/app/component/UnifiedListView.tsx
@@ -937,6 +937,13 @@ export function UnifiedListView(props: UnifiedListViewProps) {
}
});
+ let lastClickedEntityId = -1;
+ createEffect(
+ on(view, () => {
+ lastClickedEntityId = -1;
+ })
+ );
+
return (
<>
<Show when={!props.hideToolbar}>
@@ -1280,17 +1287,77 @@ export function UnifiedListView(props: UnifiedListViewProps) {
isPanelActive() && focusedSelector(innerProps.entity.id)
}
checked={selectedSelector(innerProps.entity.id)}
- onChecked={(next) => {
- unifiedListContext.setViewDataStore(
- selectedView(),
- 'selectedEntities',
- (p) => {
- if (!next) {
- return p.filter((e) => e.id !== innerProps.entity.id);
+ onChecked={(next, shiftKey) => {
+ const toggleSingle = () =>
+ unifiedListContext.setViewDataStore(
+ selectedView(),
+ 'selectedEntities',
+ (p) => {
+ if (!next) {
+ return p.filter(
+ (e) => e.id !== innerProps.entity.id
+ );
+ }
+ return p.concat(innerProps.entity);
+ }
+ );
+
+ if (shiftKey) {
+ const entityList = unifiedListContext.entitiesSignal[0]();
+ if (!entityList) return;
+
+ const selectedEntitySet = new Set(
+ unifiedListContext.viewsDataStore[
+ unifiedListContext.selectedView()
+ ].selectedEntities
+ );
+ const newEnititiesForSeleciton: EntityData[] = [];
+
+ // Try to grab the last clicked item and fall back on
+ // the highest currently selected index.
+ let anchorIndex = lastClickedEntityId;
+ if (anchorIndex === -1) {
+ for (let i = 0; i < entityList.length; i++) {
+ if (selectedEntitySet.has(entityList[i])) {
+ anchorIndex = i;
+ }
}
- return p.concat(innerProps.entity);
}
- );
+
+ if (anchorIndex === -1) {
+ toggleSingle();
+ lastClickedEntityId = innerProps.index;
+ return;
+ }
+
+ const targetIndex = innerProps.index;
+ const sign = Math.sign(targetIndex - anchorIndex);
+ if (anchorIndex === targetIndex) {
+ // no_op
+ } else {
+ for (
+ let i = anchorIndex;
+ sign > 0 ? i <= targetIndex : i >= targetIndex;
+ i += sign
+ ) {
+ const entity = entityList[i];
+ if (!selectedEntitySet.has(entity)) {
+ newEnititiesForSeleciton.push(entity);
+ }
+ }
+ }
+ unifiedListContext.setViewDataStore(
+ selectedView(),
+ 'selectedEntities',
+ (p) => {
+ return p.concat(newEnititiesForSeleciton);
+ }
+ );
+ lastClickedEntityId = innerProps.index;
+ } else {
+ toggleSingle();
+ lastClickedEntityId = innerProps.index;
+ }
}}
/>
);
diff --git a/js/app/packages/macro-entity/src/components/EntityWithEverything.tsx b/js/app/packages/macro-entity/src/components/EntityWithEverything.tsx
index 6921fed6dd..904b5c01a0 100644
--- a/js/app/packages/macro-entity/src/components/EntityWithEverything.tsx
+++ b/js/app/packages/macro-entity/src/components/EntityWithEverything.tsx
@@ -98,7 +98,7 @@ interface EntityProps<T extends WithNotification<EntityData>>
highlighted?: boolean;
selected?: boolean;
ref?: Ref<HTMLDivElement>;
- onChecked?: (checked: boolean) => void;
+ onChecked?: (checked: boolean, shiftKey?: boolean) => void;
checked?: boolean;
}
@@ -407,8 +407,8 @@ export function EntityWithEverything(
<button
type="button"
class="col-1 size-full relative group/button flex items-center justify-center"
- onClick={() => {
- props.onChecked?.(!props.checked);
+ onClick={(e) => {
+ props.onChecked?.(!props.checked, e.shiftKey);
}}
data-blocks-navigation
>
@@ -689,7 +689,7 @@ function DirectMessageIcon(props: { entity: EntityData }) {
return (
<div class="bg-panel size-5 rounded-full p-[2px]">
<Show when={participantId()} fallback={<Fallback />}>
- {(id) => <UserIcon id={id()} isDeleted={false} size="fill" />}
+ {(id) => <UserIcon id={id()} isDeleted={false} size="xs" />}
</Show>
</div>
);