Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-view/src/expansion.rs')
-rw-r--r--helix-view/src/expansion.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/helix-view/src/expansion.rs b/helix-view/src/expansion.rs
index 053152a4..99baf4bf 100644
--- a/helix-view/src/expansion.rs
+++ b/helix-view/src/expansion.rs
@@ -35,6 +35,8 @@ pub enum Variable {
LineEnding,
// The name of current buffers language as set in `languages.toml`
Language,
+ // Primary selection
+ Selection,
}
impl Variable {
@@ -44,6 +46,7 @@ impl Variable {
Self::BufferName,
Self::LineEnding,
Self::Language,
+ Self::Selection,
];
pub const fn as_str(&self) -> &'static str {
@@ -53,6 +56,7 @@ impl Variable {
Self::BufferName => "buffer_name",
Self::LineEnding => "line_ending",
Self::Language => "language",
+ Self::Selection => "selection",
}
}
@@ -63,6 +67,7 @@ impl Variable {
"buffer_name" => Some(Self::BufferName),
"line_ending" => Some(Self::LineEnding),
"language" => Some(Self::Language),
+ "selection" => Some(Self::Selection),
_ => None,
}
}
@@ -224,5 +229,8 @@ fn expand_variable(editor: &Editor, variable: Variable) -> Result<Cow<'static, s
Some(lang) => Cow::Owned(lang.to_owned()),
None => Cow::Borrowed("text"),
}),
+ Variable::Selection => Ok(Cow::Owned(
+ doc.selection(view.id).primary().fragment(text).to_string(),
+ )),
}
}