1
1
/// Defines the Editor API for plug-ins to use
2
2
use crate :: cli:: VERSION ;
3
3
use crate :: editor:: { Editor , FileContainer , FileLayout } ;
4
+ use crate :: pty:: Pty ;
4
5
use crate :: ui:: Feedback ;
5
6
use crate :: { config, fatal_error, PLUGIN_BOOTSTRAP , PLUGIN_MANAGER , PLUGIN_NETWORKING , PLUGIN_RUN } ;
6
7
use kaolinite:: utils:: { get_absolute_path, get_cwd, get_file_ext, get_file_name} ;
@@ -594,6 +595,7 @@ impl LuaUserData for Editor {
594
595
editor. ptr = editor
595
596
. files
596
597
. open_up ( editor. ptr . clone ( ) , FileLayout :: Atom ( vec ! [ fc] , 0 ) ) ;
598
+ editor. cache_old_ptr ( & editor. ptr . clone ( ) ) ;
597
599
editor. update_cwd ( ) ;
598
600
Ok ( true )
599
601
} else {
@@ -605,6 +607,7 @@ impl LuaUserData for Editor {
605
607
editor. ptr = editor
606
608
. files
607
609
. open_down ( editor. ptr . clone ( ) , FileLayout :: Atom ( vec ! [ fc] , 0 ) ) ;
610
+ editor. cache_old_ptr ( & editor. ptr . clone ( ) ) ;
608
611
editor. update_cwd ( ) ;
609
612
Ok ( true )
610
613
} else {
@@ -616,6 +619,7 @@ impl LuaUserData for Editor {
616
619
editor. ptr = editor
617
620
. files
618
621
. open_left ( editor. ptr . clone ( ) , FileLayout :: Atom ( vec ! [ fc] , 0 ) ) ;
622
+ editor. cache_old_ptr ( & editor. ptr . clone ( ) ) ;
619
623
editor. update_cwd ( ) ;
620
624
Ok ( true )
621
625
} else {
@@ -627,6 +631,7 @@ impl LuaUserData for Editor {
627
631
editor. ptr = editor
628
632
. files
629
633
. open_right ( editor. ptr . clone ( ) , FileLayout :: Atom ( vec ! [ fc] , 0 ) ) ;
634
+ editor. cache_old_ptr ( & editor. ptr . clone ( ) ) ;
630
635
editor. update_cwd ( ) ;
631
636
Ok ( true )
632
637
} else {
@@ -657,11 +662,13 @@ impl LuaUserData for Editor {
657
662
) ;
658
663
methods. add_method_mut ( "focus_split_up" , |_, editor, ( ) | {
659
664
editor. ptr = FileLayout :: move_up ( editor. ptr . clone ( ) , & editor. render_cache . span ) ;
665
+ editor. cache_old_ptr ( & editor. ptr . clone ( ) ) ;
660
666
editor. update_cwd ( ) ;
661
667
Ok ( ( ) )
662
668
} ) ;
663
669
methods. add_method_mut ( "focus_split_down" , |_, editor, ( ) | {
664
670
editor. ptr = FileLayout :: move_down ( editor. ptr . clone ( ) , & editor. render_cache . span ) ;
671
+ editor. cache_old_ptr ( & editor. ptr . clone ( ) ) ;
665
672
editor. update_cwd ( ) ;
666
673
Ok ( ( ) )
667
674
} ) ;
@@ -672,16 +679,21 @@ impl LuaUserData for Editor {
672
679
Some ( FileLayout :: FileTree )
673
680
) ;
674
681
if in_file_tree {
675
- // We just entered into a file tree, cache where we were (minus the file tree itself)
682
+ // We are about to enter a file tree, cache where we were (minus the file tree itself)
676
683
editor. old_ptr = editor. ptr . clone ( ) ;
677
- editor. old_ptr . pop ( ) ;
684
+ } else {
685
+ editor. old_ptr = new_ptr. clone ( ) ;
686
+ }
687
+ if editor. file_tree_is_open ( ) && !editor. old_ptr . is_empty ( ) {
688
+ editor. old_ptr . remove ( 0 ) ;
678
689
}
679
690
editor. ptr = new_ptr;
680
691
editor. update_cwd ( ) ;
681
692
Ok ( ( ) )
682
693
} ) ;
683
694
methods. add_method_mut ( "focus_split_right" , |_, editor, ( ) | {
684
695
editor. ptr = FileLayout :: move_right ( editor. ptr . clone ( ) , & editor. render_cache . span ) ;
696
+ editor. cache_old_ptr ( & editor. ptr . clone ( ) ) ;
685
697
editor. update_cwd ( ) ;
686
698
Ok ( ( ) )
687
699
} ) ;
@@ -770,6 +782,71 @@ impl LuaUserData for Editor {
770
782
editor. toggle_file_tree ( ) ;
771
783
Ok ( ( ) )
772
784
} ) ;
785
+ // Terminal
786
+ methods. add_method_mut ( "open_terminal_up" , |_, editor, cmd : Option < String > | {
787
+ if let Ok ( term) = Pty :: new ( config ! ( editor. config, terminal) . shell ) {
788
+ if let Some ( cmd) = cmd {
789
+ term. lock ( )
790
+ . unwrap ( )
791
+ . silent_run_command ( & format ! ( "{cmd}\n " ) ) ?;
792
+ }
793
+ editor. ptr = editor
794
+ . files
795
+ . open_up ( editor. ptr . clone ( ) , FileLayout :: Terminal ( term) ) ;
796
+ editor. cache_old_ptr ( & editor. ptr . clone ( ) ) ;
797
+ Ok ( true )
798
+ } else {
799
+ Ok ( false )
800
+ }
801
+ } ) ;
802
+ methods. add_method_mut ( "open_terminal_down" , |_, editor, cmd : Option < String > | {
803
+ if let Ok ( term) = Pty :: new ( config ! ( editor. config, terminal) . shell ) {
804
+ if let Some ( cmd) = cmd {
805
+ term. lock ( )
806
+ . unwrap ( )
807
+ . silent_run_command ( & format ! ( "{cmd}\n " ) ) ?;
808
+ }
809
+ editor. ptr = editor
810
+ . files
811
+ . open_down ( editor. ptr . clone ( ) , FileLayout :: Terminal ( term) ) ;
812
+ editor. cache_old_ptr ( & editor. ptr . clone ( ) ) ;
813
+ Ok ( true )
814
+ } else {
815
+ Ok ( false )
816
+ }
817
+ } ) ;
818
+ methods. add_method_mut ( "open_terminal_left" , |_, editor, cmd : Option < String > | {
819
+ if let Ok ( term) = Pty :: new ( config ! ( editor. config, terminal) . shell ) {
820
+ if let Some ( cmd) = cmd {
821
+ term. lock ( )
822
+ . unwrap ( )
823
+ . silent_run_command ( & format ! ( "{cmd}\n " ) ) ?;
824
+ }
825
+ editor. ptr = editor
826
+ . files
827
+ . open_left ( editor. ptr . clone ( ) , FileLayout :: Terminal ( term) ) ;
828
+ editor. cache_old_ptr ( & editor. ptr . clone ( ) ) ;
829
+ Ok ( true )
830
+ } else {
831
+ Ok ( false )
832
+ }
833
+ } ) ;
834
+ methods. add_method_mut ( "open_terminal_right" , |_, editor, cmd : Option < String > | {
835
+ if let Ok ( term) = Pty :: new ( config ! ( editor. config, terminal) . shell ) {
836
+ if let Some ( cmd) = cmd {
837
+ term. lock ( )
838
+ . unwrap ( )
839
+ . silent_run_command ( & format ! ( "{cmd}\n " ) ) ?;
840
+ }
841
+ editor. ptr = editor
842
+ . files
843
+ . open_right ( editor. ptr . clone ( ) , FileLayout :: Terminal ( term) ) ;
844
+ editor. cache_old_ptr ( & editor. ptr . clone ( ) ) ;
845
+ Ok ( true )
846
+ } else {
847
+ Ok ( false )
848
+ }
849
+ } ) ;
773
850
// Miscellaneous
774
851
methods. add_method_mut ( "open_command_line" , |_, editor, ( ) | {
775
852
match editor. prompt ( "Command" ) {
0 commit comments