mirror of https://github.com/helix-editor/helix
feat(commands): add `selection` variable expansion
parent
ac3c6ebaff
commit
ed2903b929
|
@ -48,6 +48,7 @@ The following variables are supported:
|
||||||
| `buffer_name` | The relative path of the currently focused document. `[scratch]` is expanded instead for scratch buffers. |
|
| `buffer_name` | The relative path of the currently focused document. `[scratch]` is expanded instead for scratch buffers. |
|
||||||
| `line_ending` | A string containing the line ending of the currently focused document. For example on Unix systems this is usually a line-feed character (`\n`) but on Windows systems this may be a carriage-return plus a line-feed (`\r\n`). The line ending kind of the currently focused document can be inspected with the `:line-ending` command. |
|
| `line_ending` | A string containing the line ending of the currently focused document. For example on Unix systems this is usually a line-feed character (`\n`) but on Windows systems this may be a carriage-return plus a line-feed (`\r\n`). The line ending kind of the currently focused document can be inspected with the `:line-ending` command. |
|
||||||
| `language` | A string containing the language name of the currently focused document.|
|
| `language` | A string containing the language name of the currently focused document.|
|
||||||
|
| `selection` | A string containing the primary selection of the currently focused document. |
|
||||||
|
|
||||||
Aside from editor variables, the following expansions may be used:
|
Aside from editor variables, the following expansions may be used:
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,8 @@ pub enum Variable {
|
||||||
LineEnding,
|
LineEnding,
|
||||||
// The name of current buffers language as set in `languages.toml`
|
// The name of current buffers language as set in `languages.toml`
|
||||||
Language,
|
Language,
|
||||||
|
// Primary selection
|
||||||
|
Selection,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Variable {
|
impl Variable {
|
||||||
|
@ -44,6 +46,7 @@ impl Variable {
|
||||||
Self::BufferName,
|
Self::BufferName,
|
||||||
Self::LineEnding,
|
Self::LineEnding,
|
||||||
Self::Language,
|
Self::Language,
|
||||||
|
Self::Selection,
|
||||||
];
|
];
|
||||||
|
|
||||||
pub const fn as_str(&self) -> &'static str {
|
pub const fn as_str(&self) -> &'static str {
|
||||||
|
@ -53,6 +56,7 @@ impl Variable {
|
||||||
Self::BufferName => "buffer_name",
|
Self::BufferName => "buffer_name",
|
||||||
Self::LineEnding => "line_ending",
|
Self::LineEnding => "line_ending",
|
||||||
Self::Language => "language",
|
Self::Language => "language",
|
||||||
|
Self::Selection => "selection",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,6 +67,7 @@ impl Variable {
|
||||||
"buffer_name" => Some(Self::BufferName),
|
"buffer_name" => Some(Self::BufferName),
|
||||||
"line_ending" => Some(Self::LineEnding),
|
"line_ending" => Some(Self::LineEnding),
|
||||||
"language" => Some(Self::Language),
|
"language" => Some(Self::Language),
|
||||||
|
"selection" => Some(Self::Selection),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -224,5 +229,8 @@ fn expand_variable(editor: &Editor, variable: Variable) -> Result<Cow<'static, s
|
||||||
Some(lang) => Cow::Owned(lang.to_owned()),
|
Some(lang) => Cow::Owned(lang.to_owned()),
|
||||||
None => Cow::Borrowed("text"),
|
None => Cow::Borrowed("text"),
|
||||||
}),
|
}),
|
||||||
|
Variable::Selection => Ok(Cow::Owned(
|
||||||
|
doc.selection(view.id).primary().fragment(text).to_string(),
|
||||||
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue