Cap selection history to 1024 entries
This commit is contained in:
parent
73c2f52158
commit
bbfb63ff89
1 changed files with 16 additions and 9 deletions
|
@ -10,7 +10,7 @@ mod test;
|
||||||
use aho_corasick::AhoCorasick;
|
use aho_corasick::AhoCorasick;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use clock::ReplicaId;
|
use clock::ReplicaId;
|
||||||
use collections::{BTreeMap, Bound, HashMap, HashSet};
|
use collections::{BTreeMap, Bound, HashMap, HashSet, VecDeque};
|
||||||
pub use display_map::DisplayPoint;
|
pub use display_map::DisplayPoint;
|
||||||
use display_map::*;
|
use display_map::*;
|
||||||
pub use element::*;
|
pub use element::*;
|
||||||
|
@ -62,6 +62,7 @@ use workspace::{settings, ItemNavHistory, Settings, Workspace};
|
||||||
const CURSOR_BLINK_INTERVAL: Duration = Duration::from_millis(500);
|
const CURSOR_BLINK_INTERVAL: Duration = Duration::from_millis(500);
|
||||||
const MAX_LINE_LEN: usize = 1024;
|
const MAX_LINE_LEN: usize = 1024;
|
||||||
const MIN_NAVIGATION_HISTORY_ROW_DELTA: i64 = 10;
|
const MIN_NAVIGATION_HISTORY_ROW_DELTA: i64 = 10;
|
||||||
|
const MAX_SELECTION_HISTORY_LEN: usize = 1024;
|
||||||
|
|
||||||
action!(Cancel);
|
action!(Cancel);
|
||||||
action!(Backspace);
|
action!(Backspace);
|
||||||
|
@ -537,8 +538,8 @@ struct SelectionHistory {
|
||||||
selections_by_transaction:
|
selections_by_transaction:
|
||||||
HashMap<TransactionId, (Arc<[Selection<Anchor>]>, Option<Arc<[Selection<Anchor>]>>)>,
|
HashMap<TransactionId, (Arc<[Selection<Anchor>]>, Option<Arc<[Selection<Anchor>]>>)>,
|
||||||
mode: SelectionHistoryMode,
|
mode: SelectionHistoryMode,
|
||||||
undo_stack: Vec<SelectionHistoryEntry>,
|
undo_stack: VecDeque<SelectionHistoryEntry>,
|
||||||
redo_stack: Vec<SelectionHistoryEntry>,
|
redo_stack: VecDeque<SelectionHistoryEntry>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SelectionHistory {
|
impl SelectionHistory {
|
||||||
|
@ -581,20 +582,26 @@ impl SelectionHistory {
|
||||||
fn push_undo(&mut self, entry: SelectionHistoryEntry) {
|
fn push_undo(&mut self, entry: SelectionHistoryEntry) {
|
||||||
if self
|
if self
|
||||||
.undo_stack
|
.undo_stack
|
||||||
.last()
|
.back()
|
||||||
.map_or(true, |e| e.selections != entry.selections)
|
.map_or(true, |e| e.selections != entry.selections)
|
||||||
{
|
{
|
||||||
self.undo_stack.push(entry)
|
self.undo_stack.push_back(entry);
|
||||||
|
if self.undo_stack.len() > MAX_SELECTION_HISTORY_LEN {
|
||||||
|
self.undo_stack.pop_front();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn push_redo(&mut self, entry: SelectionHistoryEntry) {
|
fn push_redo(&mut self, entry: SelectionHistoryEntry) {
|
||||||
if self
|
if self
|
||||||
.redo_stack
|
.redo_stack
|
||||||
.last()
|
.back()
|
||||||
.map_or(true, |e| e.selections != entry.selections)
|
.map_or(true, |e| e.selections != entry.selections)
|
||||||
{
|
{
|
||||||
self.redo_stack.push(entry)
|
self.redo_stack.push_back(entry);
|
||||||
|
if self.redo_stack.len() > MAX_SELECTION_HISTORY_LEN {
|
||||||
|
self.redo_stack.pop_front();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4388,7 +4395,7 @@ impl Editor {
|
||||||
pub fn undo_selection(&mut self, _: &UndoSelection, cx: &mut ViewContext<Self>) {
|
pub fn undo_selection(&mut self, _: &UndoSelection, cx: &mut ViewContext<Self>) {
|
||||||
self.end_selection(cx);
|
self.end_selection(cx);
|
||||||
self.selection_history.mode = SelectionHistoryMode::Undoing;
|
self.selection_history.mode = SelectionHistoryMode::Undoing;
|
||||||
if let Some(entry) = self.selection_history.undo_stack.pop() {
|
if let Some(entry) = self.selection_history.undo_stack.pop_back() {
|
||||||
self.set_selections(entry.selections.clone(), None, true, cx);
|
self.set_selections(entry.selections.clone(), None, true, cx);
|
||||||
self.select_next_state = entry.select_next_state.clone();
|
self.select_next_state = entry.select_next_state.clone();
|
||||||
self.add_selections_state = entry.add_selections_state.clone();
|
self.add_selections_state = entry.add_selections_state.clone();
|
||||||
|
@ -4400,7 +4407,7 @@ impl Editor {
|
||||||
pub fn redo_selection(&mut self, _: &RedoSelection, cx: &mut ViewContext<Self>) {
|
pub fn redo_selection(&mut self, _: &RedoSelection, cx: &mut ViewContext<Self>) {
|
||||||
self.end_selection(cx);
|
self.end_selection(cx);
|
||||||
self.selection_history.mode = SelectionHistoryMode::Redoing;
|
self.selection_history.mode = SelectionHistoryMode::Redoing;
|
||||||
if let Some(entry) = self.selection_history.redo_stack.pop() {
|
if let Some(entry) = self.selection_history.redo_stack.pop_back() {
|
||||||
self.set_selections(entry.selections.clone(), None, true, cx);
|
self.set_selections(entry.selections.clone(), None, true, cx);
|
||||||
self.select_next_state = entry.select_next_state.clone();
|
self.select_next_state = entry.select_next_state.clone();
|
||||||
self.add_selections_state = entry.add_selections_state.clone();
|
self.add_selections_state = entry.add_selections_state.clone();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue