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.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/helix-view/src/expansion.rs b/helix-view/src/expansion.rs index 99baf4bf..b81166ed 100644 --- a/helix-view/src/expansion.rs +++ b/helix-view/src/expansion.rs @@ -37,6 +37,10 @@ pub enum Variable { Language, // Primary selection Selection, + // The one-indexed line number of the start of the primary selection in the currently focused document. + SelectionLineStart, + // The one-indexed line number of the end of the primary selection in the currently focused document. + SelectionLineEnd, } impl Variable { @@ -47,6 +51,8 @@ impl Variable { Self::LineEnding, Self::Language, Self::Selection, + Self::SelectionLineStart, + Self::SelectionLineEnd, ]; pub const fn as_str(&self) -> &'static str { @@ -57,6 +63,8 @@ impl Variable { Self::LineEnding => "line_ending", Self::Language => "language", Self::Selection => "selection", + Self::SelectionLineStart => "selection_line_start", + Self::SelectionLineEnd => "selection_line_end", } } @@ -68,6 +76,8 @@ impl Variable { "line_ending" => Some(Self::LineEnding), "language" => Some(Self::Language), "selection" => Some(Self::Selection), + "selection_line_start" => Some(Self::SelectionLineStart), + "selection_line_end" => Some(Self::SelectionLineEnd), _ => None, } } @@ -232,5 +242,13 @@ fn expand_variable(editor: &Editor, variable: Variable) -> Result<Cow<'static, s Variable::Selection => Ok(Cow::Owned( doc.selection(view.id).primary().fragment(text).to_string(), )), + Variable::SelectionLineStart => { + let start_line = doc.selection(view.id).primary().line_range(text).0; + Ok(Cow::Owned((start_line + 1).to_string())) + } + Variable::SelectionLineEnd => { + let end_line = doc.selection(view.id).primary().line_range(text).1; + Ok(Cow::Owned((end_line + 1).to_string())) + } } } |