mirror of
https://github.com/msfjarvis/text-editor.git
synced 2024-06-03 04:18:57 +05:30
refactor(document): rewrite if
comparison to use std::cmp
This commit is contained in:
parent
170e794516
commit
09d6343874
|
@ -1,5 +1,6 @@
|
|||
use crate::Position;
|
||||
use crate::Row;
|
||||
use std::cmp::Ordering;
|
||||
use std::fs;
|
||||
use std::io::{Error, Write};
|
||||
|
||||
|
@ -39,13 +40,17 @@ impl Document {
|
|||
self.insert_newline(at);
|
||||
return;
|
||||
}
|
||||
if at.y == self.len() {
|
||||
let mut row = Row::default();
|
||||
row.insert(0, c);
|
||||
self.rows.push(row);
|
||||
} else if at.y < self.len() {
|
||||
let row = self.rows.get_mut(at.y).unwrap();
|
||||
row.insert(at.x, c);
|
||||
match self.len().cmp(&at.y) {
|
||||
Ordering::Equal => {
|
||||
let mut row = Row::default();
|
||||
row.insert(0, c);
|
||||
self.rows.push(row);
|
||||
}
|
||||
Ordering::Greater => {
|
||||
let row = self.rows.get_mut(at.y).unwrap();
|
||||
row.insert(at.x, c);
|
||||
}
|
||||
Ordering::Less => (),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user