@@ -11,7 +11,7 @@ use crate::{
1111} ;
1212use ratatui:: {
1313 Frame ,
14- crossterm:: event:: KeyCode ,
14+ crossterm:: event:: { KeyCode , KeyModifiers } ,
1515 layout:: { Alignment , Constraint , Flex , Layout , Rect } ,
1616 text:: { Line , Span } ,
1717 widgets:: { Block , Borders , Paragraph } ,
@@ -245,10 +245,10 @@ fn global_keybindings(world: &mut World) {
245245 world. get_mut :: < EditorState > ( ) . selection = selection. up ( participant_count) ;
246246 } ) ;
247247
248- kb. bind (
248+ kb. bind_many (
249249 GLOBAL ,
250- 'H' ,
251- "Move participant left / Point arrow left " ,
250+ keys ! [ 'H' , KeyBinding :: new ( KeyCode :: Left , KeyModifiers :: SHIFT ) ] ,
251+ "Move participant left" ,
252252 |world| {
253253 let mode = world. get :: < EditorState > ( ) . mode . clone ( ) ;
254254 if mode != EditorMode :: Normal {
@@ -271,10 +271,10 @@ fn global_keybindings(world: &mut World) {
271271 } ,
272272 ) ;
273273
274- kb. bind (
274+ kb. bind_many (
275275 GLOBAL ,
276- 'L' ,
277- "Move participant right / Point arrow right " ,
276+ keys ! [ 'L' , KeyBinding :: new ( KeyCode :: Right , KeyModifiers :: SHIFT ) ] ,
277+ "Move participant right" ,
278278 |world| {
279279 let mode = world. get :: < EditorState > ( ) . mode . clone ( ) ;
280280 if mode != EditorMode :: Normal {
@@ -300,36 +300,46 @@ fn global_keybindings(world: &mut World) {
300300 } ,
301301 ) ;
302302
303- kb. bind ( GLOBAL , 'J' , "Move event down" , |world| {
304- let mode = world. get :: < EditorState > ( ) . mode . clone ( ) ;
305- if mode != EditorMode :: Normal {
306- return ;
307- }
303+ kb. bind_many (
304+ GLOBAL ,
305+ keys ! [ 'J' , KeyBinding :: new( KeyCode :: Down , KeyModifiers :: SHIFT ) ] ,
306+ "Move event down" ,
307+ |world| {
308+ let mode = world. get :: < EditorState > ( ) . mode . clone ( ) ;
309+ if mode != EditorMode :: Normal {
310+ return ;
311+ }
308312
309- let selection = world. get :: < EditorState > ( ) . selection ;
310- if let Selection :: Event ( idx) = selection {
311- let event_count = world. get :: < SequenceDiagram > ( ) . event_count ( ) ;
312- if idx + 1 < event_count {
313- world. get_mut :: < SequenceDiagram > ( ) . events . swap ( idx, idx + 1 ) ;
314- world. get_mut :: < EditorState > ( ) . selection = Selection :: Event ( idx + 1 ) ;
313+ let selection = world. get :: < EditorState > ( ) . selection ;
314+ if let Selection :: Event ( idx) = selection {
315+ let event_count = world. get :: < SequenceDiagram > ( ) . event_count ( ) ;
316+ if idx + 1 < event_count {
317+ world. get_mut :: < SequenceDiagram > ( ) . events . swap ( idx, idx + 1 ) ;
318+ world. get_mut :: < EditorState > ( ) . selection = Selection :: Event ( idx + 1 ) ;
319+ }
315320 }
316- }
317- } ) ;
321+ } ,
322+ ) ;
318323
319- kb. bind ( GLOBAL , 'K' , "Move event up" , |world| {
320- let mode = world. get :: < EditorState > ( ) . mode . clone ( ) ;
321- if mode != EditorMode :: Normal {
322- return ;
323- }
324+ kb. bind_many (
325+ GLOBAL ,
326+ keys ! [ 'K' , KeyBinding :: new( KeyCode :: Up , KeyModifiers :: SHIFT ) ] ,
327+ "Move event up" ,
328+ |world| {
329+ let mode = world. get :: < EditorState > ( ) . mode . clone ( ) ;
330+ if mode != EditorMode :: Normal {
331+ return ;
332+ }
324333
325- let selection = world. get :: < EditorState > ( ) . selection ;
326- if let Selection :: Event ( idx) = selection
327- && idx > 0
328- {
329- world. get_mut :: < SequenceDiagram > ( ) . events . swap ( idx, idx - 1 ) ;
330- world. get_mut :: < EditorState > ( ) . selection = Selection :: Event ( idx - 1 ) ;
331- }
332- } ) ;
334+ let selection = world. get :: < EditorState > ( ) . selection ;
335+ if let Selection :: Event ( idx) = selection
336+ && idx > 0
337+ {
338+ world. get_mut :: < SequenceDiagram > ( ) . events . swap ( idx, idx - 1 ) ;
339+ world. get_mut :: < EditorState > ( ) . selection = Selection :: Event ( idx - 1 ) ;
340+ }
341+ } ,
342+ ) ;
333343
334344 kb. bind ( GLOBAL , 'C' , "Clear diagram" , |world| {
335345 let mode = world. get :: < EditorState > ( ) . mode . clone ( ) ;
@@ -357,24 +367,6 @@ fn global_keybindings(world: &mut World) {
357367 }
358368 } ) ;
359369
360- kb. bind ( GLOBAL , '?' , "Help" , |world| {
361- let editor = world. get_mut :: < EditorState > ( ) ;
362- if editor. mode == EditorMode :: Help {
363- editor. mode = EditorMode :: Normal ;
364- } else if editor. mode == EditorMode :: Normal {
365- editor. mode = EditorMode :: Help ;
366- }
367- } ) ;
368-
369- kb. bind ( GLOBAL , KeyBinding :: key ( KeyCode :: Esc ) , "Cancel" , |world| {
370- let editor = world. get_mut :: < EditorState > ( ) ;
371- if editor. mode == EditorMode :: Normal {
372- editor. clear_selection ( ) ;
373- } else {
374- editor. reset ( ) ;
375- }
376- } ) ;
377-
378370 kb. bind ( GLOBAL , KeyBinding :: key ( KeyCode :: Enter ) , "Edit" , |world| {
379371 let mode = world. get :: < EditorState > ( ) . mode . clone ( ) ;
380372 if mode != EditorMode :: Normal {
@@ -486,6 +478,24 @@ fn global_keybindings(world: &mut World) {
486478 Selection :: None => { }
487479 }
488480 } ) ;
481+
482+ kb. bind ( GLOBAL , '?' , "Help" , |world| {
483+ let editor = world. get_mut :: < EditorState > ( ) ;
484+ if editor. mode == EditorMode :: Help {
485+ editor. mode = EditorMode :: Normal ;
486+ } else if editor. mode == EditorMode :: Normal {
487+ editor. mode = EditorMode :: Help ;
488+ }
489+ } ) ;
490+
491+ kb. bind ( GLOBAL , KeyBinding :: key ( KeyCode :: Esc ) , "Cancel" , |world| {
492+ let editor = world. get_mut :: < EditorState > ( ) ;
493+ if editor. mode == EditorMode :: Normal {
494+ editor. clear_selection ( ) ;
495+ } else {
496+ editor. reset ( ) ;
497+ }
498+ } ) ;
489499}
490500
491501fn input_mode_keybindings ( world : & mut World ) {
0 commit comments