More balanced adaptive drill generation, Tab fixes, mouse control tweaks
This commit is contained in:
@@ -17,6 +17,7 @@ pub struct DrillState {
|
||||
pub finished_at: Option<Instant>,
|
||||
pub typo_flags: HashSet<usize>,
|
||||
pub synthetic_spans: Vec<SyntheticSpan>,
|
||||
pub auto_indent_after_newline: bool,
|
||||
}
|
||||
|
||||
impl DrillState {
|
||||
@@ -29,6 +30,7 @@ impl DrillState {
|
||||
finished_at: None,
|
||||
typo_flags: HashSet::new(),
|
||||
synthetic_spans: Vec::new(),
|
||||
auto_indent_after_newline: true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,6 +265,18 @@ mod tests {
|
||||
assert_eq!(drill.accuracy(), 100.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_correct_enter_no_auto_indent_when_disabled() {
|
||||
let mut drill = DrillState::new("if x:\n\tpass");
|
||||
drill.auto_indent_after_newline = false;
|
||||
for ch in "if x:".chars() {
|
||||
input::process_char(&mut drill, ch);
|
||||
}
|
||||
input::process_char(&mut drill, '\n');
|
||||
let expected_cursor = "if x:\n".chars().count();
|
||||
assert_eq!(drill.cursor, expected_cursor);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_nested_synthetic_spans_collapse_to_single_error() {
|
||||
let mut drill = DrillState::new("abcd\nefgh");
|
||||
|
||||
@@ -47,9 +47,9 @@ pub fn process_char(drill: &mut DrillState, ch: char) -> Option<KeystrokeEvent>
|
||||
} else if correct {
|
||||
drill.input.push(CharStatus::Correct);
|
||||
drill.cursor += 1;
|
||||
// IDE-like behavior: when Enter is correctly typed, auto-consume
|
||||
// Optional IDE-like behavior: when Enter is correctly typed, auto-consume
|
||||
// indentation whitespace on the next line.
|
||||
if ch == '\n' {
|
||||
if ch == '\n' && drill.auto_indent_after_newline {
|
||||
apply_auto_indent_after_newline(drill);
|
||||
}
|
||||
} else if ch == '\n' {
|
||||
|
||||
Reference in New Issue
Block a user