@@ -46,7 +46,7 @@ use helix_core::{
4646} ;
4747use helix_view:: {
4848 document:: { FormatterError , Mode , SCRATCH_BUFFER_NAME } ,
49- editor:: Action ,
49+ editor:: { Action , CloseError } ,
5050 expansion,
5151 info:: Info ,
5252 input:: KeyEvent ,
@@ -3157,8 +3157,6 @@ fn file_explorer_in_current_directory(cx: &mut Context) {
31573157}
31583158
31593159fn buffer_picker ( cx : & mut Context ) {
3160- let current = view ! ( cx. editor) . doc ;
3161-
31623160 struct BufferMeta {
31633161 id : DocumentId ,
31643162 path : Option < PathBuf > ,
@@ -3167,23 +3165,30 @@ fn buffer_picker(cx: &mut Context) {
31673165 focused_at : std:: time:: Instant ,
31683166 }
31693167
3170- let new_meta = |doc : & Document | BufferMeta {
3171- id : doc. id ( ) ,
3172- path : doc. path ( ) . cloned ( ) ,
3173- is_modified : doc. is_modified ( ) ,
3174- is_current : doc. id ( ) == current,
3175- focused_at : doc. focused_at ,
3176- } ;
3168+ let get_items = |editor : & Editor | -> Vec < BufferMeta > {
3169+ let current = view ! ( editor) . doc ;
31773170
3178- let mut items = cx
3179- . editor
3180- . documents
3181- . values ( )
3182- . map ( new_meta)
3183- . collect :: < Vec < BufferMeta > > ( ) ;
3171+ let new_meta = |doc : & Document | BufferMeta {
3172+ id : doc. id ( ) ,
3173+ path : doc. path ( ) . cloned ( ) ,
3174+ is_modified : doc. is_modified ( ) ,
3175+ is_current : doc. id ( ) == current,
3176+ focused_at : doc. focused_at ,
3177+ } ;
31843178
3185- // mru
3186- items. sort_unstable_by_key ( |item| std:: cmp:: Reverse ( item. focused_at ) ) ;
3179+ let mut items = editor
3180+ . documents
3181+ . values ( )
3182+ . map ( new_meta)
3183+ . collect :: < Vec < BufferMeta > > ( ) ;
3184+
3185+ // mru
3186+ items. sort_unstable_by_key ( |item| std:: cmp:: Reverse ( item. focused_at ) ) ;
3187+
3188+ items
3189+ } ;
3190+
3191+ let items = get_items ( cx. editor ) ;
31873192
31883193 let columns = [
31893194 PickerColumn :: new ( "id" , |meta : & BufferMeta , _| meta. id . to_string ( ) . into ( ) ) ,
@@ -3234,6 +3239,18 @@ fn buffer_picker(cx: &mut Context) {
32343239 ( cursor_line, cursor_line)
32353240 } ) ;
32363241 Some ( ( meta. id . into ( ) , lines) )
3242+ } )
3243+ . with_delete_item ( move |editor, meta| {
3244+ if let Err ( err) = editor. close_document ( meta. id , false ) {
3245+ editor. set_error ( match err {
3246+ CloseError :: BufferModified ( s) => format ! ( "Could not close modified buffer: {}" , s) ,
3247+ _ => "Could not close buffer" . to_owned ( ) ,
3248+ } ) ;
3249+ } else {
3250+ editor. clear_status ( ) ;
3251+ }
3252+
3253+ get_items ( editor)
32373254 } ) ;
32383255 cx. push_layer ( Box :: new ( overlaid ( picker) ) ) ;
32393256}
0 commit comments