formatting fixes
This commit is contained in:
parent
5dc0b6d638
commit
e5b1214f63
@ -1,5 +1,5 @@
|
|||||||
use super::editor::TextEditor;
|
use super::editor::TextEditor;
|
||||||
use crate::app::tab::{Tab, compute_content_hash};
|
use crate::app::tab::{compute_content_hash, Tab};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
@ -82,26 +82,28 @@ impl From<CachedTab> for Tab {
|
|||||||
match load_diff_file(&diff_path) {
|
match load_diff_file(&diff_path) {
|
||||||
Ok(diff_content) => {
|
Ok(diff_content) => {
|
||||||
match diffy::Patch::from_str(&diff_content) {
|
match diffy::Patch::from_str(&diff_content) {
|
||||||
Ok(patch) => {
|
Ok(patch) => match diffy::apply(&original_content, &patch) {
|
||||||
match diffy::apply(&original_content, &patch) {
|
|
||||||
Ok(content) => content,
|
Ok(content) => content,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
eprintln!("Warning: Failed to apply diff for {}, using original content",
|
eprintln!("Warning: Failed to apply diff for {}, using original content",
|
||||||
file_path.display());
|
file_path.display());
|
||||||
original_content
|
original_content
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}
|
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
eprintln!("Warning: Failed to parse diff for {}, using original content",
|
eprintln!(
|
||||||
file_path.display());
|
"Warning: Failed to parse diff for {}, using original content",
|
||||||
|
file_path.display()
|
||||||
|
);
|
||||||
original_content
|
original_content
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("Warning: Failed to load diff file {:?}: {}, using original content",
|
eprintln!(
|
||||||
diff_path, e);
|
"Warning: Failed to load diff file {:?}: {}, using original content",
|
||||||
|
diff_path, e
|
||||||
|
);
|
||||||
original_content
|
original_content
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -109,7 +111,8 @@ impl From<CachedTab> for Tab {
|
|||||||
original_content
|
original_content
|
||||||
};
|
};
|
||||||
|
|
||||||
let original_hash = compute_content_hash(&std::fs::read_to_string(&file_path).unwrap_or_default());
|
let original_hash =
|
||||||
|
compute_content_hash(&std::fs::read_to_string(&file_path).unwrap_or_default());
|
||||||
let expected_hash = cached.original_content_hash;
|
let expected_hash = cached.original_content_hash;
|
||||||
|
|
||||||
let mut tab = Tab::new_with_file(current_content, file_path);
|
let mut tab = Tab::new_with_file(current_content, file_path);
|
||||||
@ -160,7 +163,9 @@ impl TextEditor {
|
|||||||
Some(cache_dir.join("diffs"))
|
Some(cache_dir.join("diffs"))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cleanup_orphaned_diffs(active_diff_files: &[PathBuf]) -> Result<(), Box<dyn std::error::Error>> {
|
fn cleanup_orphaned_diffs(
|
||||||
|
active_diff_files: &[PathBuf],
|
||||||
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
if let Some(diffs_dir) = Self::diffs_cache_dir() {
|
if let Some(diffs_dir) = Self::diffs_cache_dir() {
|
||||||
if diffs_dir.exists() {
|
if diffs_dir.exists() {
|
||||||
for entry in std::fs::read_dir(diffs_dir)? {
|
for entry in std::fs::read_dir(diffs_dir)? {
|
||||||
@ -193,7 +198,8 @@ impl TextEditor {
|
|||||||
|
|
||||||
if !state_cache.tabs.is_empty() {
|
if !state_cache.tabs.is_empty() {
|
||||||
self.tabs = state_cache.tabs.into_iter().map(Tab::from).collect();
|
self.tabs = state_cache.tabs.into_iter().map(Tab::from).collect();
|
||||||
self.active_tab_index = std::cmp::min(state_cache.active_tab_index, self.tabs.len() - 1);
|
self.active_tab_index =
|
||||||
|
std::cmp::min(state_cache.active_tab_index, self.tabs.len() - 1);
|
||||||
self.tab_counter = state_cache.tab_counter;
|
self.tab_counter = state_cache.tab_counter;
|
||||||
self.text_needs_processing = true;
|
self.text_needs_processing = true;
|
||||||
}
|
}
|
||||||
@ -218,7 +224,8 @@ impl TextEditor {
|
|||||||
tab_counter: self.tab_counter,
|
tab_counter: self.tab_counter,
|
||||||
};
|
};
|
||||||
|
|
||||||
let active_diff_files: Vec<PathBuf> = state_cache.tabs
|
let active_diff_files: Vec<PathBuf> = state_cache
|
||||||
|
.tabs
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|tab| tab.diff_file.clone())
|
.filter_map(|tab| tab.diff_file.clone())
|
||||||
.collect();
|
.collect();
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
use eframe::egui;
|
use eframe::egui;
|
||||||
use plist::{Dictionary, Value};
|
use plist::{Dictionary, Value};
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use syntect::highlighting::{Theme as SyntectTheme, ThemeSet, ThemeSettings, Color as SyntectColor, UnderlineOption};
|
use syntect::highlighting::{
|
||||||
|
Color as SyntectColor, Theme as SyntectTheme, ThemeSet, ThemeSettings, UnderlineOption,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, serde::Serialize, serde::Deserialize, Default)]
|
#[derive(Debug, Clone, Copy, PartialEq, serde::Serialize, serde::Deserialize, Default)]
|
||||||
pub enum Theme {
|
pub enum Theme {
|
||||||
@ -233,7 +235,14 @@ pub fn create_code_theme_from_visuals(visuals: &egui::Visuals, font_size: f32) -
|
|||||||
blend_colors(egui::Color32::from_rgb(128, 0, 128), text_color, 0.8) // Purple-like
|
blend_colors(egui::Color32::from_rgb(128, 0, 128), text_color, 0.8) // Purple-like
|
||||||
};
|
};
|
||||||
|
|
||||||
let plist_theme = build_custom_theme_plist("System", &format!("{:?}", bg_color), &format!("{:?}", text_color), &format!("{:?}", comment_color), &format!("{:?}", string_color), &format!("{:?}", keyword_color));
|
let plist_theme = build_custom_theme_plist(
|
||||||
|
"System",
|
||||||
|
&format!("{:?}", bg_color),
|
||||||
|
&format!("{:?}", text_color),
|
||||||
|
&format!("{:?}", comment_color),
|
||||||
|
&format!("{:?}", string_color),
|
||||||
|
&format!("{:?}", keyword_color),
|
||||||
|
);
|
||||||
let file = std::fs::File::create("system.tmTheme").unwrap();
|
let file = std::fs::File::create("system.tmTheme").unwrap();
|
||||||
let writer = std::io::BufWriter::new(file);
|
let writer = std::io::BufWriter::new(file);
|
||||||
|
|
||||||
@ -245,7 +254,6 @@ pub fn create_code_theme_from_visuals(visuals: &egui::Visuals, font_size: f32) -
|
|||||||
let mut set = ThemeSet::new();
|
let mut set = ThemeSet::new();
|
||||||
set.add_from_folder(".").unwrap();
|
set.add_from_folder(".").unwrap();
|
||||||
return set;
|
return set;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_custom_theme_plist(
|
fn build_custom_theme_plist(
|
||||||
@ -263,16 +271,28 @@ fn build_custom_theme_plist(
|
|||||||
|
|
||||||
let mut global_settings_dict = Dictionary::new();
|
let mut global_settings_dict = Dictionary::new();
|
||||||
let mut inner_global_settings = Dictionary::new();
|
let mut inner_global_settings = Dictionary::new();
|
||||||
inner_global_settings.insert("background".to_string(), Value::String(background_color.to_string()));
|
inner_global_settings.insert(
|
||||||
inner_global_settings.insert("foreground".to_string(), Value::String(foreground_color.to_string()));
|
"background".to_string(),
|
||||||
global_settings_dict.insert("settings".to_string(), Value::Dictionary(inner_global_settings));
|
Value::String(background_color.to_string()),
|
||||||
|
);
|
||||||
|
inner_global_settings.insert(
|
||||||
|
"foreground".to_string(),
|
||||||
|
Value::String(foreground_color.to_string()),
|
||||||
|
);
|
||||||
|
global_settings_dict.insert(
|
||||||
|
"settings".to_string(),
|
||||||
|
Value::Dictionary(inner_global_settings),
|
||||||
|
);
|
||||||
settings_array.push(Value::Dictionary(global_settings_dict));
|
settings_array.push(Value::Dictionary(global_settings_dict));
|
||||||
|
|
||||||
let mut comment_scope_dict = Dictionary::new();
|
let mut comment_scope_dict = Dictionary::new();
|
||||||
comment_scope_dict.insert("name".to_string(), Value::String("Comment".to_string()));
|
comment_scope_dict.insert("name".to_string(), Value::String("Comment".to_string()));
|
||||||
comment_scope_dict.insert("scope".to_string(), Value::String("comment".to_string()));
|
comment_scope_dict.insert("scope".to_string(), Value::String("comment".to_string()));
|
||||||
let mut comment_settings = Dictionary::new();
|
let mut comment_settings = Dictionary::new();
|
||||||
comment_settings.insert("foreground".to_string(), Value::String(comment_color.to_string()));
|
comment_settings.insert(
|
||||||
|
"foreground".to_string(),
|
||||||
|
Value::String(comment_color.to_string()),
|
||||||
|
);
|
||||||
comment_settings.insert("fontStyle".to_string(), Value::String("italic".to_string()));
|
comment_settings.insert("fontStyle".to_string(), Value::String("italic".to_string()));
|
||||||
comment_scope_dict.insert("settings".to_string(), Value::Dictionary(comment_settings));
|
comment_scope_dict.insert("settings".to_string(), Value::Dictionary(comment_settings));
|
||||||
settings_array.push(Value::Dictionary(comment_scope_dict));
|
settings_array.push(Value::Dictionary(comment_scope_dict));
|
||||||
@ -281,7 +301,10 @@ fn build_custom_theme_plist(
|
|||||||
string_scope_dict.insert("name".to_string(), Value::String("String".to_string()));
|
string_scope_dict.insert("name".to_string(), Value::String("String".to_string()));
|
||||||
string_scope_dict.insert("scope".to_string(), Value::String("string".to_string()));
|
string_scope_dict.insert("scope".to_string(), Value::String("string".to_string()));
|
||||||
let mut string_settings = Dictionary::new();
|
let mut string_settings = Dictionary::new();
|
||||||
string_settings.insert("foreground".to_string(), Value::String(string_color.to_string()));
|
string_settings.insert(
|
||||||
|
"foreground".to_string(),
|
||||||
|
Value::String(string_color.to_string()),
|
||||||
|
);
|
||||||
string_scope_dict.insert("settings".to_string(), Value::Dictionary(string_settings));
|
string_scope_dict.insert("settings".to_string(), Value::Dictionary(string_settings));
|
||||||
settings_array.push(Value::Dictionary(string_scope_dict));
|
settings_array.push(Value::Dictionary(string_scope_dict));
|
||||||
|
|
||||||
@ -289,7 +312,10 @@ fn build_custom_theme_plist(
|
|||||||
keyword_scope_dict.insert("name".to_string(), Value::String("Keyword".to_string()));
|
keyword_scope_dict.insert("name".to_string(), Value::String("Keyword".to_string()));
|
||||||
keyword_scope_dict.insert("scope".to_string(), Value::String("keyword".to_string()));
|
keyword_scope_dict.insert("scope".to_string(), Value::String("keyword".to_string()));
|
||||||
let mut keyword_settings = Dictionary::new();
|
let mut keyword_settings = Dictionary::new();
|
||||||
keyword_settings.insert("foreground".to_string(), Value::String(keyword_color.to_string()));
|
keyword_settings.insert(
|
||||||
|
"foreground".to_string(),
|
||||||
|
Value::String(keyword_color.to_string()),
|
||||||
|
);
|
||||||
keyword_scope_dict.insert("settings".to_string(), Value::Dictionary(keyword_settings));
|
keyword_scope_dict.insert("settings".to_string(), Value::Dictionary(keyword_settings));
|
||||||
settings_array.push(Value::Dictionary(keyword_scope_dict));
|
settings_array.push(Value::Dictionary(keyword_scope_dict));
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@ use std::io::IsTerminal;
|
|||||||
mod app;
|
mod app;
|
||||||
mod io;
|
mod io;
|
||||||
mod ui;
|
mod ui;
|
||||||
use app::{TextEditor, config::Config};
|
use app::{config::Config, TextEditor};
|
||||||
|
|
||||||
fn main() -> eframe::Result {
|
fn main() -> eframe::Result {
|
||||||
let _args: Vec<String> = env::args().collect();
|
let _args: Vec<String> = env::args().collect();
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
mod editor;
|
mod editor;
|
||||||
mod find_highlight;
|
mod find_highlight;
|
||||||
mod line_numbers;
|
|
||||||
mod languages;
|
mod languages;
|
||||||
|
mod line_numbers;
|
||||||
|
|
||||||
use crate::app::TextEditor;
|
use crate::app::TextEditor;
|
||||||
use eframe::egui;
|
use eframe::egui;
|
||||||
|
|||||||
@ -185,7 +185,10 @@ pub(crate) fn menu_bar(app: &mut TextEditor, ctx: &egui::Context) {
|
|||||||
app.save_config();
|
app.save_config();
|
||||||
ui.close_kind(UiKind::Menu);
|
ui.close_kind(UiKind::Menu);
|
||||||
}
|
}
|
||||||
if ui.checkbox(&mut app.syntax_highlighting, "Syntax Highlighting").clicked() {
|
if ui
|
||||||
|
.checkbox(&mut app.syntax_highlighting, "Syntax Highlighting")
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
app.save_config();
|
app.save_config();
|
||||||
ui.close_kind(UiKind::Menu);
|
ui.close_kind(UiKind::Menu);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,16 +26,13 @@ pub(crate) fn preferences_window(app: &mut TextEditor, ctx: &egui::Context) {
|
|||||||
})
|
})
|
||||||
.show(ctx, |ui| {
|
.show(ctx, |ui| {
|
||||||
ui.vertical_centered(|ui| {
|
ui.vertical_centered(|ui| {
|
||||||
|
|
||||||
ui.heading("General Settings");
|
ui.heading("General Settings");
|
||||||
ui.add_space(8.0);
|
ui.add_space(8.0);
|
||||||
|
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
if ui
|
if ui
|
||||||
.checkbox(&mut app.state_cache, "Cache State")
|
.checkbox(&mut app.state_cache, "Cache State")
|
||||||
.on_hover_text(
|
.on_hover_text("Unsaved changes will be cached between sessions")
|
||||||
"Unsaved changes will be cached between sessions"
|
|
||||||
)
|
|
||||||
.changed()
|
.changed()
|
||||||
{
|
{
|
||||||
app.save_config();
|
app.save_config();
|
||||||
@ -67,10 +64,7 @@ pub(crate) fn preferences_window(app: &mut TextEditor, ctx: &egui::Context) {
|
|||||||
ui.add_space(4.0);
|
ui.add_space(4.0);
|
||||||
|
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
if ui
|
if ui.checkbox(&mut app.word_wrap, "Word Wrap").changed() {
|
||||||
.checkbox(&mut app.word_wrap, "Word Wrap")
|
|
||||||
.changed()
|
|
||||||
{
|
|
||||||
app.save_config();
|
app.save_config();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -92,7 +86,6 @@ pub(crate) fn preferences_window(app: &mut TextEditor, ctx: &egui::Context) {
|
|||||||
{
|
{
|
||||||
app.save_config();
|
app.save_config();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ui.add_space(12.0);
|
ui.add_space(12.0);
|
||||||
|
|||||||
@ -39,7 +39,11 @@ pub(crate) fn tab_bar(app: &mut TextEditor, ctx: &egui::Context) {
|
|||||||
label_text = label_text.italics();
|
label_text = label_text.italics();
|
||||||
}
|
}
|
||||||
|
|
||||||
let tab_response = ui.add(egui::Label::new(label_text).selectable(false).sense(egui::Sense::click()));
|
let tab_response = ui.add(
|
||||||
|
egui::Label::new(label_text)
|
||||||
|
.selectable(false)
|
||||||
|
.sense(egui::Sense::click()),
|
||||||
|
);
|
||||||
if tab_response.clicked() {
|
if tab_response.clicked() {
|
||||||
tab_to_switch = Some(i);
|
tab_to_switch = Some(i);
|
||||||
}
|
}
|
||||||
@ -49,7 +53,10 @@ pub(crate) fn tab_bar(app: &mut TextEditor, ctx: &egui::Context) {
|
|||||||
let close_button = egui::Button::new("×")
|
let close_button = egui::Button::new("×")
|
||||||
.small()
|
.small()
|
||||||
.fill(visuals.panel_fill)
|
.fill(visuals.panel_fill)
|
||||||
.stroke(egui::Stroke::new(0.0, egui::Color32::from_rgb(0, 0, 0)));
|
.stroke(egui::Stroke::new(
|
||||||
|
0.0,
|
||||||
|
egui::Color32::from_rgb(0, 0, 0),
|
||||||
|
));
|
||||||
let close_response = ui.add(close_button);
|
let close_response = ui.add(close_button);
|
||||||
if close_response.clicked() {
|
if close_response.clicked() {
|
||||||
if *is_modified {
|
if *is_modified {
|
||||||
@ -90,5 +97,4 @@ pub(crate) fn tab_bar(app: &mut TextEditor, ctx: &egui::Context) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.tab_bar_rect = Some(tab_bar.response.rect);
|
app.tab_bar_rect = Some(tab_bar.response.rect);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user