Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bookmarks #10905

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
1b6d617
setup harpoon bookmarks code skeleton
savente93 Jun 8, 2024
148f1c7
add code to dump selection location into register
savente93 Jun 8, 2024
bb7e922
add integration test for adding mark
savente93 Jun 8, 2024
b672490
make a start on jumping to bookmarks
savente93 Jun 8, 2024
719fb09
wip
savente93 Jun 8, 2024
70addbc
first working version of marks
savente93 Jun 9, 2024
cfbc46c
make marks take into account all selection ranges
savente93 Jun 9, 2024
89b63a2
make mark commands typeable
savente93 Jun 9, 2024
2da81b2
remove stray comment
savente93 Jun 9, 2024
d1e2bff
implement selection update mechanism
savente93 Jun 9, 2024
fb73cc5
remove unused imports, unused guttercode, and fix a few clippy warnings
savente93 Jun 9, 2024
dba4388
add some comments to register_mark
savente93 Jun 9, 2024
a9a7217
better error handling in parse_mark_register_contents
savente93 Jun 9, 2024
9cd6a26
make more use of anyhow
savente93 Jun 9, 2024
9f0fd62
remove stray file
savente93 Jun 9, 2024
f3d1577
apply some clippy lints
savente93 Jun 9, 2024
7395929
add an integration test
savente93 Jun 9, 2024
90748f7
also colapse current selection during test
savente93 Jun 9, 2024
c8153f4
use hypthens instead of underscores for typable commands
savente93 Jun 10, 2024
054e7f7
update test after rename
savente93 Jun 14, 2024
dadb1a4
Update helix-core/src/selection.rs
savente93 Aug 12, 2024
b82036b
fix merge conflict in cargo.toml
savente93 Sep 14, 2024
adb7658
ensure cursor in view after goto mark
savente93 Sep 16, 2024
157f9da
Merge remote-tracking branch 'upstream/master'
savente93 Dec 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions book/src/generated/typable-cmd.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
| `:write-buffer-close`, `:wbc` | Write changes to disk and closes the buffer. Accepts an optional path (:write-buffer-close some/path.txt) |
| `:write-buffer-close!`, `:wbc!` | Force write changes to disk creating necessary subdirectories and closes the buffer. Accepts an optional path (:write-buffer-close! some/path.txt) |
| `:new`, `:n` | Create a new scratch buffer. |
| `:goto-mark` | Go to the selection saved in a register. Register can be provided as argument or selected register else ^ will be used |
| `:register-mark` | Save current selection into a register. Register can be provided as argument or selected register else ^ will be used |
| `:format`, `:fmt` | Format the file using an external formatter or language server. |
| `:indent-style` | Set the indentation style for editing. ('t' for tabs or 1-16 for number of spaces.) |
| `:line-ending` | Set the document's default line ending. Options: crlf, lf. |
Expand Down
1 change: 1 addition & 0 deletions helix-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ integration = []
[dependencies]
helix-stdx = { path = "../helix-stdx" }
helix-loader = { path = "../helix-loader" }
helix-parsec = { path = "../helix-parsec" }

ropey = { version = "1.6.1", default-features = false, features = ["simd"] }
smallvec = "1.13"
Expand Down
79 changes: 78 additions & 1 deletion helix-core/src/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ use crate::{
movement::Direction,
Assoc, ChangeSet, RopeGraphemes, RopeSlice,
};
use helix_parsec::{seq, take_until, Parser};
use helix_stdx::rope::{self, RopeSliceExt};
use smallvec::{smallvec, SmallVec};
use std::{borrow::Cow, iter, slice};
use std::{borrow::Cow, fmt::Display, iter, slice};
use tree_sitter::Node;

/// A single selection range.
Expand Down Expand Up @@ -391,6 +392,34 @@ impl Range {
}
}

impl Display for Range {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "({},{})", self.anchor, self.head)
}
}

impl TryFrom<&str> for Range {
type Error = String;

fn try_from(value: &str) -> Result<Self, Self::Error> {
let parser = seq!(
"(",
take_until(|c| c == ','),
",",
take_until(|c| c == ')'),
")"
);
match parser.parse(value) {
Ok((_tail, (_, anchor, _, head, _))) => Ok(Self {
anchor: anchor.parse::<usize>().map_err(|e| e.to_string())?,
head: head.parse::<usize>().map_err(|e| e.to_string())?,
old_visual_position: None,
}),
Err(e) => Err(e.to_string()),
}
}
}

