add alert system

This commit is contained in:
alice pellerin
2026-03-18 19:26:40 -05:00
parent 2ee61fef71
commit ce2d753f96
4 changed files with 23 additions and 12 deletions
+10 -5
View File
@@ -1,5 +1,5 @@
use std::{cmp::min, fs::File, io::Write, mem::{replace, swap}};
use ratatui::{style::Stylize, text::Span};
use crate::{BYTES_PER_LINE, app::{App, Mode, PartialAction}, edit_action::EditAction};
#[derive(Clone, Copy)]
@@ -120,11 +120,13 @@ impl App {
}
}
const fn quit_if_saved(&mut self) {
fn quit_if_saved(&mut self) {
if self.all_changes_saved() {
self.quit();
} else {
// TODO: show alert of some kind
self.alert_message = Span::from(
"there are unsaved changes, use Q to override"
).red();
}
}
@@ -227,8 +229,11 @@ impl App {
self.cursor.collapse();
}
const fn goto_line_end(&mut self) {
self.cursor.head += BYTES_PER_LINE - 1 - (self.cursor.head % BYTES_PER_LINE);
fn goto_line_end(&mut self) {
self.cursor.head = min(
self.cursor.head + BYTES_PER_LINE - 1 - (self.cursor.head % BYTES_PER_LINE),
self.max_contents_index()
);
self.cursor.collapse();
}