~zanneth/hirogen

67127280b6a646b11f063baa84e2ded0174b4a3d — Charles Magahern 2 years ago d54cf10
Don't scroll to find result if already visible
1 files changed, 30 insertions(+), 9 deletions(-)

M src/document_window.rs
M src/document_window.rs => src/document_window.rs +30 -9
@@ 1011,7 1011,10 @@ impl DocumentWindow
        };
        
        if found_result_and_updated_sel {
            self.scroll_to_selection();
            if !self.is_selection_visible() {
                self.scroll_to_selection();
            }

            self.reload_actions_state();
            self.hex_view_queue_redraw();
        }


@@ 1066,20 1069,38 @@ impl DocumentWindow
        }
    }
    
    pub fn scroll_to_selection(self: &DocumentWindowRef)
    fn first_row_in_selection(self: &DocumentWindowRef) -> Option<usize>
    {
        let row = {
            let document = self.document.borrow();
            let selection = guard_unwrap!(document.checked_selection());
        let document = self.document.borrow();
        
        if let Some(selection) = document.checked_selection() {
            let loc = DocumentLocation {
                byte_offset: selection.byte_range.start,
                region:      selection.region,
            };
            
            document.row_from_location(&loc)
        };
        
        self.hex_adjustment.set_value(row as f64);
            Some(document.row_from_location(&loc))
        } else {
            None
        }
    }
    
    fn is_selection_visible(self: &DocumentWindowRef) -> bool
    {
        if let Some(row) = self.first_row_in_selection() {
            let rowf = row as f64;
            let vadj = &self.hex_adjustment;
            rowf >= vadj.get_value() && rowf < vadj.get_value() + vadj.get_page_size()
        } else {
            false
        }
    }
    
    fn scroll_to_selection(self: &DocumentWindowRef)
    {
        if let Some(row) = self.first_row_in_selection() {
            self.hex_adjustment.set_value(row as f64);
        }
    }
    
    fn header_view_queue_redraw(self: &DocumentWindowRef)