fn move_cursor(&mut self, key: Arrow) {
        match key {
            Arrow::Left => {
                if self.position.cx != 0 {
                    self.position.cx -= 1;
                } else if self.position.cy > 0 {
                    self.position.cy -= 1;
                    self.position.cx = self.rows[self.position.cy].len;
                }
            }
            Arrow::Right => {
                let rowlen = self.rows.get(self.position.cy).map_or(0, |r| r.len);
                if self.position.cx < rowlen {
                    self.position.cx += 1;
                } else if self.position.cx == rowlen {
                    self.position.cy += 1;
                    self.position.cx = 0;
                }
            }
            Arrow::Up => {
                self.position.cy = if self.position.cy == 0 {
                    0
                } else {
                    self.position.cy - 1
                }
            }
            Arrow::Down => {
                if self.position.cy < self.rows.len() {
                    self.position.cy += 1
                }
            }
        }

        // limit cursor to end of line
        let rowlen = self.rows.get(self.position.cy).map_or(0, |r| r.len);
        if self.position.cx > rowlen {
            self.position.cx = rowlen;
        }
    }
/// Move the cursor in the direction of the `Arrow`
///
/// Supports wrapping, for example a right at the end of
/// a line moves the cursor to the next line
Move the cursor in the direction of the `Arrow`
Supports wrapping, for example a right at the end of
a line moves the cursor to the next line
Move the cursor in the direction of the ` Arrow ` Supports wrapping for example a right at the end of a line moves the cursor to the next line
fn move_cursor(&mut self, key: Arrow) {
        match key {
            Arrow::Left => {
                if self.position.cx != 0 {
                    self.position.cx -= 1;
                } else if self.position.cy > 0 {
                    self.position.cy -= 1;
                    self.position.cx = self.rows[self.position.cy].len;
                }
            }
            Arrow::Right => {
                let rowlen = self.rows.get(self.position.cy).map_or(0, |r| r.len);
                if self.position.cx < rowlen {
                    self.position.cx += 1;
                } else if self.position.cx == rowlen {
                    self.position.cy += 1;
                    self.position.cx = 0;
                }
            }
            Arrow::Up => {
                self.position.cy = if self.position.cy == 0 {
                    0
                } else {
                    self.position.cy - 1
                }
            }
            Arrow::Down => {
                if self.position.cy < self.rows.len() {
                    self.position.cy += 1
                }
            }
        }
        // limit cursor to end of line
        let rowlen = self.rows.get(self.position.cy).map_or(0, |r| r.len);
        if self.position.cx > rowlen {
            self.position.cx = rowlen;
        }
    }
fn move_cursor ( & mut self , key : Arrow ) { match key { Arrow :: Left => { if self . position . cx != 0 { self . position . cx -= 1 ; } else if self . position . cy > 0 { self . position . cy -= 1 ; self . position . cx = self . rows [ self . position . cy ] . len ; } } Arrow :: Right => { let rowlen = self . rows . get ( self . position . cy ) . map_or ( 0 , | r | r . len ) ; if self . position . cx < rowlen { self . position . cx += 1 ; } else if self . position . cx == rowlen { self . position . cy += 1 ; self . position . cx = 0 ; } } Arrow :: Up => { self . position . cy = if self . position . cy == 0 { 0 } else { self . position . cy - 1 } } Arrow :: Down => { if self . position . cy < self . rows . len ( ) { self . position . cy += 1 } } } // limit cursor to end of line let rowlen = self . rows . get ( self . position . cy ) . map_or ( 0 , | r | r . len ) ; if self . position . cx > rowlen { self . position . cx = rowlen ; } }
Move the cursor in the direction of the `Arrow`
Supports wrapping, for example a right at the end of
a line moves the cursor to the next line
Move the cursor in the direction of the ` Arrow ` Supports wrapping for example a right at the end of a line moves the cursor to the next line
&mut self
key
Arrow