Skip to content

Commit d2cdb6c

Browse files
committed
should find pivot in next selection after adjacent
1 parent 247f1fb commit d2cdb6c

File tree

4 files changed

+72
-7
lines changed

4 files changed

+72
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "macos-multi-select",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "Given a list of ids, and an action, return a list of selected items with the same behaviour of macOS finder list view selection.",
55
"main": "dist/index.js",
66
"repository": "[email protected]:codingedgar/macos-multi-select.git",

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export function multiselect(context: Context, command: Command): Context {
4949
const adjacentPivot = findNextPivot(
5050
context.list,
5151
selected,
52-
context.adjacentPivot
52+
command.id
5353
);
5454

5555
return {

src/spec/arrayUtils.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,17 +168,17 @@ describe('find next pivot', () => {
168168
.chain(sortedArray =>
169169
fc
170170
.nat(sortedArray.length - 2)
171-
.chain(index =>
171+
.chain(previousPivot =>
172172
fc
173-
.integer(index + 1, sortedArray.length -1)
173+
.integer(previousPivot + 1, sortedArray.length - 1)
174174
.chain(nextPivot =>
175175
fc.
176176
tuple(
177-
fc.shuffledSubarray(sortedArray.slice(0, index)),
178-
fc.shuffledSubarray(sortedArray.slice(nextPivot +1, sortedArray.length - 1))
177+
fc.shuffledSubarray(sortedArray.slice(0, previousPivot)),
178+
fc.shuffledSubarray(sortedArray.slice(nextPivot + 1, sortedArray.length - 1))
179179
)
180180
.map(([left, right]) => ({
181-
previousPivot: sortedArray[index],
181+
previousPivot: sortedArray[previousPivot],
182182
sortedArray: sortedArray,
183183
nextPivot: sortedArray[nextPivot],
184184
selection: left.concat([sortedArray[nextPivot]]).concat(right)

src/spec/toggleSelection.spec.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,69 @@ describe('Toggle Selection', () => {
7171
)
7272
)
7373
});
74+
75+
76+
test('should find pivot in next selection even when pivot is in the initial state due to select adjacent on initial state', () => {
77+
fc.assert(
78+
fc.property(
79+
fc.set(
80+
fc.string(),
81+
{ minLength: 2 }
82+
)
83+
.chain(sortedArray =>
84+
fc
85+
.nat(sortedArray.length -2)
86+
.chain(previousSelection =>
87+
fc
88+
.integer(previousSelection + 1, sortedArray.length - 1)
89+
.chain(nextPivot =>
90+
fc.
91+
tuple(
92+
fc.constant(sortedArray.slice(0, previousSelection)),
93+
fc.shuffledSubarray(sortedArray.slice(nextPivot + 1, sortedArray.length - 1))
94+
)
95+
.map(([left, right]) => ({
96+
sortedArray: sortedArray,
97+
previousPivot: head(sortedArray)!,
98+
prevSelection: left
99+
.concat([sortedArray[previousSelection]])
100+
.concat([sortedArray[nextPivot]])
101+
.concat(right),
102+
deselectId: sortedArray[previousSelection],
103+
nextPivot: sortedArray[nextPivot],
104+
nextSelection: left
105+
.concat([sortedArray[nextPivot]])
106+
.concat(right),
107+
}))
108+
),
109+
),
110+
)
111+
,
112+
({
113+
previousPivot,
114+
sortedArray,
115+
prevSelection,
116+
nextSelection,
117+
nextPivot,
118+
deselectId
119+
}) => {
120+
expect(
121+
multiselect({
122+
adjacentPivot: previousPivot,
123+
list: sortedArray,
124+
selected: prevSelection
125+
}, {
126+
type: "TOGGLE SELECTION",
127+
id: deselectId
128+
}
129+
)
130+
).toEqual({
131+
list: sortedArray,
132+
adjacentPivot: nextPivot,
133+
selected: nextSelection
134+
})
135+
}
136+
)
137+
)
138+
})
74139
})

0 commit comments

Comments
 (0)