ced/src/app/state/tabs.rs
2025-07-16 17:20:09 -04:00

48 lines
1.5 KiB
Rust

use super::editor::TextEditor;
use crate::app::tab::Tab;
impl TextEditor {
pub fn get_active_tab(&self) -> Option<&Tab> {
self.tabs.get(self.active_tab_index)
}
pub fn get_active_tab_mut(&mut self) -> Option<&mut Tab> {
self.tabs.get_mut(self.active_tab_index)
}
pub fn add_new_tab(&mut self) {
self.tab_counter += 1;
self.tabs.push(Tab::new_empty(self.tab_counter));
self.active_tab_index = self.tabs.len() - 1;
if self.show_find && !self.find_query.is_empty() {
self.update_find_matches();
}
self.text_needs_processing = true;
}
pub fn close_tab(&mut self, tab_index: usize) {
if self.tabs.len() > 1 && tab_index < self.tabs.len() {
self.tabs.remove(tab_index);
if self.active_tab_index >= self.tabs.len() {
self.active_tab_index = self.tabs.len() - 1;
} else if self.active_tab_index > tab_index {
self.active_tab_index -= 1;
}
if self.show_find && !self.find_query.is_empty() {
self.update_find_matches();
}
self.text_needs_processing = true;
}
}
pub fn switch_to_tab(&mut self, tab_index: usize) {
if tab_index < self.tabs.len() {
self.active_tab_index = tab_index;
if self.show_find && !self.find_query.is_empty() {
self.update_find_matches();
}
self.text_needs_processing = true;
}
}
}