(feat): Text zoom for cosmic-edit.

This commit is contained in:
l-const 2025-02-17 05:17:21 +02:00 committed by Jeremy Soller
parent 48011f1847
commit 5b71f5f850
6 changed files with 123 additions and 5 deletions

View file

@ -42,14 +42,15 @@ pub struct EditorTab {
attrs: Attrs<'static>,
pub editor: Mutex<ViEditor<'static, 'static>>,
pub context_menu: Option<Point>,
pub zoom_adj: i8,
}
impl EditorTab {
pub fn new(config: &Config) -> Self {
//TODO: do not repeat, used in App::init
let attrs = Attrs::new().family(cosmic_text::Family::Monospace);
let mut buffer = Buffer::new_empty(config.metrics());
let zoom_adj = Default::default();
let mut buffer = Buffer::new_empty(config.metrics(zoom_adj));
buffer.set_text(
font_system().write().unwrap().raw(),
"",
@ -69,6 +70,7 @@ impl EditorTab {
attrs,
editor: Mutex::new(ViEditor::new(editor)),
context_menu: None,
zoom_adj,
};
// Update any other config settings
@ -309,6 +311,14 @@ impl EditorTab {
false
}
pub fn zoom_adj(&self) -> i8 {
self.zoom_adj
}
pub fn set_zoom_adj(&mut self, value: i8) {
self.zoom_adj = value;
}
// Code adapted from cosmic-text ViEditor search
pub fn search(&self, regex: &Regex, forwards: bool, wrap_around: bool) -> bool {
let mut editor = self.editor.lock().unwrap();