Skip to content

Commit

Permalink
fix #608
Browse files Browse the repository at this point in the history
  • Loading branch information
gibbz00 committed Feb 23, 2023
1 parent 6494fc1 commit 70a8889
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
13 changes: 11 additions & 2 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4310,7 +4310,12 @@ fn expand_selection(cx: &mut Context) {
// check if selection is different from the last one
if *current_selection != selection {
// save current selection so it can be restored using shrink_selection
view.object_selections.push(current_selection.clone());
if let Some(object_selections) = view.object_selections.get_mut(&doc.id()) {
object_selections.push(current_selection.clone());
} else {
view.object_selections
.insert(doc.id(), vec![current_selection.clone()]);
}

doc.set_selection(view.id, selection);
}
Expand All @@ -4325,7 +4330,11 @@ fn shrink_selection(cx: &mut Context) {
let (view, doc) = current!(editor);
let current_selection = doc.selection(view.id);
// try to restore previous selection
if let Some(prev_selection) = view.object_selections.pop() {
if let Some(prev_selection) = view
.object_selections
.get_mut(&doc.id())
.and_then(|e| e.pop())
{
if current_selection.contains(&prev_selection) {
// allow shrinking the selection only if current selection contains the previous object selection
doc.set_selection(view.id, prev_selection);
Expand Down
4 changes: 2 additions & 2 deletions helix-view/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pub struct View {
// two last modified docs which we need to manually keep track of
pub last_modified_docs: [Option<DocumentId>; 2],
/// used to store previous selections of tree-sitter objects
pub object_selections: Vec<Selection>,
pub object_selections: HashMap<DocumentId, Vec<Selection>>,
/// all gutter-related configuration settings, used primarily for gutter rendering
pub gutters: GutterConfig,
/// A mapping between documents and the last history revision the view was updated at.
Expand Down Expand Up @@ -151,7 +151,7 @@ impl View {
jumps: JumpList::new((doc, Selection::point(0))), // TODO: use actual sel
docs_access_history: Vec::new(),
last_modified_docs: [None, None],
object_selections: Vec::new(),
object_selections: HashMap::new(),
gutters,
doc_revisions: HashMap::new(),
}
Expand Down

0 comments on commit 70a8889

Please sign in to comment.