full search structure
This commit is contained in:
parent
af1f57df36
commit
c87ad99dcc
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -570,7 +570,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "calcifer"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
dependencies = [
|
||||
"eframe",
|
||||
"egui_code_editor",
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use eframe::egui;
|
||||
use eframe::egui::{text::CCursor, text_edit::CCursorRange};
|
||||
use std::{env, path::Path, path::PathBuf, cmp::max, io, fs, cmp::min};
|
||||
use crate::tools;
|
||||
use crate::tools::themes::CustomColorTheme;
|
||||
|
@ -216,7 +217,7 @@ impl super::Calcifer {
|
|||
let lines = current_tab.code.chars().filter(|&c| c == '\n').count() + 1;
|
||||
|
||||
egui::ScrollArea::vertical().show(ui, |ui| {
|
||||
CodeEditor::default()
|
||||
let mut output = CodeEditor::default()
|
||||
.id_source("code editor")
|
||||
.with_rows(max(80, lines))
|
||||
.with_fontsize(14.0)
|
||||
|
@ -224,6 +225,14 @@ impl super::Calcifer {
|
|||
.with_syntax(tools::to_syntax(¤t_tab.language))
|
||||
.with_numlines(true)
|
||||
.show(ui, &mut current_tab.code);
|
||||
if !self.search.result_selected {
|
||||
output.state.set_ccursor_range(Some(CCursorRange::two(
|
||||
CCursor::new(self.search.get_cursor_start()),
|
||||
CCursor::new(self.search.get_cursor_end()),
|
||||
)));
|
||||
println!("Changed Cursor : from {} to {}", self.search.get_cursor_start(), self.search.get_cursor_end());
|
||||
self.search.result_selected = true;
|
||||
}
|
||||
});
|
||||
|
||||
if current_tab.history.len() < 1 {
|
||||
|
|
|
@ -104,6 +104,11 @@ impl eframe::App for Calcifer {
|
|||
if self.searching {
|
||||
self.search.show(ctx, &mut self.searching, &mut self.tabs, &mut self.selected_tab);
|
||||
}
|
||||
|
||||
if !self.search.tab_selected && self.search.get_tab() != self.selected_tab {
|
||||
self.selected_tab = self.search.get_tab();
|
||||
}
|
||||
self.search.tab_selected = true;
|
||||
}
|
||||
|
||||
fn on_exit(&mut self, _gl : std::option::Option<&eframe::glow::Context>) {
|
||||
|
|
|
@ -32,10 +32,15 @@ impl Default for Selection {
|
|||
pub struct SearchWindow {
|
||||
search_text: String,
|
||||
searched_text: String,
|
||||
results: Vec<Selection>,
|
||||
current_result: Selection,
|
||||
across_documents: bool,
|
||||
replace_text: String,
|
||||
|
||||
across_documents: bool,
|
||||
|
||||
results: Vec<Selection>,
|
||||
current_result: usize,
|
||||
|
||||
pub tab_selected: bool,
|
||||
pub result_selected: bool,
|
||||
}
|
||||
|
||||
|
||||
|
@ -44,10 +49,15 @@ impl Default for SearchWindow {
|
|||
Self {
|
||||
search_text: "".into(),
|
||||
searched_text: "".into(),
|
||||
results: vec![],
|
||||
current_result: Selection::default(),
|
||||
across_documents: false,
|
||||
replace_text: "".into(),
|
||||
|
||||
across_documents: false,
|
||||
|
||||
results: vec![],
|
||||
current_result: 0,
|
||||
|
||||
tab_selected: true,
|
||||
result_selected: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -115,6 +125,18 @@ impl View for SearchWindow {
|
|||
}
|
||||
|
||||
impl SearchWindow {
|
||||
pub fn get_tab(&self) -> TabNumber {
|
||||
self.results[self.current_result].tab.clone()
|
||||
}
|
||||
|
||||
pub fn get_cursor_start(&self) -> usize {
|
||||
self.results[self.current_result].start.clone()
|
||||
}
|
||||
|
||||
pub fn get_cursor_end(&self) -> usize {
|
||||
self.results[self.current_result].end.clone()
|
||||
}
|
||||
|
||||
fn search(&mut self, tabs: &Vec<Tab>, selected_tab: &TabNumber) {
|
||||
let mut search_results: Vec<Selection> = vec![];
|
||||
|
||||
|
@ -130,9 +152,7 @@ impl SearchWindow {
|
|||
self.searched_text = self.search_text.clone();
|
||||
self.results = search_results.clone();
|
||||
|
||||
if self.results.len() > 0 {
|
||||
self.current_result = self.results[0].clone();
|
||||
}
|
||||
self.current_result = 0;
|
||||
}
|
||||
|
||||
fn match_text(&self, tab_text: String, tab_number: TabNumber) -> Vec<Selection> {
|
||||
|
@ -148,8 +168,12 @@ impl SearchWindow {
|
|||
fn find_next(&mut self, tabs: &Vec<Tab>, selected_tab: &TabNumber) {
|
||||
if self.searched_text != self.search_text && self.search_text.len() > 1 {
|
||||
self.search(tabs, selected_tab);
|
||||
} else {
|
||||
println!("just need to get next result");
|
||||
} else if self.results.len() > 1 {
|
||||
self.current_result = (self.current_result.clone() + 1) % self.results.len();
|
||||
self.result_selected = false;
|
||||
if self.results[self.current_result].tab != *selected_tab {
|
||||
self.tab_selected = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -157,11 +181,15 @@ impl SearchWindow {
|
|||
if self.searched_text != self.search_text && self.search_text.len() > 1 {
|
||||
self.search(tabs, selected_tab);
|
||||
} else {
|
||||
println!("just need to get next result");
|
||||
self.current_result = (self.current_result.clone() - 1 + self.results.len()) % self.results.len();
|
||||
self.result_selected = false;
|
||||
if self.results[self.current_result].tab != *selected_tab {
|
||||
self.tab_selected = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn replace(&mut self, tabs: &Vec<Tab>, selected_tab: &TabNumber) {
|
||||
println!("Searched to replace {} with {}", &self.search_text, &self.replace_text);
|
||||
println!("Searched to replace {} with {}, tab lang : {} ", &self.search_text, &self.replace_text, tabs[TabNumber::to_index(selected_tab)].language);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue