Compare commits

...

3 Commits

Author SHA1 Message Date
Nikita Revenco
16ebe190c2
Merge 0141aece5f into 6cca98264f 2024-11-13 09:09:03 +00:00
Nikita Revenco
0141aece5f feat: add docs for register / 2024-11-08 22:48:51 +00:00
Nikita Revenco
27aea00f28 feat: add register / for parent path 2024-11-08 22:43:06 +00:00
2 changed files with 20 additions and 2 deletions

View File

@ -44,6 +44,7 @@ ### Special registers
| `#` | Selection indices (first selection is `1`, second is `2`, etc.) | This register is not writable | | `#` | Selection indices (first selection is `1`, second is `2`, etc.) | This register is not writable |
| `.` | Contents of the current selections | This register is not writable | | `.` | Contents of the current selections | This register is not writable |
| `%` | Name of the current file | This register is not writable | | `%` | Name of the current file | This register is not writable |
| `/` | Folder which contains the current file | This register is not writable |
| `+` | Reads from the system clipboard | Joins and yanks to the system clipboard | | `+` | Reads from the system clipboard | Joins and yanks to the system clipboard |
| `*` | Reads from the primary clipboard | Joins and yanks to the primary clipboard | | `*` | Reads from the primary clipboard | Joins and yanks to the primary clipboard |

View File

@ -63,6 +63,18 @@ pub fn read<'a>(&'a self, name: char, editor: &'a Editor) -> Option<RegisterValu
let path = doc!(editor).display_name(); let path = doc!(editor).display_name();
Some(RegisterValues::new(iter::once(path))) Some(RegisterValues::new(iter::once(path)))
} }
'/' => {
let relative_path = match doc!(editor).path() {
Some(path) => path,
None => return Some(RegisterValues::new(iter::empty())),
};
let parent = match relative_path.parent() {
Some(path) => path,
None => return Some(RegisterValues::new(iter::empty())),
};
let parent = parent.display().to_string();
Some(RegisterValues::new(iter::once(parent.into())))
}
'*' | '+' => Some(read_from_clipboard( '*' | '+' => Some(read_from_clipboard(
self.clipboard_provider.as_ref(), self.clipboard_provider.as_ref(),
self.inner.get(&name), self.inner.get(&name),
@ -82,7 +94,9 @@ pub fn read<'a>(&'a self, name: char, editor: &'a Editor) -> Option<RegisterValu
pub fn write(&mut self, name: char, mut values: Vec<String>) -> Result<()> { pub fn write(&mut self, name: char, mut values: Vec<String>) -> Result<()> {
match name { match name {
'_' => Ok(()), '_' => Ok(()),
'#' | '.' | '%' => Err(anyhow::anyhow!("Register {name} does not support writing")), '#' | '.' | '%' | '/' => {
Err(anyhow::anyhow!("Register {name} does not support writing"))
}
'*' | '+' => { '*' | '+' => {
self.clipboard_provider.set_contents( self.clipboard_provider.set_contents(
values.join(NATIVE_LINE_ENDING.as_str()), values.join(NATIVE_LINE_ENDING.as_str()),
@ -107,7 +121,9 @@ pub fn write(&mut self, name: char, mut values: Vec<String>) -> Result<()> {
pub fn push(&mut self, name: char, mut value: String) -> Result<()> { pub fn push(&mut self, name: char, mut value: String) -> Result<()> {
match name { match name {
'_' => Ok(()), '_' => Ok(()),
'#' | '.' | '%' => Err(anyhow::anyhow!("Register {name} does not support pushing")), '#' | '.' | '%' | '/' => {
Err(anyhow::anyhow!("Register {name} does not support pushing"))
}
'*' | '+' => { '*' | '+' => {
let clipboard_type = match name { let clipboard_type = match name {
'+' => ClipboardType::Clipboard, '+' => ClipboardType::Clipboard,
@ -164,6 +180,7 @@ pub fn iter_preview(&self) -> impl Iterator<Item = (char, &str)> {
('#', "<selection indices>"), ('#', "<selection indices>"),
('.', "<selection contents>"), ('.', "<selection contents>"),
('%', "<document path>"), ('%', "<document path>"),
('/', "<parent of document path>"),
('+', "<system clipboard>"), ('+', "<system clipboard>"),
('*', "<primary clipboard>"), ('*', "<primary clipboard>"),
] ]