add config option to exclude files form old_file_locs

pull/9143/head
Ingrid 7 months ago
parent 838a9b6c12
commit 95573b5267

12
Cargo.lock generated

@ -1524,9 +1524,11 @@ dependencies = [
"log", "log",
"once_cell", "once_cell",
"parking_lot", "parking_lot",
"regex",
"rustix", "rustix",
"serde", "serde",
"serde_json", "serde_json",
"serde_regex",
"slotmap", "slotmap",
"tempfile", "tempfile",
"thiserror", "thiserror",
@ -2148,6 +2150,16 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "serde_regex"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8136f1a4ea815d7eac4101cfd0b16dc0cb5e1fe1b8609dfd728058656b7badf"
dependencies = [
"regex",
"serde",
]
[[package]] [[package]]
name = "serde_repr" name = "serde_repr"
version = "0.1.19" version = "0.1.19"

@ -42,6 +42,7 @@ tree-sitter = { version = "0.22" }
nucleo = "0.5.0" nucleo = "0.5.0"
slotmap = "1.0.7" slotmap = "1.0.7"
thiserror = "1.0" thiserror = "1.0"
regex = "1"
[workspace.package] [workspace.package]
version = "24.7.0" version = "24.7.0"

@ -34,7 +34,7 @@ slotmap.workspace = true
tree-sitter.workspace = true tree-sitter.workspace = true
once_cell = "1.19" once_cell = "1.19"
arc-swap = "1" arc-swap = "1"
regex = "1" regex.workspace = true
bitflags = "2.6" bitflags = "2.6"
ahash = "0.8.11" ahash = "0.8.11"
hashbrown = { version = "0.14.5", features = ["raw"] } hashbrown = { version = "0.14.5", features = ["raw"] }

@ -46,9 +46,12 @@ chardetng = "0.1"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
serde_regex = "1.1.0"
toml = "0.8" toml = "0.8"
log = "~0.4" log = "~0.4"
regex.workspace = true
parking_lot = "0.12.3" parking_lot = "0.12.3"
thiserror.workspace = true thiserror.workspace = true

@ -8,6 +8,7 @@ use crate::{
info::Info, info::Info,
input::KeyEvent, input::KeyEvent,
persistence::{self, FileHistoryEntry}, persistence::{self, FileHistoryEntry},
regex::EqRegex,
register::Registers, register::Registers,
theme::{self, Theme}, theme::{self, Theme},
tree::{self, Tree}, tree::{self, Tree},
@ -58,6 +59,8 @@ use arc_swap::{
ArcSwap, ArcSwap,
}; };
use regex::Regex;
pub const DEFAULT_AUTO_SAVE_DELAY: u64 = 3000; pub const DEFAULT_AUTO_SAVE_DELAY: u64 = 3000;
fn deserialize_duration_millis<'de, D>(deserializer: D) -> Result<Duration, D::Error> fn deserialize_duration_millis<'de, D>(deserializer: D) -> Result<Duration, D::Error>
@ -351,6 +354,7 @@ pub struct Config {
pub persist_commands: bool, pub persist_commands: bool,
pub persist_search: bool, pub persist_search: bool,
pub persist_clipboard: bool, pub persist_clipboard: bool,
pub persistence_file_exclusions: Vec<EqRegex>,
} }
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Eq, PartialOrd, Ord)] #[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Eq, PartialOrd, Ord)]
@ -989,6 +993,11 @@ impl Default for Config {
persist_commands: false, persist_commands: false,
persist_search: false, persist_search: false,
persist_clipboard: false, persist_clipboard: false,
// TODO: any more defaults we should add here?
persistence_file_exclusions: [r".*/\.git/.*"]
.iter()
.map(|s| Regex::new(s).unwrap().into())
.collect(),
} }
} }
} }
@ -1743,7 +1752,13 @@ impl Editor {
self.switch(id, action); self.switch(id, action);
if new_doc { if new_doc
&& !self
.config()
.persistence_file_exclusions
.iter()
.any(|r| r.is_match(&path.to_string_lossy()))
{
if let Some((view_position, selection)) = if let Some((view_position, selection)) =
self.old_file_locs.get(&path).map(|x| x.to_owned()) self.old_file_locs.get(&path).map(|x| x.to_owned())
{ {
@ -1787,9 +1802,16 @@ impl Editor {
if self.config().persist_old_files { if self.config().persist_old_files {
for loc in file_locs { for loc in file_locs {
persistence::push_file_history(&loc); if !self
self.old_file_locs .config()
.insert(loc.path, (loc.view_position, loc.selection)); .persistence_file_exclusions
.iter()
.any(|r| r.is_match(&loc.path.to_string_lossy()))
{
persistence::push_file_history(&loc);
self.old_file_locs
.insert(loc.path, (loc.view_position, loc.selection));
}
} }
} }
@ -1852,9 +1874,16 @@ impl Editor {
if self.config().persist_old_files { if self.config().persist_old_files {
for loc in file_locs { for loc in file_locs {
persistence::push_file_history(&loc); if !self
self.old_file_locs .config()
.insert(loc.path, (loc.view_position, loc.selection)); .persistence_file_exclusions
.iter()
.any(|r| r.is_match(&loc.path.to_string_lossy()))
{
persistence::push_file_history(&loc);
self.old_file_locs
.insert(loc.path, (loc.view_position, loc.selection));
}
} }
} }

@ -14,6 +14,7 @@ pub mod info;
pub mod input; pub mod input;
pub mod keyboard; pub mod keyboard;
pub mod persistence; pub mod persistence;
pub mod regex;
pub mod register; pub mod register;
pub mod theme; pub mod theme;
pub mod tree; pub mod tree;

@ -0,0 +1,37 @@
use regex::Regex;
use serde::{Deserialize, Serialize};
use std::{
cmp::{Eq, PartialEq},
ops::Deref,
};
/// Wrapper type for regex::Regex that only exists so we can implement Eq on it, as that's needed
/// to put it in editor::Config
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(transparent)]
pub struct EqRegex {
#[serde(with = "serde_regex")]
inner: Regex,
}
impl From<Regex> for EqRegex {
fn from(value: Regex) -> Self {
EqRegex { inner: value }
}
}
impl Deref for EqRegex {
type Target = Regex;
fn deref(&self) -> &Self::Target {
&self.inner
}
}
impl PartialEq for EqRegex {
fn eq(&self, other: &Self) -> bool {
self.as_str() == other.as_str()
}
}
impl Eq for EqRegex {}
Loading…
Cancel
Save