first working version of marks

pull/10905/head
Sam Vente 6 months ago
parent 719fb097fb
commit 70addbc870
No known key found for this signature in database

1
Cargo.lock generated

@ -1356,6 +1356,7 @@ dependencies = [
"helix-event", "helix-event",
"helix-loader", "helix-loader",
"helix-lsp", "helix-lsp",
"helix-parsec",
"helix-stdx", "helix-stdx",
"helix-tui", "helix-tui",
"helix-vcs", "helix-vcs",

@ -31,16 +31,32 @@ helix-lsp = { path = "../helix-lsp" }
helix-dap = { path = "../helix-dap" } helix-dap = { path = "../helix-dap" }
helix-vcs = { path = "../helix-vcs" } helix-vcs = { path = "../helix-vcs" }
helix-loader = { path = "../helix-loader" } helix-loader = { path = "../helix-loader" }
helix-parsec = { path = "../helix-parsec" }
anyhow = "1" anyhow = "1"
once_cell = "1.19" once_cell = "1.19"
tokio = { version = "1", features = ["rt", "rt-multi-thread", "io-util", "io-std", "time", "process", "macros", "fs", "parking_lot"] } tokio = { version = "1", features = [
tui = { path = "../helix-tui", package = "helix-tui", default-features = false, features = ["crossterm"] } "rt",
crossterm = { version = "0.28", features = ["event-stream"] } "rt-multi-thread",
"io-util",
"io-std",
"time",
"process",
"macros",
"fs",
"parking_lot",
] }
tui = { path = "../helix-tui", package = "helix-tui", default-features = false, features = [
"crossterm",
] }
crossterm = { version = "0.27", features = ["event-stream"] }
signal-hook = "0.3" signal-hook = "0.3"
tokio-stream = "0.1" tokio-stream = "0.1"
futures-util = { version = "0.3", features = ["std", "async-await"], default-features = false } futures-util = { version = "0.3", features = [
"std",
"async-await",
], default-features = false }
arc-swap = { version = "1.7.1" } arc-swap = { version = "1.7.1" }
termini = "1" termini = "1"
@ -53,14 +69,13 @@ log = "0.4"
nucleo.workspace = true nucleo.workspace = true
ignore = "0.4" ignore = "0.4"
# markdown doc rendering # markdown doc rendering
pulldown-cmark = { version = "0.12", default-features = false } pulldown-cmark = { version = "0.11", default-features = false }
# file type detection # file type detection
content_inspector = "0.2.4" content_inspector = "0.2.4"
thiserror = "1.0"
# opening URLs # opening URLs
open = "5.3.0" open = "5.1.3"
url = "2.5.2" url = "2.5.0"
# config # config
toml = "0.8" toml = "0.8"
@ -69,15 +84,15 @@ serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
# ripgrep for global search # ripgrep for global search
grep-regex = "0.1.13" grep-regex = "0.1.12"
grep-searcher = "0.1.14" grep-searcher = "0.1.13"
[target.'cfg(not(windows))'.dependencies] # https://github.com/vorner/signal-hook/issues/100 [target.'cfg(not(windows))'.dependencies] # https://github.com/vorner/signal-hook/issues/100
signal-hook-tokio = { version = "0.3", features = ["futures-v0_3"] } signal-hook-tokio = { version = "0.3", features = ["futures-v0_3"] }
libc = "0.2.158" libc = "0.2.155"
[target.'cfg(target_os = "macos")'.dependencies] [target.'cfg(target_os = "macos")'.dependencies]
crossterm = { version = "0.28", features = ["event-stream", "use-dev-tty", "libc"] } crossterm = { version = "0.27", features = ["event-stream", "use-dev-tty"] }
[build-dependencies] [build-dependencies]
helix-loader = { path = "../helix-loader" } helix-loader = { path = "../helix-loader" }
@ -85,5 +100,4 @@ helix-loader = { path = "../helix-loader" }
[dev-dependencies] [dev-dependencies]
smallvec = "1.13" smallvec = "1.13"
indoc = "2.0.5" indoc = "2.0.5"
tempfile = "3.12.0" tempfile = "3.10.1"
same-file = "1.0.1"

@ -5,6 +5,7 @@ pub(crate) mod typed;
pub use dap::*; pub use dap::*;
use futures_util::FutureExt; use futures_util::FutureExt;
use helix_event::status; use helix_event::status;
use helix_parsec::{seq, take_until, Parser};
use helix_stdx::{ use helix_stdx::{
path::expand_tilde, path::expand_tilde,
rope::{self, RopeSliceExt}, rope::{self, RopeSliceExt},
@ -44,9 +45,10 @@ use helix_view::{
info::Info, info::Info,
input::KeyEvent, input::KeyEvent,
keyboard::KeyCode, keyboard::KeyCode,
register::RegisterValues,
theme::Style, theme::Style,
tree, tree,
view::View, view::{self, View},
Document, DocumentId, Editor, ViewId, Document, DocumentId, Editor, ViewId,
}; };
@ -6124,30 +6126,63 @@ fn extend_to_word(cx: &mut Context) {
jump_to_word(cx, Movement::Extend) jump_to_word(cx, Movement::Extend)
} }
fn read_from_register(editor: &mut Editor, reg: char) -> Option<RegisterValues> {
editor.registers.read(reg, editor)
}
pub fn goto_mark(cx: &mut Context) { pub fn goto_mark(cx: &mut Context) {
let register_name = cx.register.unwrap_or('^').clone(); let register_name = cx.register.unwrap_or('^').clone();
let register_content = cx.editor.registers.read(register_name, cx.editor); let registers_vals = read_from_register(&mut cx.editor, register_name);
let res = match register_content { let blurb = registers_vals
Some(values) => values .unwrap()
.into_iter() .into_iter()
.next() .next()
.map(|c| c.into_owned()) .map(|c| c.into_owned());
.map(|s| { // let register_content = editor.registers.read(register_name, editor);
let mut split_iter = s.split(":").into_iter(); // let reg_str = match values {
let doc_id = split_iter.next().unwrap(); // Some(values) =>
let range_tupel = split_iter.next().unwrap(); // .ok_or(format!(
log::debug!("doc id: {:?}", &doc_id); // "Register {} did not contain anything",
log::debug!("range_tuple: {:?}", &range_tupel); // register_name
}) // )),
.ok_or(format!( // None => Err(format!(
"Register {} did not contain anything", // "Register {} did not contain anything",
register_name // register_name
)), // )),
None => Err(format!( // };
"Register {} did not contain anything", match blurb {
register_name Some(s) => {
)), let parser = seq!(
}; take_until(|c| c == ':'),
":(",
take_until(|c| c == ','),
",",
take_until(|c| c == ')'),
")"
);
let (_tail, (doc_id_str, _, anchor_str, _, head_str, _)) = parser.parse(&s).unwrap();
let anchor = anchor_str.parse().unwrap();
let head = head_str.parse().unwrap();
let doc_id: DocumentId = doc_id_str.try_into().unwrap();
let range = Range {
anchor,
head,
old_visual_position: None,
};
cx.editor.switch(doc_id, Action::Replace);
let (view, doc) = current!(cx.editor);
let (min_idx, max_idx) = if anchor < head {
(anchor, head)
} else {
(head, anchor)
};
let new_range = range.put_cursor(doc.text().slice(..), min_idx, false);
let new_range = new_range.put_cursor(doc.text().slice(..), max_idx, true);
doc.set_selection(view.id, new_range.into());
}
None => (),
// Err(e) => log::error!("{}", e),
}
// let picker = Picker::new(items, (), |cx, meta, action| { // let picker = Picker::new(items, (), |cx, meta, action| {
// cx.editor.switch(meta.id, action); // cx.editor.switch(meta.id, action);
// }) // })

@ -18,7 +18,7 @@ pub mod theme;
pub mod tree; pub mod tree;
pub mod view; pub mod view;
use std::num::NonZeroUsize; use std::num::{NonZeroUsize, ParseIntError};
// uses NonZeroUsize so Option<DocumentId> use a byte rather than two // uses NonZeroUsize so Option<DocumentId> use a byte rather than two
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
@ -31,6 +31,13 @@ impl Default for DocumentId {
} }
} }
impl TryFrom<&str> for DocumentId {
type Error = ParseIntError;
fn try_from(value: &str) -> Result<Self, Self::Error> {
Ok(Self(value.parse::<NonZeroUsize>()?))
}
}
impl std::fmt::Display for DocumentId { impl std::fmt::Display for DocumentId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_fmt(format_args!("{}", self.0)) f.write_fmt(format_args!("{}", self.0))

Loading…
Cancel
Save