Commit 0a25d13 1 parent 6494fc1 commit 0a25d13 Copy full SHA for 0a25d13
File tree 2 files changed +13
-4
lines changed
2 files changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -4310,7 +4310,12 @@ fn expand_selection(cx: &mut Context) {
4310
4310
// check if selection is different from the last one
4311
4311
if * current_selection != selection {
4312
4312
// save current selection so it can be restored using shrink_selection
4313
- view. object_selections . push ( current_selection. clone ( ) ) ;
4313
+ if let Some ( object_selections) = view. object_selections . get_mut ( & doc. id ( ) ) {
4314
+ object_selections. push ( current_selection. clone ( ) ) ;
4315
+ } else {
4316
+ view. object_selections
4317
+ . insert ( doc. id ( ) , vec ! [ current_selection. clone( ) ] ) ;
4318
+ }
4314
4319
4315
4320
doc. set_selection ( view. id , selection) ;
4316
4321
}
@@ -4325,7 +4330,11 @@ fn shrink_selection(cx: &mut Context) {
4325
4330
let ( view, doc) = current ! ( editor) ;
4326
4331
let current_selection = doc. selection ( view. id ) ;
4327
4332
// try to restore previous selection
4328
- if let Some ( prev_selection) = view. object_selections . pop ( ) {
4333
+ if let Some ( prev_selection) = view
4334
+ . object_selections
4335
+ . get_mut ( & doc. id ( ) )
4336
+ . and_then ( |e| e. pop ( ) )
4337
+ {
4329
4338
if current_selection. contains ( & prev_selection) {
4330
4339
// allow shrinking the selection only if current selection contains the previous object selection
4331
4340
doc. set_selection ( view. id , prev_selection) ;
Original file line number Diff line number Diff line change @@ -117,7 +117,7 @@ pub struct View {
117
117
// two last modified docs which we need to manually keep track of
118
118
pub last_modified_docs : [ Option < DocumentId > ; 2 ] ,
119
119
/// used to store previous selections of tree-sitter objects
120
- pub object_selections : Vec < Selection > ,
120
+ pub object_selections : HashMap < DocumentId , Vec < Selection > > ,
121
121
/// all gutter-related configuration settings, used primarily for gutter rendering
122
122
pub gutters : GutterConfig ,
123
123
/// A mapping between documents and the last history revision the view was updated at.
@@ -151,7 +151,7 @@ impl View {
151
151
jumps : JumpList :: new ( ( doc, Selection :: point ( 0 ) ) ) , // TODO: use actual sel
152
152
docs_access_history : Vec :: new ( ) ,
153
153
last_modified_docs : [ None , None ] ,
154
- object_selections : Vec :: new ( ) ,
154
+ object_selections : HashMap :: new ( ) ,
155
155
gutters,
156
156
doc_revisions : HashMap :: new ( ) ,
157
157
}
You can’t perform that action at this time.
0 commit comments