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]]
|
[[package]]
|
||||||
name = "calcifer"
|
name = "calcifer"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"eframe",
|
"eframe",
|
||||||
"egui_code_editor",
|
"egui_code_editor",
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use eframe::egui;
|
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 std::{env, path::Path, path::PathBuf, cmp::max, io, fs, cmp::min};
|
||||||
use crate::tools;
|
use crate::tools;
|
||||||
use crate::tools::themes::CustomColorTheme;
|
use crate::tools::themes::CustomColorTheme;
|
||||||
|
@ -216,7 +217,7 @@ impl super::Calcifer {
|
||||||
let lines = current_tab.code.chars().filter(|&c| c == '\n').count() + 1;
|
let lines = current_tab.code.chars().filter(|&c| c == '\n').count() + 1;
|
||||||
|
|
||||||
egui::ScrollArea::vertical().show(ui, |ui| {
|
egui::ScrollArea::vertical().show(ui, |ui| {
|
||||||
CodeEditor::default()
|
let mut output = CodeEditor::default()
|
||||||
.id_source("code editor")
|
.id_source("code editor")
|
||||||
.with_rows(max(80, lines))
|
.with_rows(max(80, lines))
|
||||||
.with_fontsize(14.0)
|
.with_fontsize(14.0)
|
||||||
|
@ -224,6 +225,14 @@ impl super::Calcifer {
|
||||||
.with_syntax(tools::to_syntax(¤t_tab.language))
|
.with_syntax(tools::to_syntax(¤t_tab.language))
|
||||||
.with_numlines(true)
|
.with_numlines(true)
|
||||||
.show(ui, &mut current_tab.code);
|
.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 {
|
if current_tab.history.len() < 1 {
|
||||||
|
|
|
@ -104,6 +104,11 @@ impl eframe::App for Calcifer {
|
||||||
if self.searching {
|
if self.searching {
|
||||||
self.search.show(ctx, &mut self.searching, &mut self.tabs, &mut self.selected_tab);
|
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>) {
|
fn on_exit(&mut self, _gl : std::option::Option<&eframe::glow::Context>) {
|
||||||
|
|
|
@ -32,10 +32,15 @@ impl Default for Selection {
|
||||||
pub struct SearchWindow {
|
pub struct SearchWindow {
|
||||||
search_text: String,
|
search_text: String,
|
||||||
searched_text: String,
|
searched_text: String,
|
||||||
results: Vec<Selection>,
|
|
||||||
current_result: Selection,
|
|
||||||
across_documents: bool,
|
|
||||||
replace_text: String,
|
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 {
|
Self {
|
||||||
search_text: "".into(),
|
search_text: "".into(),
|
||||||
searched_text: "".into(),
|
searched_text: "".into(),
|
||||||
results: vec![],
|
|
||||||
current_result: Selection::default(),
|
|
||||||
across_documents: false,
|
|
||||||
replace_text: "".into(),
|
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 {
|
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) {
|
fn search(&mut self, tabs: &Vec<Tab>, selected_tab: &TabNumber) {
|
||||||
let mut search_results: Vec<Selection> = vec![];
|
let mut search_results: Vec<Selection> = vec![];
|
||||||
|
|
||||||
|
@ -130,9 +152,7 @@ impl SearchWindow {
|
||||||
self.searched_text = self.search_text.clone();
|
self.searched_text = self.search_text.clone();
|
||||||
self.results = search_results.clone();
|
self.results = search_results.clone();
|
||||||
|
|
||||||
if self.results.len() > 0 {
|
self.current_result = 0;
|
||||||
self.current_result = self.results[0].clone();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn match_text(&self, tab_text: String, tab_number: TabNumber) -> Vec<Selection> {
|
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) {
|
fn find_next(&mut self, tabs: &Vec<Tab>, selected_tab: &TabNumber) {
|
||||||
if self.searched_text != self.search_text && self.search_text.len() > 1 {
|
if self.searched_text != self.search_text && self.search_text.len() > 1 {
|
||||||
self.search(tabs, selected_tab);
|
self.search(tabs, selected_tab);
|
||||||
} else {
|
} else if self.results.len() > 1 {
|
||||||
println!("just need to get next result");
|
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 {
|
if self.searched_text != self.search_text && self.search_text.len() > 1 {
|
||||||
self.search(tabs, selected_tab);
|
self.search(tabs, selected_tab);
|
||||||
} else {
|
} 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) {
|
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