File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -286,6 +286,14 @@ export const lang = {
286286 modals_rules_rule_cm_move_to_document : 'Move to document rules' ,
287287 modals_rules_rule_cm_move_to_global : 'Move to global rules' ,
288288
289+ // sort
290+ cmd_sort_child_cards_asc : 'Sort child cards: ascending order' ,
291+ cmd_sort_child_cards_desc : 'Sort child cards: descending order' ,
292+ cm_sort_child : 'Sort child cards' ,
293+ cm_sort_child_cards_asc : 'Ascending order' ,
294+ cm_sort_child_cards_desc : 'Descending order' ,
295+ modals_snapshots_sorted_child_cards : 'Sorted child cards of card ' ,
296+
289297 // settings
290298 controls_settings : 'Settings' ,
291299 controls_toggle_bar : 'Toggle controls bar' ,
Original file line number Diff line number Diff line change @@ -9,12 +9,15 @@ import {
99 Heading1 ,
1010 Merge ,
1111 Scissors ,
12+ SortAsc ,
13+ SortDesc ,
1214 Split ,
1315} from 'lucide-svelte' ;
1416import { UndoableAction } from 'src/stores/document/document-store-actions' ;
1517import { Snapshot } from 'src/stores/document/document-state-type' ;
1618import { customIcons } from 'src/helpers/load-custom-icons' ;
1719import { lang } from './lang' ;
20+ import { SortChildNodesAction } from 'src/stores/document/reducers/sort/sort-direct-child-nodes' ;
1821
1922type Key = UndoableAction [ 'type' ] ;
2023
@@ -90,4 +93,13 @@ export const snapshotActionLang: Partial<
9093 lang . modals_snapshots_split_card + snapshot . context . affectedSection ,
9194 icon : Split ,
9295 } ) ,
96+ 'document/sort-direct-child-nodes' : ( snapshot ) => {
97+ const action = snapshot . context . action as SortChildNodesAction ;
98+ return {
99+ label :
100+ lang . modals_snapshots_sorted_child_cards +
101+ snapshot . context . affectedSection ,
102+ icon : action . payload . order === 'descending' ? SortDesc : SortAsc ,
103+ } ;
104+ } ,
93105} ;
Original file line number Diff line number Diff line change @@ -14,6 +14,8 @@ import { extractBranch } from 'src/obsidian/commands/helpers/extract-branch/extr
1414import { exportColumn } from 'src/view/actions/context-menu/card-context-menu/helpers/export-column' ;
1515import { exportDocument } from 'src/obsidian/commands/helpers/export-document/export-document' ;
1616import { onPluginError } from 'src/lib/store/on-plugin-error' ;
17+ import invariant from 'tiny-invariant' ;
18+ import { sortChildNodes } from 'src/view/actions/context-menu/card-context-menu/helpers/sort-child-nodes' ;
1719
1820const createCommands = ( plugin : Lineage ) => {
1921 const commands : ( Omit < Command , 'id' | 'callback' > & {
@@ -80,6 +82,40 @@ const createCommands = (plugin: Lineage) => {
8082 } ,
8183 } ) ;
8284
85+ commands . push ( {
86+ name : lang . cmd_sort_child_cards_asc ,
87+ icon : 'sort-asc' ,
88+ checkCallback : ( checking ) => {
89+ const view = getActiveLineageView ( plugin ) ;
90+ if ( checking ) {
91+ return Boolean ( view ) ;
92+ }
93+ invariant ( view ) ;
94+ sortChildNodes (
95+ view ,
96+ view . viewStore . getValue ( ) . document . activeNode ,
97+ 'ascending' ,
98+ ) ;
99+ } ,
100+ } ) ;
101+
102+ commands . push ( {
103+ name : lang . cmd_sort_child_cards_desc ,
104+ icon : 'sort-desc' ,
105+ checkCallback : ( checking ) => {
106+ const view = getActiveLineageView ( plugin ) ;
107+ if ( checking ) {
108+ return Boolean ( view ) ;
109+ }
110+ invariant ( view ) ;
111+ sortChildNodes (
112+ view ,
113+ view . viewStore . getValue ( ) . document . activeNode ,
114+ 'descending' ,
115+ ) ;
116+ } ,
117+ } ) ;
118+
83119 commands . push ( {
84120 name : lang . cm_copy_link_to_block ,
85121 icon : 'links-coming-in' ,
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ import { loadPinnedNodes } from 'src/stores/document/reducers/pinned-nodes/load-
3535import { refreshGroupParentIds } from 'src/stores/document/reducers/meta/refresh-group-parent-ids' ;
3636import { loadDocumentFromJSON } from 'src/stores/document/reducers/load-document-from-file/load-document-from-json' ;
3737import { NO_UPDATE } from 'src/lib/store/store' ;
38+ import { sortDirectChildNodes } from 'src/stores/document/reducers/sort/sort-direct-child-nodes' ;
3839
3940const updateDocumentState = (
4041 state : DocumentState ,
@@ -91,6 +92,10 @@ const updateDocumentState = (
9192 state . document . content [ action . payload . activeNodeId ] ;
9293 newActiveNodeId = mergeNode ( state . document , action ) ;
9394 affectedNodeId = action . payload . activeNodeId ;
95+ } else if ( action . type === 'document/sort-direct-child-nodes' ) {
96+ sortDirectChildNodes ( state . document , action . payload ) ;
97+ newActiveNodeId = action . payload . id ;
98+ affectedNodeId = newActiveNodeId ;
9499 } else if ( action . type === 'DOCUMENT/LOAD_FILE' ) {
95100 if ( action . payload . __test_document__ ) {
96101 newActiveNodeId = loadDocumentFromJSON (
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import { UnpinNodeAction } from 'src/stores/document/reducers/pinned-nodes/unpin
1717import { RemoveStalePinnedNodesAction } from 'src/stores/document/reducers/pinned-nodes/remove-stale-pinned-nodes' ;
1818import { LoadPinnedNodesAction } from 'src/stores/document/reducers/pinned-nodes/load-pinned-nodes' ;
1919import { RefreshGroupParentIdsAction } from 'src/stores/document/reducers/meta/refresh-group-parent-ids' ;
20+ import { SortChildNodesAction } from 'src/stores/document/reducers/sort/sort-direct-child-nodes' ;
2021
2122export type VerticalDirection = 'up' | 'down' ;
2223export type Direction = VerticalDirection | 'right' ;
@@ -57,7 +58,8 @@ export type DocumentAction =
5758 } ;
5859 }
5960 | PinnedNodesActions
60- | MetaActions ;
61+ | MetaActions
62+ | SortChildNodesAction ;
6163
6264export type HistoryAction = UndoRedoAction | SelectSnapshotAction ;
6365export type UndoableAction =
@@ -72,7 +74,8 @@ export type UndoableAction =
7274 | PasteNodeAction
7375 | CutNodeAction
7476 | ExtractNodeAction
75- | SplitNodeAction ;
77+ | SplitNodeAction
78+ | SortChildNodesAction ;
7679
7780export type CopyNodeAction = {
7881 type : 'DOCUMENT/COPY_NODE' ;
You can’t perform that action at this time.
0 commit comments