Skip to content

Commit b21e6b6

Browse files
committed
feat: 增加t44, t66, t88, t22四个快捷键,用于快速改变子树的朝向
1 parent 6bbc967 commit b21e6b6

8 files changed

Lines changed: 228 additions & 0 deletions

File tree

app/src/core/service/controlService/keyboardOnlyEngine/keyboardOnlyTreeEngine.tsx

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,70 @@ import { Settings } from "../../Settings";
2121
export class KeyboardOnlyTreeEngine {
2222
constructor(private readonly project: Project) {}
2323

24+
/**
25+
* 方向取反
26+
*/
27+
private getOppositeDirection(direction: Direction): Direction {
28+
switch (direction) {
29+
case Direction.Left:
30+
return Direction.Right;
31+
case Direction.Right:
32+
return Direction.Left;
33+
case Direction.Up:
34+
return Direction.Down;
35+
case Direction.Down:
36+
return Direction.Up;
37+
}
38+
}
39+
40+
/**
41+
* 将一条边整体设置为标准方向连线。
42+
* 例如向左时,源端点贴左侧,目标端点贴右侧。
43+
*/
44+
private changeEdgeToDirection(edge: Edge, direction: Direction) {
45+
this.project.stageManager.changeEdgesConnectLocation([edge], direction, true);
46+
this.project.stageManager.changeEdgesConnectLocation([edge], this.getOppositeDirection(direction));
47+
}
48+
49+
/**
50+
* 以指定节点为子树根,递归修改整棵子树的边方向,
51+
* 并额外调整指向该根节点的父边,最后触发一次树形自动布局。
52+
*/
53+
private adjustSubtreeDirection(root: ConnectableEntity, direction: Direction) {
54+
const visitedNodeUUIDs = new Set<string>();
55+
56+
const dfs = (node: ConnectableEntity) => {
57+
if (visitedNodeUUIDs.has(node.uuid)) return;
58+
visitedNodeUUIDs.add(node.uuid);
59+
60+
const childEdges = this.project.graphMethods.edgeChildrenArray(node);
61+
for (const edge of childEdges) {
62+
this.changeEdgeToDirection(edge, direction);
63+
dfs(edge.target);
64+
}
65+
};
66+
67+
const parentEdges = this.project.graphMethods.edgeParentArray(root);
68+
for (const edge of parentEdges) {
69+
this.changeEdgeToDirection(edge, direction);
70+
}
71+
72+
dfs(root);
73+
this.project.autoAlign.autoLayoutSelectedFastTreeMode(root);
74+
}
75+
76+
/**
77+
* 对当前选中的所有可连接节点分别执行“以自身为根调整子树方向”。
78+
*/
79+
public adjustSelectedSubtreesDirection(direction: Direction) {
80+
const selectedRoots = this.project.stageManager
81+
.getSelectedEntities()
82+
.filter((entity) => entity instanceof ConnectableEntity);
83+
for (const root of selectedRoots) {
84+
this.adjustSubtreeDirection(root, direction);
85+
}
86+
}
87+
2488
/**
2589
* 获取节点的“预方向”
2690
* 如果有缓存,则拿缓存中的值,没有缓存,根据节点的入度线的方向,来判断“预方向”

app/src/core/service/controlService/shortcutKeysEngine/shortcutKeysRegister.tsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,6 +1826,46 @@ export const allKeyBinds: KeyBindItem[] = [
18261826
project?.controller.pressingKeySet.clear(); // 解决 mac 按下后容易卡键
18271827
},
18281828
},
1829+
{
1830+
id: "treeGraphAdjustSelectedAsRootToLeft",
1831+
defaultKey: "t 4 4",
1832+
icon: MoveLeft,
1833+
when: whenHasSelectedConnectableEntities,
1834+
onPress: (project) => {
1835+
project!.keyboardOnlyTreeEngine.adjustSelectedSubtreesDirection(Direction.Left);
1836+
project!.historyManager.recordStep();
1837+
},
1838+
},
1839+
{
1840+
id: "treeGraphAdjustSelectedAsRootToRight",
1841+
defaultKey: "t 6 6",
1842+
icon: MoveRight,
1843+
when: whenHasSelectedConnectableEntities,
1844+
onPress: (project) => {
1845+
project!.keyboardOnlyTreeEngine.adjustSelectedSubtreesDirection(Direction.Right);
1846+
project!.historyManager.recordStep();
1847+
},
1848+
},
1849+
{
1850+
id: "treeGraphAdjustSelectedAsRootToUp",
1851+
defaultKey: "t 8 8",
1852+
icon: MoveUp,
1853+
when: whenHasSelectedConnectableEntities,
1854+
onPress: (project) => {
1855+
project!.keyboardOnlyTreeEngine.adjustSelectedSubtreesDirection(Direction.Up);
1856+
project!.historyManager.recordStep();
1857+
},
1858+
},
1859+
{
1860+
id: "treeGraphAdjustSelectedAsRootToDown",
1861+
defaultKey: "t 2 2",
1862+
icon: MoveDown,
1863+
when: whenHasSelectedConnectableEntities,
1864+
onPress: (project) => {
1865+
project!.keyboardOnlyTreeEngine.adjustSelectedSubtreesDirection(Direction.Down);
1866+
project!.historyManager.recordStep();
1867+
},
1868+
},
18291869
{
18301870
id: "treeReverseX",
18311871
defaultKey: "t r x",

app/src/locales/en.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,6 +1369,30 @@ keyBinds:
13691369
description: |
13701370
Format the tree structure using the currently selected node as the root node.
13711371
Does not search for the root of the entire tree, only formats the subtree rooted at the selected node.
1372+
treeGraphAdjustSelectedAsRootToLeft:
1373+
title: Move Subtree to the Left Using Selected Node as Root
1374+
description: |
1375+
Treat the selected node as the root of a subtree.
1376+
Change all edges inside the subtree, as well as the parent edge pointing to the root node, to leftward edges.
1377+
Then auto-format the tree structure so the whole subtree moves to the left side.
1378+
treeGraphAdjustSelectedAsRootToRight:
1379+
title: Move Subtree to the Right Using Selected Node as Root
1380+
description: |
1381+
Treat the selected node as the root of a subtree.
1382+
Change all edges inside the subtree, as well as the parent edge pointing to the root node, to rightward edges.
1383+
Then auto-format the tree structure so the whole subtree moves to the right side.
1384+
treeGraphAdjustSelectedAsRootToUp:
1385+
title: Move Subtree Up Using Selected Node as Root
1386+
description: |
1387+
Treat the selected node as the root of a subtree.
1388+
Change all edges inside the subtree, as well as the parent edge pointing to the root node, to upward edges.
1389+
Then auto-format the tree structure so the whole subtree moves upward.
1390+
treeGraphAdjustSelectedAsRootToDown:
1391+
title: Move Subtree Down Using Selected Node as Root
1392+
description: |
1393+
Treat the selected node as the root of a subtree.
1394+
Change all edges inside the subtree, as well as the parent edge pointing to the root node, to downward edges.
1395+
Then auto-format the tree structure so the whole subtree moves downward.
13721396
undo:
13731397
title: Undo
13741398
description: Undo the last action

app/src/locales/id.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,6 +1882,30 @@ keyBinds:
18821882
description: |
18831883
Format struktur pohon dengan node yang dipilih saat ini sebagai node akar
18841884
Tidak akan mencari akar seluruh pohon, hanya memformat subpohon dengan node yang dipilih sebagai akar
1885+
treeGraphAdjustSelectedAsRootToLeft:
1886+
title: Pindahkan Subpohon ke Kiri dengan Node Terpilih sebagai Akar
1887+
description: |
1888+
Perlakukan node yang dipilih sebagai akar subpohon.
1889+
Ubah semua edge di dalam subpohon, serta edge induk yang mengarah ke node akar itu, menjadi edge ke kiri.
1890+
Lalu format ulang struktur pohon secara otomatis agar seluruh subpohon berpindah ke sisi kiri.
1891+
treeGraphAdjustSelectedAsRootToRight:
1892+
title: Pindahkan Subpohon ke Kanan dengan Node Terpilih sebagai Akar
1893+
description: |
1894+
Perlakukan node yang dipilih sebagai akar subpohon.
1895+
Ubah semua edge di dalam subpohon, serta edge induk yang mengarah ke node akar itu, menjadi edge ke kanan.
1896+
Lalu format ulang struktur pohon secara otomatis agar seluruh subpohon berpindah ke sisi kanan.
1897+
treeGraphAdjustSelectedAsRootToUp:
1898+
title: Pindahkan Subpohon ke Atas dengan Node Terpilih sebagai Akar
1899+
description: |
1900+
Perlakukan node yang dipilih sebagai akar subpohon.
1901+
Ubah semua edge di dalam subpohon, serta edge induk yang mengarah ke node akar itu, menjadi edge ke atas.
1902+
Lalu format ulang struktur pohon secara otomatis agar seluruh subpohon berpindah ke atas.
1903+
treeGraphAdjustSelectedAsRootToDown:
1904+
title: Pindahkan Subpohon ke Bawah dengan Node Terpilih sebagai Akar
1905+
description: |
1906+
Perlakukan node yang dipilih sebagai akar subpohon.
1907+
Ubah semua edge di dalam subpohon, serta edge induk yang mengarah ke node akar itu, menjadi edge ke bawah.
1908+
Lalu format ulang struktur pohon secara otomatis agar seluruh subpohon berpindah ke bawah.
18851909
dagGraphAdjust:
18861910
title: Sesuaikan Layout DAG Node yang Dipilih Saat Ini
18871911
description: |

app/src/locales/zh_CN.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,6 +1574,30 @@ keyBinds:
15741574
description: |
15751575
以当前选中的节点作为根节点进行树形结构格式化
15761576
不会查找整个树的根节点,只格式化以选中节点为根的子树
1577+
treeGraphAdjustSelectedAsRootToLeft:
1578+
title: 以选中节点为根,将子树整体调整到左侧
1579+
description: |
1580+
将选中节点视为子树根节点。
1581+
把子树内部所有连线,以及指向该根节点的父连线都改成左连线,
1582+
然后自动格式化树形结构,让整个子树调整到左边。
1583+
treeGraphAdjustSelectedAsRootToRight:
1584+
title: 以选中节点为根,将子树整体调整到右侧
1585+
description: |
1586+
将选中节点视为子树根节点。
1587+
把子树内部所有连线,以及指向该根节点的父连线都改成右连线,
1588+
然后自动格式化树形结构,让整个子树调整到右边。
1589+
treeGraphAdjustSelectedAsRootToUp:
1590+
title: 以选中节点为根,将子树整体调整到上侧
1591+
description: |
1592+
将选中节点视为子树根节点。
1593+
把子树内部所有连线,以及指向该根节点的父连线都改成上连线,
1594+
然后自动格式化树形结构,让整个子树调整到上方。
1595+
treeGraphAdjustSelectedAsRootToDown:
1596+
title: 以选中节点为根,将子树整体调整到下侧
1597+
description: |
1598+
将选中节点视为子树根节点。
1599+
把子树内部所有连线,以及指向该根节点的父连线都改成下连线,
1600+
然后自动格式化树形结构,让整个子树调整到下方。
15771601
dagGraphAdjust:
15781602
title: 调整当前选中节点群的DAG布局
15791603
description: |

app/src/locales/zh_TW.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,6 +1574,30 @@ keyBinds:
15741574
description: |
15751575
以當前選中的節點作為根節點進行樹形結構格式化
15761576
不會查找整個樹的根節點,只格式化以選中節點為根的子樹
1577+
treeGraphAdjustSelectedAsRootToLeft:
1578+
title: 以選中節點為根,將子樹整體調整到左側
1579+
description: |
1580+
將選中節點視為子樹根節點。
1581+
把子樹內部所有連線,以及指向該根節點的父連線都改成左連線,
1582+
然後自動格式化樹形結構,讓整個子樹調整到左邊。
1583+
treeGraphAdjustSelectedAsRootToRight:
1584+
title: 以選中節點為根,將子樹整體調整到右側
1585+
description: |
1586+
將選中節點視為子樹根節點。
1587+
把子樹內部所有連線,以及指向該根節點的父連線都改成右連線,
1588+
然後自動格式化樹形結構,讓整個子樹調整到右邊。
1589+
treeGraphAdjustSelectedAsRootToUp:
1590+
title: 以選中節點為根,將子樹整體調整到上側
1591+
description: |
1592+
將選中節點視為子樹根節點。
1593+
把子樹內部所有連線,以及指向該根節點的父連線都改成上連線,
1594+
然後自動格式化樹形結構,讓整個子樹調整到上方。
1595+
treeGraphAdjustSelectedAsRootToDown:
1596+
title: 以選中節點為根,將子樹整體調整到下側
1597+
description: |
1598+
將選中節點視為子樹根節點。
1599+
把子樹內部所有連線,以及指向該根節點的父連線都改成下連線,
1600+
然後自動格式化樹形結構,讓整個子樹調整到下方。
15771601
dagGraphAdjust:
15781602
title: 調整當前選中節點群的DAG佈局
15791603
description: |

app/src/locales/zh_TWC.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,6 +1820,30 @@ keyBinds:
18201820
description: |
18211821
以當前選中的節點作為根節點進行樹形結構格式化
18221822
不會查找整個樹的根節點,只格式化以選中節點為根的子樹
1823+
treeGraphAdjustSelectedAsRootToLeft:
1824+
title: 以選中節點為根,將子樹整體調整到左側
1825+
description: |
1826+
將選中節點視為子樹根節點。
1827+
把子樹內部所有連線,以及指向該根節點的父連線都改成左連線,
1828+
然後自動格式化樹形結構,讓整個子樹調整到左邊。
1829+
treeGraphAdjustSelectedAsRootToRight:
1830+
title: 以選中節點為根,將子樹整體調整到右側
1831+
description: |
1832+
將選中節點視為子樹根節點。
1833+
把子樹內部所有連線,以及指向該根節點的父連線都改成右連線,
1834+
然後自動格式化樹形結構,讓整個子樹調整到右邊。
1835+
treeGraphAdjustSelectedAsRootToUp:
1836+
title: 以選中節點為根,將子樹整體調整到上側
1837+
description: |
1838+
將選中節點視為子樹根節點。
1839+
把子樹內部所有連線,以及指向該根節點的父連線都改成上連線,
1840+
然後自動格式化樹形結構,讓整個子樹調整到上方。
1841+
treeGraphAdjustSelectedAsRootToDown:
1842+
title: 以選中節點為根,將子樹整體調整到下側
1843+
description: |
1844+
將選中節點視為子樹根節點。
1845+
把子樹內部所有連線,以及指向該根節點的父連線都改成下連線,
1846+
然後自動格式化樹形結構,讓整個子樹調整到下方。
18231847
treeGraphAdjust:
18241848
title: 調整目前節點所在樹狀結構的樹狀佈局
18251849
description: '主要用於關閉了鍵盤生長節點時觸發的樹狀佈局調整時使用

app/src/sub/SettingsWindow/keybinds.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,10 @@ export const shortcutKeysGroups: ShortcutKeysGroup[] = [
707707
"generateNodeGraphMoveRight",
708708
"treeGraphAdjust",
709709
"treeGraphAdjustSelectedAsRoot",
710+
"treeGraphAdjustSelectedAsRootToLeft",
711+
"treeGraphAdjustSelectedAsRootToRight",
712+
"treeGraphAdjustSelectedAsRootToUp",
713+
"treeGraphAdjustSelectedAsRootToDown",
710714
"setNodeTreeDirectionUp",
711715
"setNodeTreeDirectionDown",
712716
"setNodeTreeDirectionLeft",

0 commit comments

Comments
 (0)