@@ -112,9 +112,9 @@ impl Preview<'_, '_> {
112
112
/// Alternate text to show for the preview.
113
113
fn placeholder ( & self ) -> & str {
114
114
match * self {
115
- Self :: EditorDocument ( _) => "<File preview >" ,
115
+ Self :: EditorDocument ( _) => "<Invalid file location >" ,
116
116
Self :: Cached ( preview) => match preview {
117
- CachedPreview :: Document ( _) => "<File preview >" ,
117
+ CachedPreview :: Document ( _) => "<Invalid file location >" ,
118
118
CachedPreview :: Binary => "<Binary file>" ,
119
119
CachedPreview :: LargeFile => "<File too large to preview>" ,
120
120
CachedPreview :: NotFound => "<File not found>" ,
@@ -693,8 +693,14 @@ impl<T: Item + 'static> Picker<T> {
693
693
if let Some ( ( path, range) ) = self . current_file ( cx. editor ) {
694
694
let preview = self . get_preview ( path, cx. editor ) ;
695
695
let doc = match preview. document ( ) {
696
- Some ( doc) => doc,
697
- None => {
696
+ Some ( doc)
697
+ if range. map_or ( true , |( start, end) | {
698
+ start <= end && end <= doc. text ( ) . len_lines ( )
699
+ } ) =>
700
+ {
701
+ doc
702
+ }
703
+ _ => {
698
704
let alt_text = preview. placeholder ( ) ;
699
705
let x = inner. x + inner. width . saturating_sub ( alt_text. len ( ) as u16 ) / 2 ;
700
706
let y = inner. y + inner. height / 2 ;
0 commit comments