@ -1,6 +1,8 @@
use crate ::compositor ::{ Component , Compositor , Context , EventResult } ;
use crate ::compositor ::{ Component , Compositor , Context , EventResult } ;
use crate ::ui ;
use crate ::{ alt , ctrl , key , ui } ;
use crossterm ::event ::{ Event , KeyCode , KeyEvent , KeyModifiers } ;
use crossterm ::event ::Event ;
use helix_view ::input ::KeyEvent ;
use helix_view ::keyboard ::{ KeyCode , KeyModifiers } ;
use std ::{ borrow ::Cow , ops ::RangeFrom } ;
use std ::{ borrow ::Cow , ops ::RangeFrom } ;
use tui ::buffer ::Buffer as Surface ;
use tui ::buffer ::Buffer as Surface ;
@ -421,103 +423,29 @@ impl Component for Prompt {
compositor . pop ( ) ;
compositor . pop ( ) ;
} ) ) ) ;
} ) ) ) ;
match event {
match event . into ( ) {
KeyEvent {
ctrl ! ( 'c' ) | key ! ( Esc ) = > {
code : KeyCode ::Char ( 'c' ) ,
modifiers : KeyModifiers ::CONTROL ,
}
| KeyEvent {
code : KeyCode ::Esc , ..
} = > {
( self . callback_fn ) ( cx , & self . line , PromptEvent ::Abort ) ;
( self . callback_fn ) ( cx , & self . line , PromptEvent ::Abort ) ;
return close_fn ;
return close_fn ;
}
}
KeyEvent {
alt ! ( 'b' ) | alt ! ( Left ) = > self . move_cursor ( Movement ::BackwardWord ( 1 ) ) ,
code : KeyCode ::Left ,
alt ! ( 'f' ) | alt ! ( Right ) = > self . move_cursor ( Movement ::ForwardWord ( 1 ) ) ,
modifiers : KeyModifiers ::ALT ,
ctrl ! ( 'b' ) | ctrl ! ( Left ) = > self . move_cursor ( Movement ::BackwardChar ( 1 ) ) ,
}
ctrl ! ( 'f' ) | ctrl ! ( Right ) = > self . move_cursor ( Movement ::ForwardChar ( 1 ) ) ,
| KeyEvent {
ctrl ! ( 'e' ) | key ! ( End ) = > self . move_end ( ) ,
code : KeyCode ::Char ( 'b' ) ,
ctrl ! ( 'a' ) | key ! ( Home ) = > self . move_start ( ) ,
modifiers : KeyModifiers ::ALT ,
ctrl ! ( 'w' ) = > self . delete_word_backwards ( ) ,
} = > self . move_cursor ( Movement ::BackwardWord ( 1 ) ) ,
ctrl ! ( 'k' ) = > self . kill_to_end_of_line ( ) ,
KeyEvent {
ctrl ! ( 'u' ) = > self . kill_to_start_of_line ( ) ,
code : KeyCode ::Right ,
ctrl ! ( 'h' ) | key ! ( Backspace ) = > {
modifiers : KeyModifiers ::ALT ,
}
| KeyEvent {
code : KeyCode ::Char ( 'f' ) ,
modifiers : KeyModifiers ::ALT ,
} = > self . move_cursor ( Movement ::ForwardWord ( 1 ) ) ,
KeyEvent {
code : KeyCode ::Char ( 'f' ) ,
modifiers : KeyModifiers ::CONTROL ,
}
| KeyEvent {
code : KeyCode ::Right ,
..
} = > self . move_cursor ( Movement ::ForwardChar ( 1 ) ) ,
KeyEvent {
code : KeyCode ::Char ( 'b' ) ,
modifiers : KeyModifiers ::CONTROL ,
}
| KeyEvent {
code : KeyCode ::Left ,
..
} = > self . move_cursor ( Movement ::BackwardChar ( 1 ) ) ,
KeyEvent {
code : KeyCode ::End ,
modifiers : KeyModifiers ::NONE ,
}
| KeyEvent {
code : KeyCode ::Char ( 'e' ) ,
modifiers : KeyModifiers ::CONTROL ,
} = > self . move_end ( ) ,
KeyEvent {
code : KeyCode ::Home ,
modifiers : KeyModifiers ::NONE ,
}
| KeyEvent {
code : KeyCode ::Char ( 'a' ) ,
modifiers : KeyModifiers ::CONTROL ,
} = > self . move_start ( ) ,
KeyEvent {
code : KeyCode ::Char ( 'w' ) ,
modifiers : KeyModifiers ::CONTROL ,
} = > self . delete_word_backwards ( ) ,
KeyEvent {
code : KeyCode ::Char ( 'k' ) ,
modifiers : KeyModifiers ::CONTROL ,
} = > self . kill_to_end_of_line ( ) ,
KeyEvent {
code : KeyCode ::Char ( 'u' ) ,
modifiers : KeyModifiers ::CONTROL ,
} = > self . kill_to_start_of_line ( ) ,
KeyEvent {
code : KeyCode ::Char ( 'h' ) ,
modifiers : KeyModifiers ::CONTROL ,
}
| KeyEvent {
code : KeyCode ::Backspace ,
modifiers : KeyModifiers ::NONE ,
} = > {
self . delete_char_backwards ( ) ;
self . delete_char_backwards ( ) ;
( self . callback_fn ) ( cx , & self . line , PromptEvent ::Update ) ;
( self . callback_fn ) ( cx , & self . line , PromptEvent ::Update ) ;
}
}
KeyEvent {
ctrl ! ( 'd' ) | key ! ( Delete ) = > {
code : KeyCode ::Char ( 'd' ) ,
modifiers : KeyModifiers ::CONTROL ,
}
| KeyEvent {
code : KeyCode ::Delete ,
modifiers : KeyModifiers ::NONE ,
} = > {
self . delete_char_forwards ( ) ;
self . delete_char_forwards ( ) ;
( self . callback_fn ) ( cx , & self . line , PromptEvent ::Update ) ;
( self . callback_fn ) ( cx , & self . line , PromptEvent ::Update ) ;
}
}
KeyEvent {
ctrl ! ( 's' ) = > {
code : KeyCode ::Char ( 's' ) ,
modifiers : KeyModifiers ::CONTROL ,
} = > {
let ( view , doc ) = current ! ( cx . editor ) ;
let ( view , doc ) = current ! ( cx . editor ) ;
let text = doc . text ( ) . slice ( .. ) ;
let text = doc . text ( ) . slice ( .. ) ;
@ -535,10 +463,7 @@ impl Component for Prompt {
( self . callback_fn ) ( cx , & self . line , PromptEvent ::Update ) ;
( self . callback_fn ) ( cx , & self . line , PromptEvent ::Update ) ;
}
}
}
}
KeyEvent {
key ! ( Enter ) = > {
code : KeyCode ::Enter ,
..
} = > {
if self . selection . is_some ( ) & & self . line . ends_with ( '/' ) {
if self . selection . is_some ( ) & & self . line . ends_with ( '/' ) {
self . completion = ( self . completion_fn ) ( & self . line ) ;
self . completion = ( self . completion_fn ) ( & self . line ) ;
self . exit_selection ( ) ;
self . exit_selection ( ) ;
@ -553,50 +478,29 @@ impl Component for Prompt {
return close_fn ;
return close_fn ;
}
}
}
}
KeyEvent {
ctrl ! ( 'p' ) | key ! ( Up ) = > {
code : KeyCode ::Char ( 'p' ) ,
modifiers : KeyModifiers ::CONTROL ,
}
| KeyEvent {
code : KeyCode ::Up , ..
} = > {
if let Some ( register ) = self . history_register {
if let Some ( register ) = self . history_register {
let register = cx . editor . registers . get_mut ( register ) ;
let register = cx . editor . registers . get_mut ( register ) ;
self . change_history ( register . read ( ) , CompletionDirection ::Backward ) ;
self . change_history ( register . read ( ) , CompletionDirection ::Backward ) ;
( self . callback_fn ) ( cx , & self . line , PromptEvent ::Update ) ;
( self . callback_fn ) ( cx , & self . line , PromptEvent ::Update ) ;
}
}
}
}
KeyEvent {
ctrl ! ( 'n' ) | key ! ( Down ) = > {
code : KeyCode ::Char ( 'n' ) ,
modifiers : KeyModifiers ::CONTROL ,
}
| KeyEvent {
code : KeyCode ::Down ,
..
} = > {
if let Some ( register ) = self . history_register {
if let Some ( register ) = self . history_register {
let register = cx . editor . registers . get_mut ( register ) ;
let register = cx . editor . registers . get_mut ( register ) ;
self . change_history ( register . read ( ) , CompletionDirection ::Forward ) ;
self . change_history ( register . read ( ) , CompletionDirection ::Forward ) ;
( self . callback_fn ) ( cx , & self . line , PromptEvent ::Update ) ;
( self . callback_fn ) ( cx , & self . line , PromptEvent ::Update ) ;
}
}
}
}
KeyEvent {
key ! ( Tab ) = > {
code : KeyCode ::Tab , ..
} = > {
self . change_completion_selection ( CompletionDirection ::Forward ) ;
self . change_completion_selection ( CompletionDirection ::Forward ) ;
( self . callback_fn ) ( cx , & self . line , PromptEvent ::Update )
( self . callback_fn ) ( cx , & self . line , PromptEvent ::Update )
}
}
KeyEvent {
key ! ( BackTab ) = > {
code : KeyCode ::BackTab ,
..
} = > {
self . change_completion_selection ( CompletionDirection ::Backward ) ;
self . change_completion_selection ( CompletionDirection ::Backward ) ;
( self . callback_fn ) ( cx , & self . line , PromptEvent ::Update )
( self . callback_fn ) ( cx , & self . line , PromptEvent ::Update )
}
}
KeyEvent {
ctrl ! ( 'q' ) = > self . exit_selection ( ) ,
code : KeyCode ::Char ( 'q' ) ,
modifiers : KeyModifiers ::CONTROL ,
} = > self . exit_selection ( ) ,
// any char event that's not combined with control or mapped to any other combo
// any char event that's not combined with control or mapped to any other combo
KeyEvent {
KeyEvent {
code : KeyCode ::Char ( c ) ,
code : KeyCode ::Char ( c ) ,