@@ -2,7 +2,7 @@ use revi_ui::tui::layout::{Pos, Size};
2
2
3
3
use crate :: context:: Context ;
4
4
use crate :: mode:: Mode ;
5
- use crate :: { Buffer , Event , MessageBox } ;
5
+ use crate :: { panes :: MessageBox , Buffer , Event } ;
6
6
use std:: any:: Any ;
7
7
use std:: cell:: RefCell ;
8
8
use std:: fmt;
@@ -16,7 +16,8 @@ pub trait Command: fmt::Debug {
16
16
}
17
17
18
18
macro_rules! build_command {
19
- ( $name: ident$( ( $( $ty: ty $( , ) ?) * ) ) ?; $caller: expr) => {
19
+ ( $( [ doc: $doc: expr] ) ? $name: ident$( ( $( $ty: ty $( , ) ?) * ) ) ?; $caller: expr) => {
20
+ $( #[ doc=$doc] ) ?
20
21
#[ derive( Debug , PartialEq ) ]
21
22
pub struct $name $( ( $( pub $ty, ) * ) ) ?;
22
23
impl Command for $name {
@@ -342,29 +343,23 @@ build_command!(
342
343
) ;
343
344
344
345
build_command ! (
346
+ [ doc: "loads a file from disk if it exsists and if not just create a empty file
347
+ and place it in buffer list and put the current file buffer into the current window." ]
345
348
EditFile ( String ) ;
346
349
|Self ( command) : & EditFile , ctx: Context | {
347
350
let Some ( ( _, name) ) = command. split_once( ' ' ) else {
348
351
let msg = "edit command requires a file path" ;
349
352
Message ( msg. into( ) , command. into( ) ) . call( ctx) ;
350
353
return ;
351
354
} ;
352
- let settings = ctx. settings. borrow( ) ;
353
- let line_numbers = settings. line_numbers;
354
- let id = ctx. panes. borrow( ) . len( ) ;
355
- * ctx. focused_pane. borrow_mut( ) = id;
356
355
let text = std:: fs:: read_to_string( name) . unwrap_or( "\n " . into( ) ) ;
357
356
let rope = ropey:: Rope :: from_str( & text) ;
358
- let buf = Rc :: new( RefCell :: new( Buffer :: new( name, rope) ) ) ;
359
- let pos = revi_ui:: tui:: layout:: Pos :: default ( ) ;
360
- // HACK: sheppereds hook
361
- // size needs to be dynamicly dispatched
362
- let size = ctx. window_size( ) ;
363
- let window = crate :: Window :: new( pos, size, buf)
364
- . with_status_bar( true )
365
- . with_status_bar( line_numbers) ;
366
- let mut panes = ctx. panes. borrow_mut( ) ;
367
- panes. push( Rc :: new( RefCell :: new( window) ) ) ;
357
+ let new_buf = Rc :: new( RefCell :: new( Buffer :: new( name, rope) ) ) ;
358
+ let mut buf_list = ctx. buffers. borrow_mut( ) ;
359
+ buf_list. push( new_buf. clone( ) ) ;
360
+ let pane = ctx. focused_pane( ) ;
361
+ let mut pane = pane. borrow_mut( ) ;
362
+ pane. set_buffer( new_buf) ;
368
363
}
369
364
) ;
370
365
0 commit comments