Skip to content

Commit

Permalink
Fix yank sharing across tabs (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
panarch authored Nov 19, 2024
1 parent 826a7b4 commit 0604e19
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
13 changes: 10 additions & 3 deletions tui/src/context/notebook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,19 @@ impl NotebookContext {
self.tab_index = Some(self.tabs.len() - 1);
}

let yank = self.yank.clone();
if let Some(yank) = yank {
self.apply_yank();
}

pub fn apply_yank(&mut self) {
if let Some(yank) = self.yank.clone() {
self.get_editor_mut().set_yank_text(yank);
}
}

pub fn update_yank(&mut self) {
self.yank = Some(self.get_editor().yank_text());
}

pub fn consume(&mut self, input: &Input) -> Action {
let code = match input {
Input::Key(key) => key.code,
Expand Down Expand Up @@ -334,7 +341,7 @@ impl NotebookContext {
.into(),
KeyCode::Char('n') if idle => {
self.show_browser = true;
self.yank = Some(self.get_editor_mut().yank_text());
self.update_yank();

TuiAction::SaveAndPassThrough.into()
}
Expand Down
14 changes: 14 additions & 0 deletions tui/src/transitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ impl App {

self.context.notebook.update_items(root);
self.context.notebook.select_item(&note_id);
self.context.notebook.apply_yank();
}
CloseTab(note_id) => {
self.context.notebook.close_tab(&note_id);
Expand All @@ -200,6 +201,7 @@ impl App {
let note_id = &state.get_selected_note().log_unwrap().id;
self.context.notebook.update_items(&state.root);
self.context.notebook.select_item(note_id);
self.context.notebook.apply_yank();
}
ToggleLineNumbers => {
self.context.notebook.show_line_number = !self.context.notebook.show_line_number;
Expand Down Expand Up @@ -319,6 +321,7 @@ impl App {
editor.move_cursor(cursor_move);
editor.cut();
self.context.notebook.mark_dirty();
self.context.notebook.update_yank();
}
Paste => {
let line_yanked = self.context.notebook.line_yanked;
Expand Down Expand Up @@ -354,6 +357,7 @@ impl App {
editor.cancel_selection();
editor.move_cursor(CursorMove::Jump(cursor.0 as u16, cursor.1 as u16));
self.context.notebook.line_yanked = true;
self.context.notebook.update_yank();
}
DeleteLines(n) => {
let editor = self.context.notebook.get_editor_mut();
Expand All @@ -378,6 +382,7 @@ impl App {
move_cursor_to_line_non_empty_start(editor);
self.context.notebook.line_yanked = true;
self.context.notebook.mark_dirty();
self.context.notebook.update_yank();
}
DeleteLinesAndInsert(n) => {
let editor = self.context.notebook.get_editor_mut();
Expand All @@ -389,6 +394,7 @@ impl App {
editor.cut();
self.context.notebook.line_yanked = true;
self.context.notebook.mark_dirty();
self.context.notebook.update_yank();
}
DeleteInsideWord(n) => {
let editor = self.context.notebook.get_editor_mut();
Expand All @@ -409,6 +415,7 @@ impl App {

self.context.notebook.line_yanked = false;
self.context.notebook.mark_dirty();
self.context.notebook.update_yank();
}
DeleteWordEnd(n) => {
let editor = self.context.notebook.get_editor_mut();
Expand All @@ -419,6 +426,7 @@ impl App {

self.context.notebook.line_yanked = false;
self.context.notebook.mark_dirty();
self.context.notebook.update_yank();
}
DeleteWordBack(n) => {
let editor = self.context.notebook.get_editor_mut();
Expand All @@ -428,6 +436,7 @@ impl App {

self.context.notebook.line_yanked = false;
self.context.notebook.mark_dirty();
self.context.notebook.update_yank();
}
DeleteLineStart => {
let editor = self.context.notebook.get_editor_mut();
Expand All @@ -437,6 +446,7 @@ impl App {

self.context.notebook.line_yanked = false;
self.context.notebook.mark_dirty();
self.context.notebook.update_yank();
}
DeleteLineEnd(n) => {
let editor = self.context.notebook.get_editor_mut();
Expand All @@ -448,6 +458,7 @@ impl App {

self.context.notebook.line_yanked = false;
self.context.notebook.mark_dirty();
self.context.notebook.update_yank();
}
};
}
Expand Down Expand Up @@ -547,20 +558,23 @@ impl App {
reselect_for_yank(editor);
editor.copy();
self.context.notebook.line_yanked = false;
self.context.notebook.update_yank();
}
DeleteSelection => {
let editor = self.context.notebook.get_editor_mut();
reselect_for_yank(editor);
editor.cut();
self.context.notebook.line_yanked = false;
self.context.notebook.mark_dirty();
self.context.notebook.update_yank();
}
DeleteSelectionAndInsertMode => {
let editor = self.context.notebook.get_editor_mut();
reselect_for_yank(editor);
editor.cut();
self.context.notebook.line_yanked = false;
self.context.notebook.mark_dirty();
self.context.notebook.update_yank();
}
}
}
Expand Down

0 comments on commit 0604e19

Please sign in to comment.