Skip to content

Commit 0ac6f54

Browse files
authored
Merge pull request #442 from k1LoW/fix-with-freeze
fix: when slide pages are added or moved, the freeze option does not behave correctly.
2 parents 9d24bb6 + be17338 commit 0ac6f54

File tree

3 files changed

+115
-3
lines changed

3 files changed

+115
-3
lines changed

action.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ func generateActions(before, after Slides) (_ []*action, err error) {
5959
return nil, fmt.Errorf("failed to adjust slide count: %w", err)
6060
}
6161

62+
// Prevent actions from being generated from indexes that should be frozen.
63+
for i, afterSlide := range adjustedAfter {
64+
if afterSlide.Freeze {
65+
adjustedBefore[i] = copySlide(afterSlide)
66+
}
67+
}
68+
6269
// Map slides algorithm
6370
mapping, err := mapSlides(adjustedBefore, adjustedAfter)
6471
if err != nil {
@@ -78,7 +85,7 @@ func generateActions(before, after Slides) (_ []*action, err error) {
7885
updateActions := generateUpdateActions(adjustedBefore, adjustedAfter, mapping)
7986
actions = append(actions, updateActions...)
8087

81-
// Remove .delete slides from after
88+
// Remove delete slides from after
8289
cleanedAfter := removeDeleteMarked(adjustedAfter)
8390

8491
// Generate delete actions

action_test.go

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ var tests = []struct {
2929
name string
3030
before Slides
3131
after Slides
32+
want Slides // Expected result when freeze functionality is properly implemented
3233
}{
3334
{
3435
name: "empty slides",
@@ -1608,6 +1609,96 @@ var tests = []struct {
16081609
},
16091610
},
16101611
},
1612+
{
1613+
name: "freeze slide moved",
1614+
before: Slides{
1615+
{
1616+
Layout: "title",
1617+
Titles: []string{"Slide A"},
1618+
TitleBodies: toBodies([]string{"Slide A"}),
1619+
},
1620+
{
1621+
Layout: "title",
1622+
Titles: []string{"Slide B"},
1623+
TitleBodies: toBodies([]string{"Slide B"}),
1624+
},
1625+
{
1626+
Layout: "title",
1627+
Titles: []string{"Slide C"},
1628+
TitleBodies: toBodies([]string{"Slide C"}),
1629+
},
1630+
},
1631+
after: Slides{
1632+
{
1633+
Layout: "title",
1634+
Titles: []string{"Slide A"},
1635+
TitleBodies: toBodies([]string{"Slide A"}),
1636+
},
1637+
{
1638+
Layout: "title",
1639+
Titles: []string{"Slide C"},
1640+
TitleBodies: toBodies([]string{"Slide C"}),
1641+
},
1642+
{
1643+
Layout: "title",
1644+
Titles: []string{"Slide B"},
1645+
TitleBodies: toBodies([]string{"Slide B"}),
1646+
Freeze: true,
1647+
},
1648+
},
1649+
want: Slides{
1650+
{
1651+
Layout: "title",
1652+
Titles: []string{"Slide A"},
1653+
TitleBodies: toBodies([]string{"Slide A"}),
1654+
},
1655+
{
1656+
Layout: "title",
1657+
Titles: []string{"Slide C"},
1658+
TitleBodies: toBodies([]string{"Slide C"}),
1659+
},
1660+
{
1661+
Layout: "title",
1662+
Titles: []string{"Slide C"},
1663+
TitleBodies: toBodies([]string{"Slide C"}),
1664+
},
1665+
},
1666+
},
1667+
{
1668+
name: "freeze slide with append",
1669+
before: Slides{
1670+
{
1671+
Layout: "title",
1672+
Titles: []string{"Slide A'"},
1673+
TitleBodies: toBodies([]string{"Slide A'"}),
1674+
},
1675+
},
1676+
after: Slides{
1677+
{
1678+
Layout: "title",
1679+
Titles: []string{"Slide A"},
1680+
TitleBodies: toBodies([]string{"Slide A"}),
1681+
Freeze: true,
1682+
},
1683+
{
1684+
Layout: "title",
1685+
Titles: []string{"Slide B"},
1686+
TitleBodies: toBodies([]string{"Slide B"}),
1687+
},
1688+
},
1689+
want: Slides{
1690+
{
1691+
Layout: "title",
1692+
Titles: []string{"Slide A'"},
1693+
TitleBodies: toBodies([]string{"Slide A'"}),
1694+
},
1695+
{
1696+
Layout: "title",
1697+
Titles: []string{"Slide B"},
1698+
TitleBodies: toBodies([]string{"Slide B"}),
1699+
},
1700+
},
1701+
},
16111702
}
16121703

16131704
func TestGenerateActions(t *testing.T) {
@@ -1624,7 +1715,14 @@ func TestGenerateActions(t *testing.T) {
16241715
t.Fatal(err)
16251716
}
16261717
got := actionsEmulator(t, tt.before, actions)
1627-
if diff := cmp.Diff(got, tt.after, cmpopts...); diff != "" {
1718+
1719+
// Use tt.want if provided, otherwise fallback to tt.after
1720+
want := tt.after
1721+
if tt.want != nil {
1722+
want = tt.want
1723+
}
1724+
1725+
if diff := cmp.Diff(got, want, cmpopts...); diff != "" {
16281726
t.Error(diff)
16291727
}
16301728
})

integration_apply_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,14 @@ func TestApply(t *testing.T) {
5656
if err != nil {
5757
t.Fatal(err)
5858
}
59-
if diff := cmp.Diff(after, tt.after, cmpopts...); diff != "" {
59+
60+
// Use tt.want if provided, otherwise fallback to tt.after
61+
want := tt.after
62+
if tt.want != nil {
63+
want = tt.want
64+
}
65+
66+
if diff := cmp.Diff(after, want, cmpopts...); diff != "" {
6067
t.Error(diff)
6168
}
6269
})

0 commit comments

Comments
 (0)