@@ -9,9 +9,9 @@ use crate::editor::Editor;
9
9
use crate :: window:: WindowId ;
10
10
11
11
#[ derive( Debug ) ]
12
- pub struct Context < ' ctx > {
12
+ pub struct Context {
13
13
pub editor : Arc < RwLock < Editor > > ,
14
- pub cursors : & ' ctx mut BTreeMap < WindowId , Cursor > ,
14
+ pub cursors : Arc < RwLock < BTreeMap < WindowId , Cursor > > > ,
15
15
}
16
16
17
17
pub enum MappableCommand {
@@ -68,15 +68,17 @@ fn move_left(ctx: &mut Context) {
68
68
let tab = editor. focused_tab ( ) ;
69
69
let window = tab. tree . focus ( ) ;
70
70
let window = tab. tree . window ( window) ;
71
- let cursor = ctx. cursors . get_mut ( & window. id ) . unwrap ( ) ;
71
+ let mut cursors = ctx. cursors . write ( ) ;
72
+ let cursor = cursors. get_mut ( & window. id ) . unwrap ( ) ;
72
73
cursor. move_left ( ) ;
73
74
}
74
75
75
76
let mut editor = ctx. editor . write ( ) ;
76
77
let tab = editor. focused_tab_mut ( ) ;
77
78
let window = tab. tree . focus ( ) ;
78
79
let window = tab. tree . window_mut ( window) ;
79
- let cursor = ctx. cursors . get_mut ( & window. id ) . unwrap ( ) ;
80
+ let mut cursors = ctx. cursors . write ( ) ;
81
+ let cursor = cursors. get_mut ( & window. id ) . unwrap ( ) ;
80
82
81
83
if cursor. x ( ) . checked_sub ( window. scroll ( ) . 0 ) . is_none ( ) {
82
84
window. scroll_left ( ) ;
@@ -90,15 +92,17 @@ fn move_down(ctx: &mut Context) {
90
92
let window = tab. tree . focus ( ) ;
91
93
let window = tab. tree . window ( window) ;
92
94
let document = editor. document ( & window. document ) ;
93
- let cursor = ctx. cursors . get_mut ( & window. id ) . unwrap ( ) ;
95
+ let mut cursors = ctx. cursors . write ( ) ;
96
+ let cursor = cursors. get_mut ( & window. id ) . unwrap ( ) ;
94
97
cursor. move_down ( document) ;
95
98
}
96
99
97
100
let mut editor = ctx. editor . write ( ) ;
98
101
let tab = editor. focused_tab_mut ( ) ;
99
102
let window = tab. tree . focus ( ) ;
100
103
let window = tab. tree . window_mut ( window) ;
101
- let cursor = ctx. cursors . get_mut ( & window. id ) . unwrap ( ) ;
104
+ let mut cursors = ctx. cursors . write ( ) ;
105
+ let cursor = cursors. get_mut ( & window. id ) . unwrap ( ) ;
102
106
103
107
if cursor. y ( ) - window. scroll ( ) . 1 >= window. area . height . into ( ) {
104
108
window. scroll_down ( ) ;
@@ -111,15 +115,17 @@ fn move_up(ctx: &mut Context) {
111
115
let tab = editor. focused_tab ( ) ;
112
116
let window = tab. tree . focus ( ) ;
113
117
let window = tab. tree . window ( window) ;
114
- let cursor = ctx. cursors . get_mut ( & window. id ) . unwrap ( ) ;
118
+ let mut cursors = ctx. cursors . write ( ) ;
119
+ let cursor = cursors. get_mut ( & window. id ) . unwrap ( ) ;
115
120
cursor. move_up ( ) ;
116
121
}
117
122
118
123
let mut editor = ctx. editor . write ( ) ;
119
124
let tab = editor. focused_tab_mut ( ) ;
120
125
let window = tab. tree . focus ( ) ;
121
126
let window = tab. tree . window_mut ( window) ;
122
- let cursor = ctx. cursors . get_mut ( & window. id ) . unwrap ( ) ;
127
+ let mut cursors = ctx. cursors . write ( ) ;
128
+ let cursor = cursors. get_mut ( & window. id ) . unwrap ( ) ;
123
129
124
130
if cursor. y ( ) . checked_sub ( window. scroll ( ) . 1 ) . is_none ( ) {
125
131
window. scroll_up ( ) ;
@@ -133,15 +139,17 @@ pub fn move_right(ctx: &mut Context) {
133
139
let window = tab. tree . focus ( ) ;
134
140
let window = tab. tree . window ( window) ;
135
141
let document = editor. document ( & window. document ) ;
136
- let cursor = ctx. cursors . get_mut ( & window. id ) . unwrap ( ) ;
142
+ let mut cursors = ctx. cursors . write ( ) ;
143
+ let cursor = cursors. get_mut ( & window. id ) . unwrap ( ) ;
137
144
cursor. move_right ( document) ;
138
145
}
139
146
140
147
let mut editor = ctx. editor . write ( ) ;
141
148
let tab = editor. focused_tab_mut ( ) ;
142
149
let window = tab. tree . focus ( ) ;
143
150
let window = tab. tree . window_mut ( window) ;
144
- let cursor = ctx. cursors . get_mut ( & window. id ) . unwrap ( ) ;
151
+ let mut cursors = ctx. cursors . write ( ) ;
152
+ let cursor = cursors. get_mut ( & window. id ) . unwrap ( ) ;
145
153
146
154
if cursor. x ( ) - window. scroll ( ) . 0 >= window. area . width . into ( ) {
147
155
window. scroll_right ( ) ;
0 commit comments