diff options
Diffstat (limited to 'lib/editorBuffer.ml')
-rw-r--r-- | lib/editorBuffer.ml | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/editorBuffer.ml b/lib/editorBuffer.ml index 959c04a..8aacd71 100644 --- a/lib/editorBuffer.ml +++ b/lib/editorBuffer.ml | |||
@@ -10,15 +10,17 @@ type buffer = { | |||
10 | kind : kind; | 10 | kind : kind; |
11 | content : (char zipper zipper, error) Result.t; | 11 | content : (char zipper zipper, error) Result.t; |
12 | rendered : char Sequence.t zipper; | 12 | rendered : char Sequence.t zipper; |
13 | last_modified : float; | ||
13 | } | 14 | } |
14 | 15 | ||
15 | type t = buffer | 16 | type t = buffer |
16 | 17 | ||
17 | let empty = | 18 | let empty () = |
18 | { | 19 | { |
19 | kind = No_name; | 20 | kind = No_name; |
20 | content = empty |> push empty |> Result.return; | 21 | content = empty |> push empty |> Result.return; |
21 | rendered = push Sequence.empty empty; | 22 | rendered = push Sequence.empty empty; |
23 | last_modified = Unix.gettimeofday (); | ||
22 | } | 24 | } |
23 | 25 | ||
24 | let kind b = b.kind | 26 | let kind b = b.kind |
@@ -106,13 +108,14 @@ module Action = struct | |||
106 | match b.content with | 108 | match b.content with |
107 | | Error _ -> ((), b) | 109 | | Error _ -> ((), b) |
108 | | Ok c -> | 110 | | Ok c -> |
109 | let step = if before then left else right in | 111 | let rstep = if before then left else right ~by_one:false in |
112 | let cstep = if before then left else right ~by_one:false in | ||
110 | let rec aux i r c = | 113 | let rec aux i r c = |
111 | if i = 0 then r | 114 | if i = 0 then r |
112 | else | 115 | else |
113 | let default = Sequence.empty in | 116 | let default = Sequence.empty in |
114 | let l = apply_focus_or ~default (to_seq &> render) c in | 117 | let l = apply_focus_or ~default (to_seq &> render) c in |
115 | let c' = step c and r' = swap_focus l r |> step in | 118 | let c' = cstep c and r' = swap_focus l r |> rstep in |
116 | aux (i - 1) r' c' | 119 | aux (i - 1) r' c' |
117 | in | 120 | in |
118 | ((), { b with rendered = aux n b.rendered c |> goto (left_length c) }) | 121 | ((), { b with rendered = aux n b.rendered c |> goto (left_length c) }) |
@@ -444,9 +447,11 @@ let from_file f = | |||
444 | Sequence.(of_list lines |> map ~f:line_to_seq) | 447 | Sequence.(of_list lines |> map ~f:line_to_seq) |
445 | with Unix.Unix_error (ENOENT, _, _) -> Sequence.empty | 448 | with Unix.Unix_error (ENOENT, _, _) -> Sequence.empty |
446 | in | 449 | in |
447 | let rendered = Sequence.map ~f:render lines |> of_seq in | 450 | let kind = File f |
448 | let content = Sequence.map ~f:of_seq lines |> of_seq in | 451 | and content = Sequence.map ~f:of_seq lines |> of_seq |> Result.return |
449 | { kind = File f; content = Ok content; rendered } | 452 | and rendered = Sequence.map ~f:render lines |> of_seq |
453 | and last_modified = Unix.gettimeofday () in | ||
454 | { kind; content; rendered; last_modified } | ||
450 | 455 | ||
451 | let unrendered_view x y h w b = | 456 | let unrendered_view x y h w b = |
452 | match b.content with | 457 | match b.content with |