formatting/some sanity fixes

This commit is contained in:
candle 2025-07-16 17:34:11 -04:00
parent 1edf0995c0
commit f56ad6c7c5
7 changed files with 39 additions and 23 deletions

View File

@ -149,7 +149,7 @@ fn get_shortcuts() -> Vec<ShortcutDefinition> {
] ]
} }
fn execute_action(action: ShortcutAction, editor: &mut TextEditor, ctx: &egui::Context) -> bool { fn execute_action(action: ShortcutAction, editor: &mut TextEditor) -> bool {
match action { match action {
ShortcutAction::NewFile => { ShortcutAction::NewFile => {
io::new_file(editor); io::new_file(editor);
@ -291,16 +291,16 @@ pub fn handle(editor: &mut TextEditor, ctx: &egui::Context) {
if i.consume_key(modifiers, key) { if i.consume_key(modifiers, key) {
match action { match action {
ShortcutAction::ZoomIn | ShortcutAction::ZoomOut => { ShortcutAction::ZoomIn | ShortcutAction::ZoomOut => {
font_zoom_occurred = execute_action(action, editor, ctx); font_zoom_occurred = execute_action(action, editor);
} }
ShortcutAction::GlobalZoomIn ShortcutAction::GlobalZoomIn
| ShortcutAction::GlobalZoomOut | ShortcutAction::GlobalZoomOut
| ShortcutAction::ResetZoom => { | ShortcutAction::ResetZoom => {
execute_action(action, editor, ctx); execute_action(action, editor);
global_zoom_occurred = true; global_zoom_occurred = true;
} }
_ => { _ => {
execute_action(action, editor, ctx); execute_action(action, editor);
} }
} }
break; break;

View File

@ -154,9 +154,10 @@ impl TextEditor {
self.update_find_matches(); self.update_find_matches();
if let Some(active_tab) = self.get_active_tab() { if let Some(active_tab) = self.get_active_tab() {
let replacement_end_char = Self::safe_slice_to_pos(&active_tab.content, replacement_end) let replacement_end_char =
.chars() Self::safe_slice_to_pos(&active_tab.content, replacement_end)
.count(); .chars()
.count();
let text_edit_id = egui::Id::new("main_text_editor"); let text_edit_id = egui::Id::new("main_text_editor");
if let Some(mut state) = egui::TextEdit::load_state(ctx, text_edit_id) { if let Some(mut state) = egui::TextEdit::load_state(ctx, text_edit_id) {

View File

@ -35,13 +35,17 @@ impl TextEditor {
let (files_to_list, title, confirmation_text, button_text, action) = let (files_to_list, title, confirmation_text, button_text, action) =
if let Some(action) = &self.pending_unsaved_action { if let Some(action) = &self.pending_unsaved_action {
match action { match action {
UnsavedAction::Quit => ( UnsavedAction::Quit => {
self.get_unsaved_files(), let files = self.get_unsaved_files();
"Unsaved Changes".to_string(), let file_plural = if files.len() > 1 { "s" } else { "" };
"You have unsaved changes.".to_string(), (
"Quit Without Saving".to_string(), files,
action.to_owned(), "Unsaved Changes".to_string(),
), format!("File{file_plural} with unsaved changes:"),
"Quit Without Saving".to_string(),
action.to_owned(),
)
}
UnsavedAction::CloseTab(tab_index) => { UnsavedAction::CloseTab(tab_index) => {
let file_name = self let file_name = self
.tabs .tabs
@ -50,7 +54,7 @@ impl TextEditor {
( (
vec![file_name], vec![file_name],
"Unsaved Changes".to_string(), "Unsaved Changes".to_string(),
"The file has unsaved changes.".to_string(), "This file has unsaved changes:".to_string(),
"Close Without Saving".to_string(), "Close Without Saving".to_string(),
action.to_owned(), action.to_owned(),
) )

View File

@ -326,7 +326,9 @@ impl TextEditor {
let line_start_boundary = line_start; let line_start_boundary = line_start;
let line_end_boundary = line_end; let line_end_boundary = line_end;
if content.is_char_boundary(line_start_boundary) && content.is_char_boundary(line_end_boundary) { if content.is_char_boundary(line_start_boundary)
&& content.is_char_boundary(line_end_boundary)
{
content[line_start_boundary..line_end_boundary].to_string() content[line_start_boundary..line_end_boundary].to_string()
} else { } else {
Self::safe_slice_to_pos(content, line_end_boundary)[line_start_boundary..].to_string() Self::safe_slice_to_pos(content, line_end_boundary)[line_start_boundary..].to_string()

View File

@ -24,7 +24,10 @@ pub(crate) fn open_file(app: &mut TextEditor) {
if should_replace_current_tab { if should_replace_current_tab {
if let Some(active_tab) = app.get_active_tab_mut() { if let Some(active_tab) = app.get_active_tab_mut() {
let title = path.file_name().and_then(|n| n.to_str()).unwrap_or("Untitled"); let title = path
.file_name()
.and_then(|n| n.to_str())
.unwrap_or("Untitled");
active_tab.content = content; active_tab.content = content;
active_tab.file_path = Some(path.to_path_buf()); active_tab.file_path = Some(path.to_path_buf());
active_tab.title = title.to_string(); active_tab.title = title.to_string();
@ -71,7 +74,10 @@ pub(crate) fn save_to_path(app: &mut TextEditor, path: PathBuf) {
if let Some(active_tab) = app.get_active_tab_mut() { if let Some(active_tab) = app.get_active_tab_mut() {
match fs::write(&path, &active_tab.content) { match fs::write(&path, &active_tab.content) {
Ok(()) => { Ok(()) => {
let title = path.file_name().and_then(|n| n.to_str()).unwrap_or("Untitled"); let title = path
.file_name()
.and_then(|n| n.to_str())
.unwrap_or("Untitled");
active_tab.file_path = Some(path.to_path_buf()); active_tab.file_path = Some(path.to_path_buf());
active_tab.title = title.to_string(); active_tab.title = title.to_string();
active_tab.mark_as_saved(); active_tab.mark_as_saved();

View File

@ -62,7 +62,9 @@ fn draw_single_highlight(
} }
let line_start_byte_pos = text_up_to_start.rfind('\n').map(|pos| pos + 1).unwrap_or(0); let line_start_byte_pos = text_up_to_start.rfind('\n').map(|pos| pos + 1).unwrap_or(0);
let line_start_char_pos = safe_slice_to_pos(content, line_start_byte_pos).chars().count(); let line_start_char_pos = safe_slice_to_pos(content, line_start_byte_pos)
.chars()
.count();
let start_char_pos = safe_slice_to_pos(content, start_pos).chars().count(); let start_char_pos = safe_slice_to_pos(content, start_pos).chars().count();
let start_col = start_char_pos - line_start_char_pos; let start_col = start_char_pos - line_start_char_pos;

View File

@ -143,7 +143,8 @@ pub(crate) fn preferences_window(app: &mut TextEditor, ctx: &egui::Context) {
.font(preview_font.to_owned()), .font(preview_font.to_owned()),
); );
ui.label( ui.label(
egui::RichText::new("1234567890 !@#$%^&*()").font(preview_font.to_owned()), egui::RichText::new("1234567890 !@#$%^&*()")
.font(preview_font.to_owned()),
); );
}); });
}); });