added replace

This commit is contained in:
Penwing 2024-01-23 09:41:17 +01:00
parent 82e3b64290
commit 53d9531646
4 changed files with 15 additions and 7 deletions

View file

@ -1 +1 @@
{"tabs":["/home/penwing/Documents/notes/victory2.txt","untitled"],"theme":6} {"tabs":["/home/penwing/Documents/notes/victory2.txt"],"theme":6}

View file

@ -147,7 +147,6 @@ impl super::Calcifer {
CCursor::new(self.search.get_cursor_end()), CCursor::new(self.search.get_cursor_end()),
)); ));
self.search.result_selected = true; 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") CodeEditor::default().id_source("code editor")

View file

@ -210,7 +210,6 @@ impl CodeEditor {
output.response.request_focus(); output.response.request_focus();
output.state.set_ccursor_range(override_cursor); output.state.set_ccursor_range(override_cursor);
output.state.store(ui.ctx(), output.response.id); output.state.store(ui.ctx(), output.response.id);
println!("Cursor range overriden");
} }
//text_edit_output = Some(output); //text_edit_output = Some(output);

View file

@ -182,9 +182,11 @@ impl SearchWindow {
self.results = search_results.clone(); self.results = search_results.clone();
self.current_result = 0; self.current_result = 0;
if self.results.len() > 0 {
self.result_selected = false; self.result_selected = false;
self.tab_selected = false; self.tab_selected = false;
} }
}
fn match_text(&self, tab_text: String, tab_number: TabNumber) -> Vec<Selection> { fn match_text(&self, tab_text: String, tab_number: TabNumber) -> Vec<Selection> {
let matches = tab_text.match_indices(&self.search_text.clone()).map(|(i, _)| Selection { let matches = tab_text.match_indices(&self.search_text.clone()).map(|(i, _)| Selection {
@ -220,7 +222,15 @@ impl SearchWindow {
} }
} }
fn replace(&mut self, tabs: &Vec<Tab>, selected_tab: &TabNumber) { fn replace(&mut self, tabs: &mut Vec<Tab>, selected_tab: &TabNumber) {
println!("Searched to replace {} with {}, tab lang : {} ", &self.search_text, &self.replace_text, tabs[selected_tab.to_index()].language); 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);
}
} }
} }