Skip to content

Commit 70a8889

Browse files
committed
fix #608
1 parent 6494fc1 commit 70a8889

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

helix-term/src/commands.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -4310,7 +4310,12 @@ fn expand_selection(cx: &mut Context) {
43104310
// check if selection is different from the last one
43114311
if *current_selection != selection {
43124312
// 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+
}
43144319

43154320
doc.set_selection(view.id, selection);
43164321
}
@@ -4325,7 +4330,11 @@ fn shrink_selection(cx: &mut Context) {
43254330
let (view, doc) = current!(editor);
43264331
let current_selection = doc.selection(view.id);
43274332
// 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+
{
43294338
if current_selection.contains(&prev_selection) {
43304339
// allow shrinking the selection only if current selection contains the previous object selection
43314340
doc.set_selection(view.id, prev_selection);

helix-view/src/view.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ pub struct View {
117117
// two last modified docs which we need to manually keep track of
118118
pub last_modified_docs: [Option<DocumentId>; 2],
119119
/// used to store previous selections of tree-sitter objects
120-
pub object_selections: Vec<Selection>,
120+
pub object_selections: HashMap<DocumentId, Vec<Selection>>,
121121
/// all gutter-related configuration settings, used primarily for gutter rendering
122122
pub gutters: GutterConfig,
123123
/// A mapping between documents and the last history revision the view was updated at.
@@ -151,7 +151,7 @@ impl View {
151151
jumps: JumpList::new((doc, Selection::point(0))), // TODO: use actual sel
152152
docs_access_history: Vec::new(),
153153
last_modified_docs: [None, None],
154-
object_selections: Vec::new(),
154+
object_selections: HashMap::new(),
155155
gutters,
156156
doc_revisions: HashMap::new(),
157157
}

0 commit comments

Comments
 (0)