From 53d95316466dfb7a09825e0e120a75e9c11a572f Mon Sep 17 00:00:00 2001 From: Penwing Date: Tue, 23 Jan 2024 09:41:17 +0100 Subject: [PATCH] added replace --- calcifer_save.json | 2 +- src/calcifer.rs | 1 - src/calcifer/code_editor/mod.rs | 1 - src/tools/search.rs | 18 ++++++++++++++---- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/calcifer_save.json b/calcifer_save.json index 5b4d04e..d227408 100644 --- a/calcifer_save.json +++ b/calcifer_save.json @@ -1 +1 @@ -{"tabs":["/home/penwing/Documents/notes/victory2.txt","untitled"],"theme":6} \ No newline at end of file +{"tabs":["/home/penwing/Documents/notes/victory2.txt"],"theme":6} \ No newline at end of file diff --git a/src/calcifer.rs b/src/calcifer.rs index b405d5e..2035a6a 100644 --- a/src/calcifer.rs +++ b/src/calcifer.rs @@ -147,7 +147,6 @@ impl super::Calcifer { CCursor::new(self.search.get_cursor_end()), )); self.search.result_selected = true; - println!("Override cursor set : [{}, {}]", self.search.get_cursor_start(), self.search.get_cursor_end()); } CodeEditor::default().id_source("code editor") diff --git a/src/calcifer/code_editor/mod.rs b/src/calcifer/code_editor/mod.rs index b755c81..5de6cc1 100644 --- a/src/calcifer/code_editor/mod.rs +++ b/src/calcifer/code_editor/mod.rs @@ -210,7 +210,6 @@ impl CodeEditor { output.response.request_focus(); output.state.set_ccursor_range(override_cursor); output.state.store(ui.ctx(), output.response.id); - println!("Cursor range overriden"); } //text_edit_output = Some(output); diff --git a/src/tools/search.rs b/src/tools/search.rs index a7eb9f3..25c1bf4 100644 --- a/src/tools/search.rs +++ b/src/tools/search.rs @@ -182,8 +182,10 @@ impl SearchWindow { self.results = search_results.clone(); self.current_result = 0; - self.result_selected = false; - self.tab_selected = false; + if self.results.len() > 0 { + self.result_selected = false; + self.tab_selected = false; + } } fn match_text(&self, tab_text: String, tab_number: TabNumber) -> Vec { @@ -220,7 +222,15 @@ impl SearchWindow { } } - fn replace(&mut self, tabs: &Vec, selected_tab: &TabNumber) { - println!("Searched to replace {} with {}, tab lang : {} ", &self.search_text, &self.replace_text, tabs[selected_tab.to_index()].language); + fn replace(&mut self, tabs: &mut Vec, selected_tab: &TabNumber) { + if self.searched_text != self.search_text { + self.search(tabs, selected_tab); + } + + println!("trying to replace {} with {}", self.search_text, self.replace_text); + + for element in &self.results { + tabs[element.tab.to_index()].code = tabs[element.tab.to_index()].code.replace(&self.search_text, &self.replace_text); + } } } \ No newline at end of file