Skip to content

Commit b979fc3

Browse files
committed
move setLayout to LayoutStore
1 parent cddec7d commit b979fc3

File tree

2 files changed

+29
-23
lines changed

2 files changed

+29
-23
lines changed

src/engine.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class TilingEngine {
167167
this.nextLayout();
168168
break;
169169
case UserInput.SetLayout:
170-
this.setLayout(data);
170+
this.layouts.setLayout(this.driver.getCurrentContext(), data);
171171
break;
172172
}
173173
this.arrange();
@@ -227,20 +227,6 @@ class TilingEngine {
227227
this.layouts.cycleLayout(this.driver.getCurrentContext());
228228
}
229229

230-
public setLayout(cls: any) {
231-
const ctx = this.driver.getCurrentContext();
232-
const lastLayout = this.layouts.getCurrentLayout(ctx);
233-
for (;;) {
234-
this.layouts.cycleLayout(ctx);
235-
236-
const layout = this.layouts.getCurrentLayout(ctx);
237-
if (layout instanceof cls)
238-
break;
239-
if (layout === lastLayout)
240-
break;
241-
}
242-
}
243-
244230
/*
245231
* Privates
246232
*/

src/layoutstore.ts

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,17 @@ class LayoutStore {
2929
if (ctx.skipTiling)
3030
return null;
3131

32-
if (!this.store[ctx.path])
33-
this.initEntry(ctx.path);
32+
const entry = this.getEntry(ctx.path);
3433

3534
// TODO: if no layout, return floating layout, which is a static object.
36-
return this.store[ctx.path][0];
35+
return entry[0];
3736
}
3837

3938
public cycleLayout(ctx: Context) {
40-
const entry = this.store[ctx.path];
41-
if (!entry) {
42-
this.initEntry(ctx.path);
43-
return;
44-
}
39+
if (ctx.skipTiling)
40+
return null;
4541

42+
const entry = this.getEntry(ctx.path);
4643
for (;;) {
4744
const layout = entry.shift();
4845
if (!layout)
@@ -55,6 +52,29 @@ class LayoutStore {
5552
}
5653
}
5754

55+
public setLayout(ctx: Context, cls: any) {
56+
if (ctx.skipTiling)
57+
return;
58+
59+
const entry = this.getEntry(ctx.path);
60+
const result = entry.filter((l) => l instanceof cls);
61+
if (result.length === 0)
62+
return;
63+
64+
const layout = result[0];
65+
if (!layout.enabled)
66+
return;
67+
68+
const idx = entry.indexOf(layout);
69+
entry.push(...entry.splice(0, idx));
70+
}
71+
72+
private getEntry(key: string): ILayout[] {
73+
if (!this.store[key])
74+
this.initEntry(key);
75+
return this.store[key];
76+
}
77+
5878
private initEntry(key: string) {
5979
const entry = [];
6080
// TODO: user config

0 commit comments

Comments
 (0)