first pass of merging in warp (doesn't build)
This commit is contained in:
+66
-8
@@ -1,5 +1,6 @@
|
||||
use galaxy_core::safe_info;
|
||||
use galaxyui::{keymap::Keystroke, Entity, ModelContext, ModelHandle, ViewContext};
|
||||
use galaxyui_core::keymap::Keystroke;
|
||||
use galaxyui_core::{Entity, ModelContext, ModelHandle, ViewContext};
|
||||
|
||||
use crate::register::{valid_register_name, BLACK_HOLE_REGISTER};
|
||||
|
||||
@@ -245,6 +246,8 @@ enum PendingAction {
|
||||
},
|
||||
/// the full "g" command
|
||||
G,
|
||||
/// the full "z" command (e.g. zz)
|
||||
Z,
|
||||
FindChar {
|
||||
direction: Direction,
|
||||
destination: FindCharDestination,
|
||||
@@ -269,6 +272,7 @@ impl From<char> for PendingAction {
|
||||
pending_operand: None,
|
||||
},
|
||||
'g' => Self::G,
|
||||
'z' => Self::Z,
|
||||
'f' => Self::FindChar {
|
||||
direction: Direction::Forward,
|
||||
destination: FindCharDestination::AtChar,
|
||||
@@ -586,6 +590,12 @@ pub enum VimEventType {
|
||||
GotoDefinition,
|
||||
FindReferences,
|
||||
ShowHover,
|
||||
/// Center the current line vertically in the viewport. Triggered by `zz`.
|
||||
CenterCursorVertically,
|
||||
/// Move cursor and scroll viewport down by half a page. Triggered by `<C-d>`.
|
||||
ScrollHalfPageDown,
|
||||
/// Move cursor and scroll viewport up by half a page. Triggered by `<C-u>`.
|
||||
ScrollHalfPageUp,
|
||||
}
|
||||
|
||||
impl VimEventType {
|
||||
@@ -643,7 +653,10 @@ impl VimEventType {
|
||||
| VimEventType::Escape
|
||||
| VimEventType::GotoDefinition
|
||||
| VimEventType::FindReferences
|
||||
| VimEventType::ShowHover => None,
|
||||
| VimEventType::ShowHover
|
||||
| VimEventType::CenterCursorVertically
|
||||
| VimEventType::ScrollHalfPageDown
|
||||
| VimEventType::ScrollHalfPageUp => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -699,7 +712,7 @@ impl VimFSA {
|
||||
pending_operand_count: None,
|
||||
pending_visual_object: None,
|
||||
last_find_motion: None,
|
||||
// When doing an operation that reads/writes to a register, the default (unnamed) regsiter
|
||||
// When doing an operation that reads/writes to a register, the default (unnamed) register
|
||||
// is called ".
|
||||
register: '"',
|
||||
dot_repeat_event: None,
|
||||
@@ -795,6 +808,28 @@ impl VimFSA {
|
||||
VimMode::Normal | VimMode::Visual(_) => self.typed_character('x')?,
|
||||
VimMode::Replace => self.change_mode(VimMode::Normal.into()).into(),
|
||||
},
|
||||
"ctrl-d" => match self.mode {
|
||||
VimMode::Normal | VimMode::Visual(_) => {
|
||||
let count = self.get_action_count().unwrap_or(1);
|
||||
self.clear();
|
||||
VimEvent {
|
||||
event_type: VimEventType::ScrollHalfPageDown,
|
||||
count,
|
||||
}
|
||||
}
|
||||
_ => return None,
|
||||
},
|
||||
"ctrl-u" => match self.mode {
|
||||
VimMode::Normal | VimMode::Visual(_) => {
|
||||
let count = self.get_action_count().unwrap_or(1);
|
||||
self.clear();
|
||||
VimEvent {
|
||||
event_type: VimEventType::ScrollHalfPageUp,
|
||||
count,
|
||||
}
|
||||
}
|
||||
_ => return None,
|
||||
},
|
||||
_ => return None,
|
||||
};
|
||||
Some(event)
|
||||
@@ -824,7 +859,7 @@ impl VimFSA {
|
||||
}
|
||||
}
|
||||
|
||||
/// Exiting insert mode is simple when it had been entered without a count, you just chenge the
|
||||
/// Exiting insert mode is simple when it had been entered without a count, you just change the
|
||||
/// mode. However, if there was a count, we need to repeat the text that was entered n - 1
|
||||
/// times.
|
||||
fn exit_insert_mode(&mut self) -> VimEvent {
|
||||
@@ -917,7 +952,7 @@ impl VimFSA {
|
||||
},
|
||||
),
|
||||
'r' => self.change_mode(VimMode::Replace.into()),
|
||||
'g' | 'd' | 'c' | 'y' | 'f' | 'F' | 't' | 'T' | '[' | ']' | '"' => {
|
||||
'g' | 'd' | 'c' | 'y' | 'z' | 'f' | 'F' | 't' | 'T' | '[' | ']' | '"' => {
|
||||
self.pending_action = Some(PendingAction::from(c));
|
||||
return None;
|
||||
}
|
||||
@@ -1025,6 +1060,13 @@ impl VimFSA {
|
||||
action: PendingAction,
|
||||
) -> Option<VimEventType> {
|
||||
let event = match action {
|
||||
PendingAction::Z => match c {
|
||||
'z' => VimEventType::CenterCursorVertically,
|
||||
_ => {
|
||||
self.clear();
|
||||
return None;
|
||||
}
|
||||
},
|
||||
PendingAction::G => match c {
|
||||
'e' | 'E' => VimEventType::Navigate(VimMotion::Word(WordMotion {
|
||||
direction: Direction::Backward,
|
||||
@@ -1467,7 +1509,7 @@ impl VimFSA {
|
||||
write_register_name,
|
||||
}
|
||||
}
|
||||
'g' | 'f' | 'F' | 't' | 'T' | '[' | ']' | '"' => {
|
||||
'g' | 'z' | 'f' | 'F' | 't' | 'T' | '[' | ']' | '"' => {
|
||||
self.pending_action = Some(PendingAction::from(c));
|
||||
return None;
|
||||
}
|
||||
@@ -1502,6 +1544,13 @@ impl VimFSA {
|
||||
pending_action: PendingAction,
|
||||
) -> Option<VimEventType> {
|
||||
let event_type = match pending_action {
|
||||
PendingAction::Z => match c {
|
||||
'z' => VimEventType::CenterCursorVertically,
|
||||
_ => {
|
||||
self.clear();
|
||||
return None;
|
||||
}
|
||||
},
|
||||
PendingAction::G => match c {
|
||||
'e' | 'E' => VimEventType::Navigate(VimMotion::Word(WordMotion {
|
||||
direction: Direction::Backward,
|
||||
@@ -1744,7 +1793,7 @@ pub struct VimState<'a> {
|
||||
pub showcmd: &'a str,
|
||||
}
|
||||
|
||||
/// This struct is a wrapper around the VimFSA that turns it into a galaxyui::Entity. We want to keep
|
||||
/// This struct is a wrapper around the VimFSA that turns it into a galaxyui_core::Entity. We want to keep
|
||||
/// the VimFSA independent of our UI framework, so anything involving galaxyui should live here
|
||||
/// instead.
|
||||
#[derive(Default)]
|
||||
@@ -1768,7 +1817,7 @@ impl VimModel {
|
||||
}
|
||||
|
||||
pub fn keypress(&mut self, keystroke: &Keystroke, ctx: &mut ModelContext<Self>) {
|
||||
if let Some(event) = self.fsa.keypress(keystroke.key.as_str()) {
|
||||
if let Some(event) = self.fsa.keypress(keystroke.normalized().as_str()) {
|
||||
ctx.emit(event);
|
||||
}
|
||||
}
|
||||
@@ -1885,6 +1934,9 @@ where
|
||||
VimEventType::GotoDefinition => self.goto_definition(ctx),
|
||||
VimEventType::FindReferences => self.find_references(ctx),
|
||||
VimEventType::ShowHover => self.show_hover(ctx),
|
||||
VimEventType::CenterCursorVertically => self.center_cursor_vertically(ctx),
|
||||
VimEventType::ScrollHalfPageDown => self.scroll_half_page_down(event.count, ctx),
|
||||
VimEventType::ScrollHalfPageUp => self.scroll_half_page_up(event.count, ctx),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -2003,4 +2055,10 @@ pub trait VimHandler {
|
||||
fn find_references(&mut self, _ctx: &mut ViewContext<Self>) {}
|
||||
/// Show hover information for the symbol under cursor (gh).
|
||||
fn show_hover(&mut self, _ctx: &mut ViewContext<Self>) {}
|
||||
/// Center the current line vertically in the viewport (zz).
|
||||
fn center_cursor_vertically(&mut self, _ctx: &mut ViewContext<Self>) {}
|
||||
/// Move the cursor down `count` half-pages and scroll the viewport (`<C-d>`).
|
||||
fn scroll_half_page_down(&mut self, _count: u32, _ctx: &mut ViewContext<Self>) {}
|
||||
/// Move the cursor up `count` half-pages and scroll the viewport (`<C-u>`).
|
||||
fn scroll_half_page_up(&mut self, _count: u32, _ctx: &mut ViewContext<Self>) {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user