pressing e lets you edit the file, but it doesn't save it yet
This commit is contained in:
66
main.ml
66
main.ml
@ -838,7 +838,9 @@ module Panel = struct
|
|||||||
@@ empty
|
@@ empty
|
||||||
|
|
||||||
type textedit =
|
type textedit =
|
||||||
{ze: unit Zed_edit.t; zc: Zed_cursor.t; keybind: Input.Bind.state}
|
{ mutable ze: unit Zed_edit.t
|
||||||
|
; mutable zc: Zed_cursor.t
|
||||||
|
; mutable keybind: Input.Bind.state }
|
||||||
|
|
||||||
let make_textedit ?(keybinds = textedit_bindings) () =
|
let make_textedit ?(keybinds = textedit_bindings) () =
|
||||||
let z = Zed_edit.create () in
|
let z = Zed_edit.create () in
|
||||||
@ -846,6 +848,11 @@ module Panel = struct
|
|||||||
; zc= Zed_edit.new_cursor z
|
; zc= Zed_edit.new_cursor z
|
||||||
; keybind= Input.Bind.init keybinds }
|
; keybind= Input.Bind.init keybinds }
|
||||||
|
|
||||||
|
let clear_textedit ?(keybinds = textedit_bindings) te =
|
||||||
|
te.ze <- Zed_edit.create () ;
|
||||||
|
te.zc <- Zed_edit.new_cursor te.ze ;
|
||||||
|
te.keybind <- Input.Bind.init keybinds
|
||||||
|
|
||||||
let str_of_textedit (te : textedit) =
|
let str_of_textedit (te : textedit) =
|
||||||
Zed_string.to_utf8 (Zed_rope.to_string (Zed_edit.text te.ze))
|
Zed_string.to_utf8 (Zed_rope.to_string (Zed_edit.text te.ze))
|
||||||
|
|
||||||
@ -1024,22 +1031,52 @@ module Store = struct
|
|||||||
|
|
||||||
let editor ?(branch = "current") storepath : Panel.t =
|
let editor ?(branch = "current") storepath : Panel.t =
|
||||||
let sv = make_storeview storepath branch in
|
let sv = make_storeview storepath branch in
|
||||||
let keybinds =
|
let globalbinds =
|
||||||
let open CamomileLibrary in
|
let open Input.Bind in
|
||||||
|
add [([], Char 'e')]
|
||||||
|
[Custom (fun () -> sv.editmode <- not sv.editmode)]
|
||||||
|
empty in
|
||||||
|
let navbinds =
|
||||||
let open Input.Bind in
|
let open Input.Bind in
|
||||||
add [([], Char 'n')] [Custom (navigate sv `Next)]
|
add [([], Char 'n')] [Custom (navigate sv `Next)]
|
||||||
@@ add [([], Char 'p')] [Custom (navigate sv `Prev)]
|
@@ add [([], Char 'p')] [Custom (navigate sv `Prev)]
|
||||||
@@ add [([], Char 'w')] [Custom (navigate sv `Prev)]
|
@@ add [([], Char 'w')] [Custom (navigate sv `Prev)]
|
||||||
@@ add [([], Char 's')] [Custom (navigate sv `Next)]
|
@@ add [([], Char 's')] [Custom (navigate sv `Next)]
|
||||||
@@ add [([], Char 'd')] [Custom (navigate sv `Sub)]
|
@@ add [([], Char 'd')] [Custom (navigate sv `Sub)]
|
||||||
@@ add [([], Char 'a')] [Custom (navigate sv `Sup)] empty in
|
@@ add [([], Char 'a')] [Custom (navigate sv `Sup)] globalbinds
|
||||||
let bindstate = Input.Bind.init keybinds in
|
in
|
||||||
|
let editbinds =
|
||||||
|
let open Input.Bind in
|
||||||
|
add [([], Char 'e')]
|
||||||
|
[Custom (fun () -> sv.editmode <- not sv.editmode)]
|
||||||
|
Panel.textedit_bindings in
|
||||||
|
let bindstate = Input.Bind.init navbinds in
|
||||||
|
let te = Panel.make_textedit () in
|
||||||
{ act=
|
{ act=
|
||||||
(fun panel events ->
|
(fun panel events ->
|
||||||
|
if sv.editmode then bindstate.bindings <- editbinds
|
||||||
|
else bindstate.bindings <- navbinds ;
|
||||||
List.iter
|
List.iter
|
||||||
Input.Bind.(function Custom f -> f () | _ -> ())
|
Input.Bind.(function Custom f -> f () | _ -> ())
|
||||||
(Event.actions_of_events bindstate events) ;
|
(Event.actions_of_events bindstate events) ;
|
||||||
(Panel.vbox panel.subpanels).act panel events )
|
if not sv.editmode then (
|
||||||
|
let contents =
|
||||||
|
Lwt_main.run
|
||||||
|
( Istore.get_tree sv.store sv.view
|
||||||
|
>>= fun t ->
|
||||||
|
Istore.Tree.kind t sv.selection
|
||||||
|
>>= function
|
||||||
|
| Some a -> (
|
||||||
|
match a with
|
||||||
|
| `Contents -> Istore.Tree.get t sv.selection
|
||||||
|
| `Node -> Lwt.return "Node..." )
|
||||||
|
| None -> Lwt.return "Invalid Selection..." ) in
|
||||||
|
Panel.clear_textedit te ;
|
||||||
|
let zctx = Zed_edit.context te.ze te.zc in
|
||||||
|
Zed_edit.insert zctx
|
||||||
|
(Zed_rope.of_string (Zed_string.of_utf8 contents)) ) ;
|
||||||
|
(Panel.vbox panel.subpanels).act panel
|
||||||
|
(if sv.editmode then events else []) )
|
||||||
; subpanels=
|
; subpanels=
|
||||||
[ Panel.hbox
|
[ Panel.hbox
|
||||||
[ Panel.prettyprint (fun pp ->
|
[ Panel.prettyprint (fun pp ->
|
||||||
@ -1050,15 +1087,15 @@ module Store = struct
|
|||||||
(fun _i (step, node) ->
|
(fun _i (step, node) ->
|
||||||
Format.pp_open_vbox pp 0 ;
|
Format.pp_open_vbox pp 0 ;
|
||||||
Format.pp_open_hbox pp () ;
|
Format.pp_open_hbox pp () ;
|
||||||
for _ = 0 to !indent do
|
for _ = 1 to !indent do
|
||||||
Format.pp_print_space pp ()
|
Format.pp_print_space pp ()
|
||||||
done ;
|
done ;
|
||||||
if sel = [step] then
|
if sel = [step] then
|
||||||
Format.pp_open_stag pp
|
Format.pp_open_stag pp
|
||||||
Display.(
|
Display.(
|
||||||
Panel.Color_bg
|
Panel.Cursor
|
||||||
(Wall.Color.v 0.99 0.99 0.125 0.3)) ;
|
(Wall.Color.v 0.99 0.99 0.125 0.3)) ;
|
||||||
Format.fprintf pp "%d-%s@." !indent step ;
|
Format.fprintf pp "%s@." step ;
|
||||||
if sel = [step] then
|
if sel = [step] then
|
||||||
Format.pp_close_stag pp () ;
|
Format.pp_close_stag pp () ;
|
||||||
Format.pp_close_box pp () ;
|
Format.pp_close_box pp () ;
|
||||||
@ -1074,8 +1111,8 @@ module Store = struct
|
|||||||
let root =
|
let root =
|
||||||
Lwt_main.run (Istore.get_tree sv.store sv.view)
|
Lwt_main.run (Istore.get_tree sv.store sv.view)
|
||||||
in
|
in
|
||||||
draw_levels root sv.selection )
|
draw_levels root sv.selection ); Panel.textedit te
|
||||||
; Panel.prettyprint (fun pp ->
|
(*; Panel.prettyprint (fun pp ->
|
||||||
let contents =
|
let contents =
|
||||||
Lwt_main.run
|
Lwt_main.run
|
||||||
( Istore.get_tree sv.store sv.view
|
( Istore.get_tree sv.store sv.view
|
||||||
@ -1087,9 +1124,10 @@ module Store = struct
|
|||||||
| `Contents -> Istore.Tree.get t sv.selection
|
| `Contents -> Istore.Tree.get t sv.selection
|
||||||
| `Node -> Lwt.return "Node..." )
|
| `Node -> Lwt.return "Node..." )
|
||||||
| None -> Lwt.return "Invalid Selection..." )
|
| None -> Lwt.return "Invalid Selection..." )
|
||||||
in
|
in Format.fprintf pp "%s @." contents ) *) ]
|
||||||
Format.fprintf pp "%s @." contents ) ]
|
; Panel.bindingstate bindstate
|
||||||
; Panel.bindingstate bindstate ]
|
; Panel.prettyprint (fun pp ->
|
||||||
|
Format.fprintf pp "sv.editmode = %b @." sv.editmode ) ]
|
||||||
; tag= "store-editor" }
|
; tag= "store-editor" }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user