2025-07-05 14:42:45 -04:00
|
|
|
use crate::app::tab::Tab;
|
|
|
|
|
use crate::app::theme::Theme;
|
|
|
|
|
use eframe::egui;
|
|
|
|
|
use std::sync::{Arc, Mutex};
|
|
|
|
|
use std::thread;
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, PartialEq)]
|
|
|
|
|
pub enum UnsavedAction {
|
|
|
|
|
Quit,
|
|
|
|
|
CloseTab(usize),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
|
pub struct TextProcessingResult {
|
|
|
|
|
pub line_count: usize,
|
2025-07-15 11:07:41 -04:00
|
|
|
pub longest_line_index: usize, // Which line is the longest (0-based)
|
|
|
|
|
pub longest_line_length: usize, // Character count of the longest line
|
2025-07-15 00:42:01 -04:00
|
|
|
pub longest_line_pixel_width: f32, // Actual pixel width of the longest line
|
2025-07-05 14:42:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Default for TextProcessingResult {
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
line_count: 1,
|
2025-07-15 00:42:01 -04:00
|
|
|
longest_line_index: 0,
|
|
|
|
|
longest_line_length: 0,
|
|
|
|
|
longest_line_pixel_width: 0.0,
|
2025-07-05 14:42:45 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive()]
|
|
|
|
|
pub struct TextEditor {
|
|
|
|
|
pub(crate) tabs: Vec<Tab>,
|
|
|
|
|
pub(crate) active_tab_index: usize,
|
|
|
|
|
pub(crate) tab_counter: usize, // Counter for numbering new tabs
|
|
|
|
|
pub(crate) show_about: bool,
|
|
|
|
|
pub(crate) show_shortcuts: bool,
|
|
|
|
|
pub(crate) show_find: bool,
|
|
|
|
|
pub(crate) show_preferences: bool,
|
|
|
|
|
pub(crate) pending_unsaved_action: Option<UnsavedAction>,
|
|
|
|
|
pub(crate) force_quit_confirmed: bool,
|
|
|
|
|
pub(crate) clean_quit_requested: bool,
|
|
|
|
|
pub(crate) show_line_numbers: bool,
|
|
|
|
|
pub(crate) word_wrap: bool,
|
|
|
|
|
pub(crate) auto_hide_toolbar: bool,
|
2025-07-15 00:42:01 -04:00
|
|
|
pub(crate) auto_hide_tab_bar: bool,
|
2025-07-05 14:42:45 -04:00
|
|
|
pub(crate) theme: Theme,
|
|
|
|
|
pub(crate) line_side: bool,
|
|
|
|
|
pub(crate) font_family: String,
|
|
|
|
|
pub(crate) font_size: f32,
|
|
|
|
|
pub(crate) font_size_input: Option<String>,
|
|
|
|
|
pub(crate) zoom_factor: f32,
|
|
|
|
|
pub(crate) menu_interaction_active: bool,
|
|
|
|
|
pub(crate) tab_bar_rect: Option<egui::Rect>,
|
|
|
|
|
pub(crate) menu_bar_stable_until: Option<std::time::Instant>,
|
|
|
|
|
pub(crate) text_processing_result: Arc<Mutex<TextProcessingResult>>,
|
2025-07-15 11:07:41 -04:00
|
|
|
pub(crate) _processing_thread_handle: Option<thread::JoinHandle<()>>,
|
2025-07-05 14:42:45 -04:00
|
|
|
pub(crate) find_query: String,
|
|
|
|
|
pub(crate) find_matches: Vec<(usize, usize)>, // (start_pos, end_pos) byte positions
|
|
|
|
|
pub(crate) current_match_index: Option<usize>,
|
|
|
|
|
pub(crate) case_sensitive_search: bool,
|
|
|
|
|
pub(crate) prev_show_find: bool, // Track previous state to detect transitions
|
2025-07-15 11:07:41 -04:00
|
|
|
|
2025-07-05 14:42:45 -04:00
|
|
|
// Cursor tracking for smart scrolling
|
|
|
|
|
pub(crate) previous_cursor_position: Option<usize>,
|
2025-07-15 11:07:41 -04:00
|
|
|
|
2025-07-15 00:42:01 -04:00
|
|
|
// Track previous content for incremental processing
|
|
|
|
|
pub(crate) previous_content: String,
|
|
|
|
|
pub(crate) previous_cursor_char_index: Option<usize>,
|
2025-07-15 11:07:41 -04:00
|
|
|
pub(crate) current_cursor_line: usize, // Track current line number incrementally
|
|
|
|
|
pub(crate) previous_cursor_line: usize, // Track previous line for comparison
|
|
|
|
|
pub(crate) font_settings_changed: bool, // Flag to trigger text reprocessing when font changes
|
2025-07-05 14:42:45 -04:00
|
|
|
}
|