Skip to content

Commit

Permalink
feat(marks): newly placed marks are now inactive instead of hidden
Browse files Browse the repository at this point in the history
  • Loading branch information
myypo committed Aug 23, 2024
1 parent 053207f commit f3a10a0
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 164 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ Default configuration:
debounce_milliseconds = {
run = 200, -- Change checking interval
maintenance = 500, -- Consistency enforcing interval
show = 3000, -- How long to wait before visualizing a freshly placed mark
-- How long to wait before activating a freshly placed mark
-- Inactive marks are not visualized and can't be jumped back to,
-- but still can be jump forward to and by using goto or follow commands
activate = 3000,
},
-- Files matching the following glob patterns will never be tracked
ignored_patterns = {
Expand Down
4 changes: 2 additions & 2 deletions compass/src/config/tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ pub struct Debounce {
#[serde(deserialize_with = "duration_from_millis")]
pub maintenance: Duration,
#[serde(deserialize_with = "duration_from_millis")]
pub show: Duration,
pub activate: Duration,
}

impl Default for Debounce {
fn default() -> Self {
Self {
run: Duration::from_millis(200),
maintenance: Duration::from_millis(500),
show: Duration::from_millis(3000),
activate: Duration::from_millis(3000),
}
}
}
Expand Down
32 changes: 19 additions & 13 deletions compass/src/state/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use bitcode::{Decode, Encode};
use nvim_oxi::api::{command, set_current_buf, Buffer, Window};
use serde::Deserialize;

use super::track_list::Mark;
use super::track_list::{Active, Mark};

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Record {
Expand All @@ -25,15 +25,15 @@ pub struct Record {
pub enum LazyExtmark {
Loaded(Extmark),
Unloaded((CursorPosition, RecordMarkTime)),
Hidden((CursorPosition, RecordMarkTime, Instant)),
Inactive((CursorPosition, RecordMarkTime, Instant)),
}

impl LazyExtmark {
pub fn pos(&self, buf: Buffer) -> CursorPosition {
match self {
Self::Loaded(e) => e.pos(buf),
Self::Unloaded((p, _)) => p.clone(),
Self::Hidden((p, _, _)) => p.clone(),
Self::Inactive((p, _, _)) => p.clone(),
}
}

Expand All @@ -48,7 +48,7 @@ impl LazyExtmark {
match self {
Self::Loaded(e) => e.delete(buf),
Self::Unloaded(_) => Ok(()),
Self::Hidden(_) => Ok(()),
Self::Inactive(_) => Ok(()),
}
}
}
Expand Down Expand Up @@ -103,11 +103,11 @@ impl Record {
})
}

pub fn try_new_hidden(buf: Buffer, typ: TypeRecord, pos: CursorPosition) -> Result<Self> {
pub fn try_new_inactive(buf: Buffer, typ: TypeRecord, pos: CursorPosition) -> Result<Self> {
Ok(Self {
buf,
typ,
lazy_extmark: LazyExtmark::Hidden((pos, RecordMarkTime::PastClose, Instant::now())),
lazy_extmark: LazyExtmark::Inactive((pos, RecordMarkTime::PastClose, Instant::now())),
frecency: Frecency::new(),
})
}
Expand All @@ -122,7 +122,7 @@ impl Record {

extmark
}
LazyExtmark::Hidden((p, t, _)) => {
LazyExtmark::Inactive((p, t, _)) => {
let extmark =
create_record_mark(self.buf.clone(), &Into::<CursorRange>::into(p), *t)?;
self.lazy_extmark = LazyExtmark::Loaded(extmark.clone());
Expand All @@ -148,7 +148,7 @@ impl Record {
create_record_mark(self.buf.clone(), &Into::<CursorRange>::into(&pos), time)?;
self.lazy_extmark = LazyExtmark::Loaded(extmark.clone());
}
LazyExtmark::Hidden(_) => {
LazyExtmark::Inactive(_) => {
let extmark =
create_record_mark(self.buf.clone(), &Into::<CursorRange>::into(&pos), time)?;
self.lazy_extmark = LazyExtmark::Loaded(extmark.clone());
Expand All @@ -161,7 +161,7 @@ impl Record {
Ok(())
}

pub fn hide_update(
pub fn deact_update(
&mut self,
buf: Buffer,
typ: TypeRecord,
Expand All @@ -172,7 +172,7 @@ impl Record {
e.delete(buf)?;
}

self.lazy_extmark = LazyExtmark::Hidden((pos, time, Instant::now()));
self.lazy_extmark = LazyExtmark::Inactive((pos, time, Instant::now()));
self.typ = typ;
self.frecency.add_record(FrecencyType::Update);

Expand Down Expand Up @@ -213,8 +213,8 @@ impl Record {
LazyExtmark::Unloaded((p, _)) => {
self.lazy_extmark = LazyExtmark::Unloaded((p.clone(), time));
}
LazyExtmark::Hidden((p, _, i)) => {
self.lazy_extmark = LazyExtmark::Hidden((p.clone(), time, *i));
LazyExtmark::Inactive((p, _, i)) => {
self.lazy_extmark = LazyExtmark::Inactive((p.clone(), time, *i));
}
}
}
Expand Down Expand Up @@ -251,7 +251,7 @@ impl Mark for Record {

Ok(())
}
LazyExtmark::Hidden((p, t, _)) => {
LazyExtmark::Inactive((p, t, _)) => {
let extmark =
create_record_mark(self.buf.clone(), &Into::<CursorRange>::into(p), *t)?;
self.lazy_extmark = LazyExtmark::Loaded(extmark.clone());
Expand All @@ -269,6 +269,12 @@ impl Mark for Record {
}
}

impl Active for Record {
fn is_active(&self) -> bool {
!matches!(self.lazy_extmark, LazyExtmark::Inactive(_))
}
}

mod tests {
use core::panic;

Expand Down
Loading

0 comments on commit f3a10a0

Please sign in to comment.