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",
"once_cell",
"parking_lot",
"regex",
"rustix",
"serde",
"serde_json",
"serde_regex",
"slotmap",
"tempfile",
"thiserror",
@ -2148,6 +2150,16 @@ dependencies = [
"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]]
name = "serde_repr"
version = "0.1.19"

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

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

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

@ -8,6 +8,7 @@ use crate::{
info::Info,
input::KeyEvent,
persistence::{self, FileHistoryEntry},
regex::EqRegex,
register::Registers,
theme::{self, Theme},
tree::{self, Tree},
@ -58,6 +59,8 @@ use arc_swap::{
ArcSwap,
};
use regex::Regex;
pub const DEFAULT_AUTO_SAVE_DELAY: u64 = 3000;
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_search: bool,
pub persist_clipboard: bool,
pub persistence_file_exclusions: Vec<EqRegex>,
}
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Eq, PartialOrd, Ord)]
@ -989,6 +993,11 @@ impl Default for Config {
persist_commands: false,
persist_search: 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);
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)) =
self.old_file_locs.get(&path).map(|x| x.to_owned())
{
@ -1787,9 +1802,16 @@ impl Editor {
if self.config().persist_old_files {
for loc in file_locs {
persistence::push_file_history(&loc);
self.old_file_locs
.insert(loc.path, (loc.view_position, loc.selection));
if !self
.config()
.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 {
for loc in file_locs {
persistence::push_file_history(&loc);
self.old_file_locs
.insert(loc.path, (loc.view_position, loc.selection));
if !self
.config()
.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 keyboard;
pub mod persistence;
pub mod regex;
pub mod register;
pub mod theme;
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