Skip to content

Commit 9e8d501

Browse files
committed
feat: persist panel widths, enforce line limits, and improve font selection
Implemented four efficiency and usability improvements from the TODO list: - Added Persistent Panel Widths: Debug, History, Settings, and Theme Editor panels now save and restore their user-adjusted widths. - Improved History Capacity: Increased default limit to 1000 items. Modified logic so global limit changes only affect newly created files. - Enforced Line Limit: Introduced a configurable line limit (default 1000) that truncates content and warns the user when exceeded. Can be disabled by setting it to 0. - Enhanced Font Selection: Added support for confirming font choices with the "Enter" key in both UI and Editor font dropdowns. - Refactored Editor Logic: Restructured the text editor's rendering loop to resolve borrow-checker issues and improve code maintainability.
1 parent 16e5504 commit 9e8d501

5 files changed

Lines changed: 212 additions & 103 deletions

File tree

src/app.rs

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -587,43 +587,67 @@ impl eframe::App for EditorApp {
587587

588588
// Theme Editor panel (right)
589589
if self.show_theme_editor {
590-
egui::SidePanel::right("theme_editor")
590+
let panel_res = egui::SidePanel::right("theme_editor")
591591
.resizable(true)
592-
.default_width(270.0)
592+
.default_width(self.settings.theme_editor_width)
593593
.show(ctx, |ui| {
594594
self.render_theme_editor_panel(ui);
595595
});
596+
597+
let actual_width = panel_res.response.rect.width();
598+
if (actual_width - self.settings.theme_editor_width).abs() > 1.0 {
599+
self.settings.theme_editor_width = actual_width;
600+
let _ = self.settings.save();
601+
}
596602
}
597603

598604
// Settings panel (right)
599605
if self.show_settings_panel {
600-
egui::SidePanel::right("settings_panel")
606+
let panel_res = egui::SidePanel::right("settings_panel")
601607
.resizable(true)
602-
.default_width(350.0)
608+
.default_width(self.settings.settings_panel_width)
603609
.min_width(300.0)
604610
.show(ctx, |ui| {
605611
self.render_settings_panel(ui);
606612
});
613+
614+
let actual_width = panel_res.response.rect.width();
615+
if (actual_width - self.settings.settings_panel_width).abs() > 1.0 {
616+
self.settings.settings_panel_width = actual_width;
617+
let _ = self.settings.save();
618+
}
607619
}
608620

609621
// History panel (right)
610622
if self.show_history_panel {
611-
egui::SidePanel::right("history")
623+
let panel_res = egui::SidePanel::right("history")
612624
.resizable(true)
613-
.default_width(250.0)
625+
.default_width(self.settings.history_panel_width)
614626
.show(ctx, |ui| {
615627
self.render_history_panel(ui);
616628
});
629+
630+
let actual_width = panel_res.response.rect.width();
631+
if (actual_width - self.settings.history_panel_width).abs() > 1.0 {
632+
self.settings.history_panel_width = actual_width;
633+
let _ = self.settings.save();
634+
}
617635
}
618636

619637
// Debug panel (right, below history if both shown)
620638
if self.show_debug_panel {
621-
egui::SidePanel::right("debug")
639+
let panel_res = egui::SidePanel::right("debug")
622640
.resizable(true)
623-
.default_width(250.0)
641+
.default_width(self.settings.debug_panel_width)
624642
.show(ctx, |ui| {
625643
self.render_debug_panel(ui);
626644
});
645+
646+
let actual_width = panel_res.response.rect.width();
647+
if (actual_width - self.settings.debug_panel_width).abs() > 1.0 {
648+
self.settings.debug_panel_width = actual_width;
649+
let _ = self.settings.save();
650+
}
627651
}
628652

629653
// Central editor

src/history.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ pub struct DocumentWithHistory {
4848
}
4949

5050
fn default_max_history() -> usize {
51-
100
51+
1000
5252
}
5353

5454
impl Default for DocumentWithHistory {
5555
fn default() -> Self {
5656
Self {
5757
current_content: String::new(),
5858
history: Vec::new(),
59-
max_history_length: 100,
59+
max_history_length: 1000,
6060
}
6161
}
6262
}
@@ -98,15 +98,15 @@ impl DocumentWithHistory {
9898
Self {
9999
current_content,
100100
history,
101-
max_history_length: 100,
101+
max_history_length: 1000,
102102
}
103103
}
104104
} else {
105105
// No history, just content
106106
Self {
107107
current_content: file_content.to_string(),
108108
history: Vec::new(),
109-
max_history_length: 100,
109+
max_history_length: 1000,
110110
}
111111
}
112112
}

src/settings.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,32 @@ pub struct Settings {
8080
pub show_debug_panel: bool,
8181
/// File tree panel width
8282
pub file_tree_width: f32,
83+
84+
/// Theme editor panel width
85+
#[serde(default = "default_panel_width_270")]
86+
pub theme_editor_width: f32,
87+
88+
/// Settings panel width
89+
#[serde(default = "default_panel_width_350")]
90+
pub settings_panel_width: f32,
91+
92+
/// History panel width
93+
#[serde(default = "default_panel_width_250")]
94+
pub history_panel_width: f32,
95+
96+
/// Debug panel width
97+
#[serde(default = "default_panel_width_250")]
98+
pub debug_panel_width: f32,
99+
83100
/// Show subfolders in file tree
84101
pub show_subfolders: bool,
102+
85103
/// Max history length
86104
pub max_history_length: usize,
105+
106+
/// Editor line limit (0 means disabled)
107+
#[serde(default = "default_max_lines")]
108+
pub max_lines: usize,
87109

88110
/// Whether to show full keyfile path in status bar
89111
#[serde(default)]
@@ -133,6 +155,22 @@ fn default_toolbar_icon_size() -> f32 {
133155
24.0
134156
}
135157

158+
fn default_panel_width_250() -> f32 {
159+
250.0
160+
}
161+
162+
fn default_panel_width_270() -> f32 {
163+
270.0
164+
}
165+
166+
fn default_panel_width_350() -> f32 {
167+
350.0
168+
}
169+
170+
fn default_max_lines() -> usize {
171+
1000
172+
}
173+
136174
impl Default for Settings {
137175
fn default() -> Self {
138176
Self {
@@ -158,8 +196,13 @@ impl Default for Settings {
158196

159197
show_debug_panel: false,
160198
file_tree_width: 200.0,
199+
theme_editor_width: default_panel_width_270(),
200+
settings_panel_width: default_panel_width_350(),
201+
history_panel_width: default_panel_width_250(),
202+
debug_panel_width: default_panel_width_250(),
161203
show_subfolders: true,
162204
max_history_length: 100,
205+
max_lines: default_max_lines(),
163206

164207
show_keyfile_path: false,
165208
start_maximized: false,

0 commit comments

Comments
 (0)