fix(records): allow adding rows in empty records view
Add helper methods to CmdContext to clarify layout state and synthetic record presence. Update AddRecordRow to check for records mode generally rather than requiring a synthetic record at the current cursor, which allows adding the first row to an empty records view. Includes a regression test for the empty records view scenario. Co-Authored-By: fiddlerwoaroof/git-smart-commit (gemma-4-31B-it-UD-Q4_K_XL.gguf)
This commit is contained in:
@ -712,6 +712,35 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
/// Regression: pressing `o` in an empty records view should create the
|
||||
/// first synthetic row instead of only entering edit mode on empty space.
|
||||
#[test]
|
||||
fn add_record_row_in_empty_records_view_creates_first_row() {
|
||||
let mut m = Model::new("T");
|
||||
m.add_category("Region").unwrap();
|
||||
m.category_mut("Region").unwrap().add_item("East");
|
||||
let mut app = App::new(m, None);
|
||||
|
||||
app.handle_key(KeyEvent::new(KeyCode::Char('R'), KeyModifiers::NONE))
|
||||
.unwrap();
|
||||
assert!(app.layout.is_records_mode(), "R should enter records mode");
|
||||
assert_eq!(app.layout.row_count(), 0, "fresh records view starts empty");
|
||||
|
||||
app.handle_key(KeyEvent::new(KeyCode::Char('o'), KeyModifiers::NONE))
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
app.layout.row_count(),
|
||||
1,
|
||||
"o should create the first record row in an empty records view"
|
||||
);
|
||||
assert!(
|
||||
matches!(app.mode, AppMode::Editing { .. }),
|
||||
"o should leave the app in edit mode, got {:?}",
|
||||
app.mode
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn command_mode_buffer_cleared_on_reentry() {
|
||||
use crossterm::event::KeyEvent;
|
||||
|
||||
Reference in New Issue
Block a user