pull/12887/merge
Nik Revenco 2025-06-15 20:59:16 +02:00 committed by GitHub
commit cbc2f9f785
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 8 deletions

View File

@ -43,7 +43,8 @@ Some registers have special behavior when read from and written to.
| `_` | No values are returned | All values are discarded |
| `#` | 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 |
| `%` | Name of the current file | This register is not writable |
| `%` | Name of the current file, relative to Helix's current working directory | This register is not writable |
| `=` | Absolute path to the current file | This register is not writable |
| `+` | Reads from the system clipboard | Joins and yanks to the system clipboard |
| `*` | Reads from the primary clipboard | Joins and yanks to the primary clipboard |

View File

@ -18,7 +18,8 @@ use crate::{
/// * Black hole (`_`): all values read and written are discarded
/// * Selection indices (`#`): index number of each selection starting at 1
/// * Selection contents (`.`)
/// * Document path (`%`): filename of the current buffer
/// * Relative document path (`%`): filename of the current buffer, relative to Helix's current working directory
/// * Absolute document path (`=`): absolute path of the current buffer
/// * System clipboard (`*`)
/// * Primary clipboard (`+`)
pub struct Registers {
@ -57,8 +58,16 @@ impl Registers {
let text = doc.text().slice(..);
Some(RegisterValues::new(doc.selection(view.id).fragments(text)))
}
'%' => {
let path = doc!(editor).display_name();
'%' | '=' => {
let doc = doc!(editor);
let path = match name {
'%' => doc.display_name(),
'=' => doc.path().map_or_else(
|| crate::document::SCRATCH_BUFFER_NAME.into(),
|path| path.to_string_lossy(),
),
_ => unreachable!(),
};
Some(RegisterValues::new(iter::once(path)))
}
'*' | '+' => Some(read_from_clipboard(
@ -80,7 +89,9 @@ impl Registers {
pub fn write(&mut self, name: char, mut values: Vec<String>) -> Result<()> {
match name {
'_' => Ok(()),
'#' | '.' | '%' => Err(anyhow::anyhow!("Register {name} does not support writing")),
'#' | '.' | '%' | '=' => {
Err(anyhow::anyhow!("Register {name} does not support writing"))
}
'*' | '+' => {
self.clipboard_provider.load().set_contents(
&values.join(NATIVE_LINE_ENDING.as_str()),
@ -105,7 +116,9 @@ impl Registers {
pub fn push(&mut self, name: char, mut value: String) -> Result<()> {
match name {
'_' => Ok(()),
'#' | '.' | '%' => Err(anyhow::anyhow!("Register {name} does not support pushing")),
'#' | '.' | '%' | '=' => {
Err(anyhow::anyhow!("Register {name} does not support pushing"))
}
'*' | '+' => {
let clipboard_type = match name {
'+' => ClipboardType::Clipboard,
@ -166,7 +179,8 @@ impl Registers {
('_', "<empty>"),
('#', "<selection indices>"),
('.', "<selection contents>"),
('%', "<document path>"),
('%', "<relative document path>"),
('=', "<absolute document path>"),
('+', "<system clipboard>"),
('*', "<primary clipboard>"),
]
@ -193,7 +207,7 @@ impl Registers {
true
}
'_' | '#' | '.' | '%' => false,
'_' | '#' | '.' | '%' | '=' => false,
_ => self.inner.remove(&name).is_some(),
}
}