76 lines
2.4 KiB
Rust
76 lines
2.4 KiB
Rust
|
|
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,
|
||
|
|
pub visual_line_mapping: Vec<Option<usize>>,
|
||
|
|
pub max_line_length: f32,
|
||
|
|
pub _processed_content: String,
|
||
|
|
}
|
||
|
|
|
||
|
|
impl Default for TextProcessingResult {
|
||
|
|
fn default() -> Self {
|
||
|
|
Self {
|
||
|
|
line_count: 1,
|
||
|
|
visual_line_mapping: vec![Some(1)],
|
||
|
|
max_line_length: 0.0,
|
||
|
|
_processed_content: String::new(),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
#[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,
|
||
|
|
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>>,
|
||
|
|
pub(crate) processing_thread_handle: Option<thread::JoinHandle<()>>,
|
||
|
|
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
|
||
|
|
|
||
|
|
// Width calculation cache and state tracking
|
||
|
|
pub(crate) cached_width: Option<f32>,
|
||
|
|
pub(crate) last_word_wrap: bool,
|
||
|
|
pub(crate) last_show_line_numbers: bool,
|
||
|
|
pub(crate) last_font_size: f32,
|
||
|
|
pub(crate) last_line_side: bool,
|
||
|
|
pub(crate) last_viewport_width: f32,
|
||
|
|
// pub(crate) vim_mode: bool,
|
||
|
|
|
||
|
|
// Cursor tracking for smart scrolling
|
||
|
|
pub(crate) previous_cursor_position: Option<usize>,
|
||
|
|
}
|