Skip to content

Commit

Permalink
fix(place): remove change option to force place a new mark since it
Browse files Browse the repository at this point in the history
conflicts with merge
  • Loading branch information
myypo committed Aug 18, 2024
1 parent 2081111 commit fc30482
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 59 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ keys = {

-- Manually place a change mark that works the same way as automatically put ones
{ "<C-m>", "<Cmd>Compass place change<CR>" },
-- Same as above but always creates a new mark instead of trying to update a nearby one
{ "<C-S-m>", "<Cmd>Compass place change try_update=false<CR>" },
},

```
Expand Down
8 changes: 2 additions & 6 deletions compass/src/functions/place/completion.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
use crate::viml::CompassArgs;

pub fn get_place_completion(cargs: &CompassArgs) -> Vec<String> {
let Some(first) = cargs.sub_cmds.first() else {
let Some(_) = cargs.sub_cmds.first() else {
return Vec::from(&["change".to_owned()]);
};

match *first {
"change" => Vec::from(&["try_update=".to_owned()]),

_ => Vec::from(&["change".to_owned()]),
}
Vec::from(&["change".to_owned()])
}
56 changes: 24 additions & 32 deletions compass/src/functions/place/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,36 @@ pub fn get_place(sync_tracker: SyncTracker) -> impl Fn(Option<PlaceOptions>) ->
let mut tracker = sync_tracker.lock()?;

match opts {
PlaceOptions::Change(ChangeOptions { try_update }) => {
PlaceOptions::Change(ChangeOptions {}) => {
let buf_curr = get_current_buf();
let win_curr = get_current_win();

match try_update {
true => {
let pos_curr = get_current_win().get_cursor()?.into();
let pos_curr = get_current_win().get_cursor()?.into();

let Some((i, old_record)) =
tracker.list.iter_mut_from_future().enumerate().find(
|(
_,
Record {
buf, lazy_extmark, ..
},
)| {
buf_curr == *buf && {
lazy_extmark.pos(buf_curr.clone()).is_nearby(&pos_curr)
}
},
)
else {
return new_change_manual_record(buf_curr, win_curr, &mut tracker.list);
};
let Some((i, old_record)) = tracker.list.iter_mut_from_future().enumerate().find(
|(
_,
Record {
buf, lazy_extmark, ..
},
)| {
buf_curr == *buf && {
lazy_extmark.pos(buf_curr.clone()).is_nearby(&pos_curr)
}
},
) else {
return new_change_manual_record(buf_curr, win_curr, &mut tracker.list);
};

old_record.update(
buf_curr,
TypeRecord::Change(ChangeTypeRecord::Manual(old_record.typ.tick())),
pos_curr,
RecordMarkTime::PastClose,
)?;
tracker.list.make_close_past(i);
old_record.update(
buf_curr,
TypeRecord::Change(ChangeTypeRecord::Manual(old_record.typ.tick())),
pos_curr,
RecordMarkTime::PastClose,
)?;
tracker.list.make_close_past(i);

Ok(())
}

false => new_change_manual_record(buf_curr, win_curr, &mut tracker.list),
}
Ok(())
}
}
}
Expand Down
21 changes: 2 additions & 19 deletions compass/src/functions/place/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,7 @@ impl Default for PlaceOptions {
}

#[derive(Default, Deserialize)]
pub struct ChangeOptions {
#[serde(default = "default_try_update")]
pub try_update: bool,
}

fn default_try_update() -> bool {
true
}
pub struct ChangeOptions {}

impl<'a> TryFrom<CompassArgs<'a>> for PlaceOptions {
type Error = Error;
Expand All @@ -35,17 +28,7 @@ impl<'a> TryFrom<CompassArgs<'a>> for PlaceOptions {
};

match sub {
"change" => {
let try_update = value
.map_args
.get("try_update")
.map(|&s| s.parse::<bool>())
.transpose()
.map_err(InputError::Bool)?
.unwrap_or_else(default_try_update);

Ok(Self::Change(ChangeOptions { try_update }))
}
"change" => Ok(Self::Change(ChangeOptions {})),

sub => Err(InputError::FunctionArguments(format!(
"unknown `place` subcommand provided: {}",
Expand Down

0 comments on commit fc30482

Please sign in to comment.