~zanneth/hirogen

65d45b5066c7170834fd22f02be757992aeaaebb — Charles Magahern 2 years ago dc0b9c7
Fix crash when directional arrows change the current page
1 files changed, 33 insertions(+), 23 deletions(-)

M src/document_window.rs
M src/document_window.rs => src/document_window.rs +33 -23
@@ 805,33 805,43 @@ impl DocumentWindow
    
    fn handle_direction_key_press(self: &DocumentWindowRef, direction: Direction)
    {
        let mut document = self.document.borrow_mut();
        document.move_selection(&direction);
        self.hex_view_queue_redraw();
        let page_scroll_dir = {
            let mut document = self.document.borrow_mut();
            document.move_selection(&direction);
            self.hex_view_queue_redraw();

        // check to see if we must page up/down the scrolling window based on the new selection.
        if let Some(selection) = document.checked_selection() {
            let start = selection.byte_range.start;
            let location = DocumentLocation {
                byte_offset: start,
                region:      selection.region,
            };
            // check to see if we must page up/down the scrolling window based on the new selection.
            if let Some(selection) = document.checked_selection() {
                let start = selection.byte_range.start;
                let location = DocumentLocation {
                    byte_offset: start,
                    region:      selection.region,
                };

            let pixel = document.pixel_from_location(&location);
            let translated_pos = self
                .hex_view
                .translate_coordinates(
                    &self.hex_view, 
                    pixel.0 as i32,
                    pixel.1 as i32)
                .unwrap();
            let bounds = self.hex_view.get_allocation();
                let pixel = document.pixel_from_location(&location);
                let translated_pos = self
                    .hex_view
                    .translate_coordinates(
                        &self.hex_view, 
                        pixel.0 as i32,
                        pixel.1 as i32)
                    .unwrap();
                let bounds = self.hex_view.get_allocation();

            if translated_pos.1 > bounds.height {
                self.scroll_page(&Direction::Down);
            } else if translated_pos.1 < 0 {
                self.scroll_page(&Direction::Up);
                if translated_pos.1 > bounds.height {
                    Some(Direction::Down)
                } else if translated_pos.1 < 0 {
                    Some(Direction::Up)
                } else {
                    None
                }
            } else {
                None
            }
        };
        
        if let Some(page_scroll_dir) = page_scroll_dir {
            self.scroll_page(&page_scroll_dir);
        }
    }