@@ -35,6 +35,7 @@ use crossterm::event::{KeyCode, KeyEvent};
35use once_cell::sync::Lazy;
35use once_cell::sync::Lazy;
37pub struct Context<'a> {
37pub struct Context<'a> {
38+ pub register: helix_view::RegisterSelection,
38 pub count: usize,
39 pub count: usize,
39 pub editor: &'a mut Editor,
40 pub editor: &'a mut Editor,
@@ -777,7 +778,7 @@ pub fn extend_line(cx: &mut Context) {
778// heuristic: append changes to history after each command, unless we're in insert mode
779// heuristic: append changes to history after each command, unless we're in insert mode
780−fn _delete_selection(doc: &mut Document, view_id: ViewId) {
781+fn _delete_selection(reg: char, doc: &mut Document, view_id: ViewId) {
781 // first yank the selection
782 // first yank the selection
782 let values: Vec<String> = doc
783 let values: Vec<String> = doc
783 .selection(view_id)
784 .selection(view_id)
@@ -785,8 +786,6 @@ fn _delete_selection(doc: &mut Document, view_id: ViewId) {
785 .map(Cow::into_owned)
786 .map(Cow::into_owned)
786 .collect();
787 .collect();
788− // TODO: allow specifying reg
790 register::set(reg, values);
789 register::set(reg, values);
792 // then delete
791 // then delete
@@ -800,8 +799,9 @@ fn _delete_selection(doc: &mut Document, view_id: ViewId) {
802pub fn delete_selection(cx: &mut Context) {
801pub fn delete_selection(cx: &mut Context) {
802+ let reg = cx.register.name();
803 let (view, doc) = cx.current();
803 let (view, doc) = cx.current();
804− _delete_selection(doc, view.id);
804+ _delete_selection(reg, doc, view.id);
806 doc.append_changes_to_history(view.id);
806 doc.append_changes_to_history(view.id);
@@ -810,8 +810,9 @@ pub fn delete_selection(cx: &mut Context) {
812pub fn change_selection(cx: &mut Context) {
812pub fn change_selection(cx: &mut Context) {
813+ let reg = cx.register.name();
813 let (view, doc) = cx.current();
814 let (view, doc) = cx.current();
814− _delete_selection(doc, view.id);
815+ _delete_selection(reg, doc, view.id);
815 enter_insert_mode(doc);
816 enter_insert_mode(doc);
@@ -1893,11 +1894,13 @@ pub fn yank(cx: &mut Context) {
1893 .map(Cow::into_owned)
1894 .map(Cow::into_owned)
1894 .collect();
1895 .collect();
1896− // TODO: allow specifying reg
1897+ let msg = format!(
1898− let msg = format!("yanked {} selection(s) to register {}", values.len(), reg);
1898+ "yanked {} selection(s) to register {}",
1900− register::set(reg, values);
1903+ register::set(cx.register.name(), values);
1902 cx.editor.set_status(msg)
1905 cx.editor.set_status(msg)
@@ -1908,9 +1911,7 @@ enum Paste {
1911−fn _paste(doc: &mut Document, view: &View, action: Paste) -> Option<Transaction> {
1914+fn _paste(reg: char, doc: &mut Document, view: &View, action: Paste) -> Option<Transaction> {
1912− // TODO: allow specifying reg
1914 if let Some(values) = register::get(reg) {
1915 if let Some(values) = register::get(reg) {
1915 let repeat = std::iter::repeat(
1916 let repeat = std::iter::repeat(
@@ -1956,18 +1957,20 @@ fn _paste(doc: &mut Document, view: &View, action: Paste) -> Option<Transaction>
1956// default insert
1957// default insert
1958pub fn paste_after(cx: &mut Context) {
1959pub fn paste_after(cx: &mut Context) {
1960+ let reg = cx.register.name();
1959 let (view, doc) = cx.current();
1961 let (view, doc) = cx.current();
1961− if let Some(transaction) = _paste(doc, view, Paste::After) {
1963+ if let Some(transaction) = _paste(reg, doc, view, Paste::After) {
1962 doc.apply(&transaction, view.id);
1964 doc.apply(&transaction, view.id);
1963 doc.append_changes_to_history(view.id);
1965 doc.append_changes_to_history(view.id);
1967pub fn paste_before(cx: &mut Context) {
1969pub fn paste_before(cx: &mut Context) {
1970+ let reg = cx.register.name();
1968 let (view, doc) = cx.current();
1971 let (view, doc) = cx.current();
1970− if let Some(transaction) = _paste(doc, view, Paste::Before) {
1973+ if let Some(transaction) = _paste(reg, doc, view, Paste::Before) {
1971 doc.apply(&transaction, view.id);
1974 doc.apply(&transaction, view.id);
1972 doc.append_changes_to_history(view.id);
1975 doc.append_changes_to_history(view.id);
@@ -2426,6 +2429,18 @@ pub fn wclose(cx: &mut Context) {
2426 cx.editor.close(view_id, /* close_buffer */ false);
2429 cx.editor.close(view_id, /* close_buffer */ false);
2432+pub fn select_register(cx: &mut Context) {
2433+ cx.on_next_key(move |cx, event| {
2435+ code: KeyCode::Char(ch),
2439+ cx.editor.register.select(ch);
2429pub fn space_mode(cx: &mut Context) {
2444pub fn space_mode(cx: &mut Context) {
2430 cx.on_next_key(move |cx, event| {
2445 cx.on_next_key(move |cx, event| {
2431 if let KeyEvent {
2446 if let KeyEvent {
@@ -2439,7 +2454,7 @@ pub fn space_mode(cx: &mut Context) {
2439 'b' => buffer_picker(cx),
2454 'b' => buffer_picker(cx),
2440 'w' => window_mode(cx),
2455 'w' => window_mode(cx),
2441 // ' ' => toggle_alternate_buffer(cx),
2456 // ' ' => toggle_alternate_buffer(cx),
2442− // TODO: temporary since space mode took it's old key
2457+ // TODO: temporary since space mode took its old key
2443 ' ' => keep_primary_selection(cx),
2458 ' ' => keep_primary_selection(cx),
2444 _ => (),
2459 _ => (),