uncovered already implemented undo, cleaned up code

This commit is contained in:
Penwing 2024-01-23 15:00:13 +01:00
parent 4e03fb8c03
commit 467d2b698a
5 changed files with 7 additions and 29 deletions

View file

@ -17,3 +17,4 @@ Library subjugation (got the raw files of the egui_code_editor for some internal
# 1.0.2 : # 1.0.2 :
Added find and replace function Added find and replace function
Added multi line tab and shift+tab Added multi line tab and shift+tab
Added Ctrl+E : comment multiline

View file

@ -155,7 +155,7 @@ impl super::Calcifer {
.with_theme(self.theme) .with_theme(self.theme)
.with_syntax(tools::to_syntax(&current_tab.language)) .with_syntax(tools::to_syntax(&current_tab.language))
.with_numlines(true) .with_numlines(true)
.show(ui, &mut current_tab.code, &mut current_tab.history, &mut current_tab.last_cursor, &mut current_tab.scroll_offset, override_cursor); .show(ui, &mut current_tab.code, &mut current_tab.saved, &mut current_tab.last_cursor, &mut current_tab.scroll_offset, override_cursor);
} }
pub fn save_tab(&self) -> Option<PathBuf> { pub fn save_tab(&self) -> Option<PathBuf> {

View file

@ -237,7 +237,7 @@ impl CodeEditor {
} }
/// Show Code Editor /// Show Code Editor
pub fn show(&mut self, ui: &mut egui::Ui, text: &mut String, history: &mut Vec<String>, last_cursor: &mut Option<CCursorRange>, vertical_offset: &mut f32, override_cursor: Option<CCursorRange>) { pub fn show(&mut self, ui: &mut egui::Ui, text: &mut String, saved: &mut bool, last_cursor: &mut Option<CCursorRange>, vertical_offset: &mut f32, override_cursor: Option<CCursorRange>) {
//let mut text_edit_output: Option<TextEditOutput> = None; //let mut text_edit_output: Option<TextEditOutput> = None;
let mut code_editor = |ui: &mut egui::Ui| { let mut code_editor = |ui: &mut egui::Ui| {
ui.horizontal_top(|h| { ui.horizontal_top(|h| {
@ -269,6 +269,7 @@ impl CodeEditor {
if output.response.has_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter)) { if output.response.has_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter)) {
println!("line break"); println!("line break");
//get previous line number of tabs, and 2 charcters before cursor
} }
if output.response.has_focus() && ui.input(|i| i.key_pressed(egui::Key::E) && i.modifiers.ctrl) { if output.response.has_focus() && ui.input(|i| i.key_pressed(egui::Key::E) && i.modifiers.ctrl) {
@ -296,17 +297,6 @@ impl CodeEditor {
} }
} }
if output.response.has_focus() && ui.input( |i| i.key_pressed(egui::Key::Z) && i.modifiers.ctrl) {
println!("Ctrl+Z");
//let current_tab = &mut self.tabs[self.selected_tab.to_index()];
//if current_tab.history.len() > 1 {
//current_tab.code = current_tab.history[current_tab.history.len() - 2].clone();
//current_tab.history.pop();
//}
}
if override_cursor != None { if override_cursor != None {
output.response.request_focus(); output.response.request_focus();
output.state.set_ccursor_range(override_cursor); output.state.set_ccursor_range(override_cursor);
@ -332,20 +322,10 @@ impl CodeEditor {
} }
} }
if previous_text != text.clone() {
//text_edit_output = Some(output); *saved = false;
if history.len() < 1 {
history.push(text.clone());
} }
//text_edit_output = Some(output);
//if &current_tab.code != current_tab.history.last().expect("There should be an history") {
//current_tab.history.push(current_tab.code.clone());
//current_tab.saved = false;
//if current_tab.history.len() > super::HISTORY_LENGTH {
//current_tab.history.remove(0);
//}
//}
}); });
}); });
}; };

View file

@ -9,7 +9,6 @@ use calcifer::code_editor::themes::DEFAULT_THEMES;
const TERMINAL_HEIGHT : f32 = 200.0; const TERMINAL_HEIGHT : f32 = 200.0;
const RED : egui::Color32 = egui::Color32::from_rgb(235, 108, 99); const RED : egui::Color32 = egui::Color32::from_rgb(235, 108, 99);
const HISTORY_LENGTH : usize = 2;
const SAVE_PATH : &str = "calcifer_save.json"; const SAVE_PATH : &str = "calcifer_save.json";

View file

@ -77,7 +77,6 @@ pub struct Tab {
pub code : String, pub code : String,
pub language : String, pub language : String,
pub saved : bool, pub saved : bool,
pub history : Vec<String>,
pub scroll_offset : f32, pub scroll_offset : f32,
pub last_cursor : Option<CCursorRange>, pub last_cursor : Option<CCursorRange>,
} }
@ -89,7 +88,6 @@ impl Default for Tab {
code: "// Hello there, Master".into(), code: "// Hello there, Master".into(),
language: "rs".into(), language: "rs".into(),
saved: false, saved: false,
history: vec![],
scroll_offset: 0.0, scroll_offset: 0.0,
last_cursor: None, last_cursor: None,
} }