@@ -64,6 +64,58 @@ export async function sortBlocksCommand(contextBlockUUID: string | null = null)
6464 transformSelectedBlocksCommand ( blocks , sortBlocks , isSelectedState )
6565}
6666
67+ export async function reverseBlocksCommand ( contextBlockUUID : string | null = null ) {
68+ let blocks : BlockEntity [ ]
69+ let isSelectedState = true
70+ if ( contextBlockUUID )
71+ blocks = [ ( await logseq . Editor . getBlock ( contextBlockUUID ) ) ! ]
72+ else
73+ [ blocks , isSelectedState ] = await getChosenBlocks ( )
74+
75+ if ( blocks . length === 0 ) {
76+ await logseq . UI . showMsg (
77+ `[:div
78+ [:b "🪚 Reverse Blocks Command"]
79+ [:p "Select some blocks to use the command"]]` ,
80+ 'warning' ,
81+ { timeout : 10000 } ,
82+ )
83+ return
84+ }
85+
86+ const reverseBlocks = ( blocks ) => Array
87+ . from ( blocks as BlockEntity [ ] )
88+ . reverse ( )
89+
90+ transformSelectedBlocksCommand ( blocks , reverseBlocks , isSelectedState )
91+ }
92+
93+ export async function shuffleBlocksCommand ( contextBlockUUID : string | null = null ) {
94+ let blocks : BlockEntity [ ]
95+ let isSelectedState = true
96+ if ( contextBlockUUID )
97+ blocks = [ ( await logseq . Editor . getBlock ( contextBlockUUID ) ) ! ]
98+ else
99+ [ blocks , isSelectedState ] = await getChosenBlocks ( )
100+
101+ if ( blocks . length === 0 ) {
102+ await logseq . UI . showMsg (
103+ `[:div
104+ [:b "🪚 Shuffle Blocks Command"]
105+ [:p "Select some blocks to use the command"]]` ,
106+ 'warning' ,
107+ { timeout : 10000 } ,
108+ )
109+ return
110+ }
111+
112+ const shuffleBlocks = ( blocks ) => Array
113+ . from ( blocks as BlockEntity [ ] )
114+ . sort ( ( ) => Math . random ( ) - 0.5 )
115+
116+ transformSelectedBlocksCommand ( blocks , shuffleBlocks , isSelectedState )
117+ }
118+
67119
68120// paragraphs → lines → sentences
69121
0 commit comments