impl From<(usize, usize)> for Range {
fn from((anchor, head): (usize, usize)) -> Self {
Self {
Expand Down Expand Up @@ -888,6 +917,54 @@ mod test {
use super::*;
use crate::Rope;

#[test]
fn parse_range() -> Result<(), String> {
// sometimes we want Ok, sometimes we want Err, but we never want a panic
assert_eq!(
Range::try_from("(0,28)"),
Ok(Range {
anchor: 0,
head: 28,
old_visual_position: None
})
);
assert_eq!(
Range::try_from("(3456789,123456789)"),
Ok(Range {
anchor: 3456789,
head: 123456789,
old_visual_position: None
})
);
assert_eq!(Range::try_from("(,)"), Err("(,)".to_string()));
assert_eq!(
Range::try_from("(asdf,asdf)"),
Err("invalid digit found in string".to_string())
);
assert_eq!(Range::try_from("()"), Err("()".to_string()));
assert_eq!(
Range::try_from("(-4,ALSK)"),
Err("invalid digit found in string".to_string())
);
assert_eq!(
Range::try_from("(⦡⓼␀⍆ⴉ├⺶⍄⾨,⦡⓼␀⍆ⴉ├⺶⍄⾨)"),
Err("invalid digit found in string".to_string())
);
Ok(())
}

#[test]
fn display_range() {
assert_eq!(
Range {
anchor: 72,
head: 28,
old_visual_position: None,
}
.to_string(),
"(72,28)".to_string(),
);
}
#[test]
#[should_panic]
fn test_new_empty() {
Expand Down
30 changes: 25 additions & 5 deletions helix-term/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,32 @@ helix-lsp = { path = "../helix-lsp" }
helix-dap = { path = "../helix-dap" }
helix-vcs = { path = "../helix-vcs" }
helix-loader = { path = "../helix-loader" }
helix-parsec = { path = "../helix-parsec" }

anyhow = "1"
once_cell = "1.20"

tokio = { version = "1", features = ["rt", "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"] }
tokio = { version = "1", features = [
"rt",
"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.28", features = ["event-stream"] }
signal-hook = "0.3"
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" }
termini = "1"

Expand Down Expand Up @@ -72,12 +88,16 @@ serde = { version = "1.0", features = ["derive"] }
grep-regex = "0.1.13"
grep-searcher = "0.1.14"

[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"] }
libc = "0.2.167"

[target.'cfg(target_os = "macos")'.dependencies]
crossterm = { version = "0.28", features = ["event-stream", "use-dev-tty", "libc"] }
crossterm = { version = "0.28", features = [
"event-stream",
"use-dev-tty",
"libc",
] }

[build-dependencies]
helix-loader = { path = "../helix-loader" }
Expand Down
7 changes: 7 additions & 0 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub(crate) mod typed;
pub use dap::*;
use futures_util::FutureExt;
use helix_event::status;
use helix_parsec::{seq, take_until, Parser};
use helix_stdx::{
path::{self, find_paths},
rope::{self, RopeSliceExt},
Expand Down Expand Up @@ -44,6 +45,7 @@ use helix_view::{
info::Info,
input::KeyEvent,
keyboard::KeyCode,
register::RegisterValues,
theme::Style,
tree,
view::View,
Expand Down Expand Up @@ -71,6 +73,7 @@ use std::{
future::Future,
io::Read,
num::NonZeroUsize,
str::FromStr,
};

use std::{
Expand Down Expand Up @@ -6238,6 +6241,10 @@ fn extend_to_word(cx: &mut Context) {
jump_to_word(cx, Movement::Extend)
}

fn read_from_register(editor: &mut Editor, reg: char) -> Option<RegisterValues> {
editor.registers.read(reg, &*editor)
}

fn jump_to_label(cx: &mut Context, labels: Vec<Range>, behaviour: Movement) {
let doc = doc!(cx.editor);
let alphabet = &cx.editor.config().jump_label_alphabet;
Expand Down
Loading
Loading