diff options
| author | Rose Hogenson <rosehogenson@posteo.net> | 2024-01-11 16:38:04 -0800 |
|---|---|---|
| committer | Rose Hogenson <rosehogenson@posteo.net> | 2024-01-11 21:31:39 -0800 |
| commit | e23b1c7254aa21c0eb2fd18f720df262725c6d81 (patch) | |
| tree | bec06482f9e461f25aced992277718af9a83ac72 /src/rope.rs | |
| parent | Apply a clippy suggestion. (diff) | |
| download | editor-e23b1c7254aa21c0eb2fd18f720df262725c6d81.tar.zst | |
Implement Home, End, PgUp, and PgDn.
Diffstat (limited to 'src/rope.rs')
| -rw-r--r-- | src/rope.rs | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/rope.rs b/src/rope.rs index 737d949..8bda5af 100644 --- a/src/rope.rs +++ b/src/rope.rs @@ -84,7 +84,7 @@ impl Rope { Rope(Node::Leaf(Leaf { unsafe_buf: Some(Rc::from(buf)), start: 0, - end: u16::try_from(buf.len()).expect("I just checked the length, it should be ok"), + end: u16::try_from(buf.len()).expect("buf.len() <= MAX_NODE_SIZE"), })) } @@ -291,6 +291,9 @@ impl Rope { } pub fn line(&self, n: usize) -> Rope { + if n > self.lines() { + panic!("Line index {} out of range 0..={}", n, self.lines()); + } self.slice(self.line_start(n), self.line_end(n)).clone() } @@ -327,13 +330,11 @@ impl Rope { return self.clone(); } match self { - Rope(Node::Leaf(l)) => { - Rope(Node::Leaf(Leaf{ - unsafe_buf: l.unsafe_buf.clone(), - start: l.start+u16::try_from(start).expect("index.start should be less than MAX_NODE_SIZE since self is a leaf"), - end: l.start+u16::try_from(end).expect("index.end should be less than or equal to MAX_NODE_SIZE since self is a leaf"), - })) - } + Rope(Node::Leaf(l)) => Rope(Node::Leaf(Leaf { + unsafe_buf: l.unsafe_buf.clone(), + start: l.start + u16::try_from(start).expect("start <= self.len()"), + end: l.start + u16::try_from(end).expect("end <= self.len()"), + })), Rope(Node::Branch(b)) => { let mut s = Rope::new(&[]); let mut start = start; |
