aboutsummaryrefslogtreecommitdiff
path: root/helix-view/src/register_selection.rs
diff options
context:
space:
mode:
authorBenoît CORTIER2021-06-05 02:21:31 +0000
committerBlaž Hrastnik2021-06-07 12:52:09 +0000
commit68affa3c598723a8b9451ef3dcceda83ae161e39 (patch)
tree06a6c0ed9f6e0483b138b44d969f4341206cf4c0 /helix-view/src/register_selection.rs
parentd5de9183ef8392168b06131278554e483eddfff3 (diff)
Implement register selection
User can select register to yank into with the " command. A new state is added to `Editor` and `commands::Context` structs. This state is managed by leveraging a new struct `RegisterSelection`.
Diffstat (limited to 'helix-view/src/register_selection.rs')
-rw-r--r--helix-view/src/register_selection.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/helix-view/src/register_selection.rs b/helix-view/src/register_selection.rs
new file mode 100644
index 00000000..d7f073b6
--- /dev/null
+++ b/helix-view/src/register_selection.rs
@@ -0,0 +1,47 @@
+/// Register selection and configuration
+///
+/// This is a kind a of specialized `Option<char>` for register selection.
+/// Point is to keep whether the register selection has been explicitely
+/// set or not while being convenient by knowing the default register name.
+pub struct RegisterSelection {
+ selected: char,
+ default_name: char,
+}
+
+impl RegisterSelection {
+ pub fn new(default_name: char) -> Self {
+ Self {
+ selected: default_name,
+ default_name,
+ }
+ }
+
+ pub fn select(&mut self, name: char) {
+ self.selected = name;
+ }
+
+ pub fn take(&mut self) -> Self {
+ Self {
+ selected: std::mem::replace(&mut self.selected, self.default_name),
+ default_name: self.default_name,
+ }
+ }
+
+ pub fn is_default(&self) -> bool {
+ self.selected == self.default_name
+ }
+
+ pub fn name(&self) -> char {
+ self.selected
+ }
+}
+
+impl Default for RegisterSelection {
+ fn default() -> Self {
+ let default_name = '"';
+ Self {
+ selected: default_name,
+ default_name,
+ }
+ }
+}