mirror of https://github.com/helix-editor/helix
Move ui, keymap & commands to helix-view
parent
11b8f068da
commit
1aa2b027d7
@ -1,127 +0,0 @@
|
||||
#[macro_export]
|
||||
macro_rules! key {
|
||||
($key:ident) => {
|
||||
::helix_view::input::KeyEvent {
|
||||
code: ::helix_view::keyboard::KeyCode::$key,
|
||||
modifiers: ::helix_view::keyboard::KeyModifiers::NONE,
|
||||
}
|
||||
};
|
||||
($($ch:tt)*) => {
|
||||
::helix_view::input::KeyEvent {
|
||||
code: ::helix_view::keyboard::KeyCode::Char($($ch)*),
|
||||
modifiers: ::helix_view::keyboard::KeyModifiers::NONE,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! shift {
|
||||
($key:ident) => {
|
||||
::helix_view::input::KeyEvent {
|
||||
code: ::helix_view::keyboard::KeyCode::$key,
|
||||
modifiers: ::helix_view::keyboard::KeyModifiers::SHIFT,
|
||||
}
|
||||
};
|
||||
($($ch:tt)*) => {
|
||||
::helix_view::input::KeyEvent {
|
||||
code: ::helix_view::keyboard::KeyCode::Char($($ch)*),
|
||||
modifiers: ::helix_view::keyboard::KeyModifiers::SHIFT,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! ctrl {
|
||||
($key:ident) => {
|
||||
::helix_view::input::KeyEvent {
|
||||
code: ::helix_view::keyboard::KeyCode::$key,
|
||||
modifiers: ::helix_view::keyboard::KeyModifiers::CONTROL,
|
||||
}
|
||||
};
|
||||
($($ch:tt)*) => {
|
||||
::helix_view::input::KeyEvent {
|
||||
code: ::helix_view::keyboard::KeyCode::Char($($ch)*),
|
||||
modifiers: ::helix_view::keyboard::KeyModifiers::CONTROL,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! alt {
|
||||
($key:ident) => {
|
||||
::helix_view::input::KeyEvent {
|
||||
code: ::helix_view::keyboard::KeyCode::$key,
|
||||
modifiers: ::helix_view::keyboard::KeyModifiers::ALT,
|
||||
}
|
||||
};
|
||||
($($ch:tt)*) => {
|
||||
::helix_view::input::KeyEvent {
|
||||
code: ::helix_view::keyboard::KeyCode::Char($($ch)*),
|
||||
modifiers: ::helix_view::keyboard::KeyModifiers::ALT,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// Macro for defining the root of a `Keymap` object. Example:
|
||||
///
|
||||
/// ```
|
||||
/// # use helix_core::hashmap;
|
||||
/// # use helix_term::keymap;
|
||||
/// # use helix_term::keymap::Keymap;
|
||||
/// let normal_mode = keymap!({ "Normal mode"
|
||||
/// "i" => insert_mode,
|
||||
/// "g" => { "Goto"
|
||||
/// "g" => goto_file_start,
|
||||
/// "e" => goto_file_end,
|
||||
/// },
|
||||
/// "j" | "down" => move_line_down,
|
||||
/// });
|
||||
/// let keymap = Keymap::new(normal_mode);
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! keymap {
|
||||
(@trie $cmd:ident) => {
|
||||
$crate::keymap::KeyTrie::Leaf($crate::commands::MappableCommand::$cmd)
|
||||
};
|
||||
|
||||
(@trie
|
||||
{ $label:literal $(sticky=$sticky:literal)? $($($key:literal)|+ => $value:tt,)+ }
|
||||
) => {
|
||||
keymap!({ $label $(sticky=$sticky)? $($($key)|+ => $value,)+ })
|
||||
};
|
||||
|
||||
(@trie [$($cmd:ident),* $(,)?]) => {
|
||||
$crate::keymap::KeyTrie::Sequence(vec![$($crate::commands::Command::$cmd),*])
|
||||
};
|
||||
|
||||
(
|
||||
{ $label:literal $(sticky=$sticky:literal)? $($($key:literal)|+ => $value:tt,)+ }
|
||||
) => {
|
||||
// modified from the hashmap! macro
|
||||
{
|
||||
let _cap = hashmap!(@count $($($key),+),*);
|
||||
let mut _map = ::std::collections::HashMap::with_capacity(_cap);
|
||||
let mut _order = ::std::vec::Vec::with_capacity(_cap);
|
||||
$(
|
||||
$(
|
||||
let _key = $key.parse::<::helix_view::input::KeyEvent>().unwrap();
|
||||
let _duplicate = _map.insert(
|
||||
_key,
|
||||
keymap!(@trie $value)
|
||||
);
|
||||
assert!(_duplicate.is_none(), "Duplicate key found: {:?}", _duplicate.unwrap());
|
||||
_order.push(_key);
|
||||
)+
|
||||
)*
|
||||
let mut _node = $crate::keymap::KeyTrieNode::new($label, _map, _order);
|
||||
$( _node.is_sticky = $sticky; )?
|
||||
$crate::keymap::KeyTrie::Node(_node)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub use alt;
|
||||
pub use ctrl;
|
||||
pub use key;
|
||||
pub use keymap;
|
||||
pub use shift;
|
@ -0,0 +1,36 @@
|
||||
use helix_core::Position;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
/// Parse arg into [`PathBuf`] and position.
|
||||
pub fn parse_file(s: &str) -> (PathBuf, Position) {
|
||||
let def = || (PathBuf::from(s), Position::default());
|
||||
if Path::new(s).exists() {
|
||||
return def();
|
||||
}
|
||||
split_path_row_col(s)
|
||||
.or_else(|| split_path_row(s))
|
||||
.unwrap_or_else(def)
|
||||
}
|
||||
|
||||
/// Split file.rs:10:2 into [`PathBuf`], row and col.
|
||||
///
|
||||
/// Does not validate if file.rs is a file or directory.
|
||||
fn split_path_row_col(s: &str) -> Option<(PathBuf, Position)> {
|
||||
let mut s = s.rsplitn(3, ':');
|
||||
let col: usize = s.next()?.parse().ok()?;
|
||||
let row: usize = s.next()?.parse().ok()?;
|
||||
let path = s.next()?.into();
|
||||
let pos = Position::new(row.saturating_sub(1), col.saturating_sub(1));
|
||||
Some((path, pos))
|
||||
}
|
||||
|
||||
/// Split file.rs:10 into [`PathBuf`] and row.
|
||||
///
|
||||
/// Does not validate if file.rs is a file or directory.
|
||||
fn split_path_row(s: &str) -> Option<(PathBuf, Position)> {
|
||||
let (path, row) = s.rsplit_once(':')?;
|
||||
let row: usize = row.parse().ok()?;
|
||||
let path = path.into();
|
||||
let pos = Position::new(row.saturating_sub(1), 0);
|
||||
Some((path, pos))
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
use super::*;
|
||||
|
||||
use helix_view::editor::{Action, ConfigEvent};
|
||||
use crate::editor::{Action, ConfigEvent};
|
||||
use ui::completers::{self, Completer};
|
||||
|
||||
#[derive(Clone)]
|
@ -0,0 +1,60 @@
|
||||
/// Macro for defining the root of a `Keymap` object. Example:
|
||||
///
|
||||
/// ```
|
||||
/// # use helix_core::hashmap;
|
||||
/// # use helix_term::keymap;
|
||||
/// # use helix_term::keymap::Keymap;
|
||||
/// let normal_mode = keymap!({ "Normal mode"
|
||||
/// "i" => insert_mode,
|
||||
/// "g" => { "Goto"
|
||||
/// "g" => goto_file_start,
|
||||
/// "e" => goto_file_end,
|
||||
/// },
|
||||
/// "j" | "down" => move_line_down,
|
||||
/// });
|
||||
/// let keymap = Keymap::new(normal_mode);
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! keymap {
|
||||
(@trie $cmd:ident) => {
|
||||
$crate::keymap::KeyTrie::Leaf($crate::commands::MappableCommand::$cmd)
|
||||
};
|
||||
|
||||
(@trie
|
||||
{ $label:literal $(sticky=$sticky:literal)? $($($key:literal)|+ => $value:tt,)+ }
|
||||
) => {
|
||||
keymap!({ $label $(sticky=$sticky)? $($($key)|+ => $value,)+ })
|
||||
};
|
||||
|
||||
(@trie [$($cmd:ident),* $(,)?]) => {
|
||||
$crate::keymap::KeyTrie::Sequence(vec![$($crate::commands::Command::$cmd),*])
|
||||
};
|
||||
|
||||
(
|
||||
{ $label:literal $(sticky=$sticky:literal)? $($($key:literal)|+ => $value:tt,)+ }
|
||||
) => {
|
||||
// modified from the hashmap! macro
|
||||
{
|
||||
let _cap = hashmap!(@count $($($key),+),*);
|
||||
let mut _map = ::std::collections::HashMap::with_capacity(_cap);
|
||||
let mut _order = ::std::vec::Vec::with_capacity(_cap);
|
||||
$(
|
||||
$(
|
||||
let _key = $key.parse::<$crate::input::KeyEvent>().unwrap();
|
||||
let _duplicate = _map.insert(
|
||||
_key,
|
||||
keymap!(@trie $value)
|
||||
);
|
||||
assert!(_duplicate.is_none(), "Duplicate key found: {:?}", _duplicate.unwrap());
|
||||
_order.push(_key);
|
||||
)+
|
||||
)*
|
||||
let mut _node = $crate::keymap::KeyTrieNode::new($label, _map, _order);
|
||||
$( _node.is_sticky = $sticky; )?
|
||||
$crate::keymap::KeyTrie::Node(_node)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub use crate::{alt, ctrl, key, shift};
|
||||
pub use keymap;
|
@ -1,10 +1,10 @@
|
||||
use helix_view::compositor::{Component, Context, Event, EventResult, RenderContext};
|
||||
use helix_view::editor::CompleteAction;
|
||||
use crate::compositor::{Component, Context, Event, EventResult, RenderContext};
|
||||
use crate::editor::CompleteAction;
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
||||
use helix_core::{Change, Transaction};
|
||||
use helix_view::{
|
||||
use crate::{
|
||||
graphics::Rect,
|
||||
input::{KeyCode, KeyEvent},
|
||||
Document, Editor,
|
@ -1,10 +1,10 @@
|
||||
use helix_core::Position;
|
||||
use helix_view::{
|
||||
use crate::{
|
||||
graphics::{CursorKind, Rect},
|
||||
Editor,
|
||||
};
|
||||
|
||||
use helix_view::compositor::{Component, Context, Event, EventResult, RenderContext};
|
||||
use crate::compositor::{Component, Context, Event, EventResult, RenderContext};
|
||||
|
||||
/// Contains a component placed in the center of the parent component
|
||||
pub struct Overlay<T> {
|
@ -1,8 +1,8 @@
|
||||
use crate::{ctrl, key};
|
||||
use helix_view::compositor::{Callback, Component, Context, Event, EventResult, RenderContext};
|
||||
use crate::compositor::{Callback, Component, Context, Event, EventResult, RenderContext};
|
||||
|
||||
use helix_core::Position;
|
||||
use helix_view::{
|
||||
use crate::{
|
||||
graphics::{Margin, Rect},
|
||||
Editor,
|
||||
};
|
@ -1,17 +1,17 @@
|
||||
use helix_view::compositor::{Component, Compositor, Context, Event, EventResult, RenderContext};
|
||||
use crate::compositor::{Component, Compositor, Context, Event, EventResult, RenderContext};
|
||||
use crate::input::KeyEvent;
|
||||
use crate::keyboard::KeyCode;
|
||||
use crate::{alt, ctrl, key, shift, ui};
|
||||
use helix_view::input::KeyEvent;
|
||||
use helix_view::keyboard::KeyCode;
|
||||
use std::{borrow::Cow, ops::RangeFrom};
|
||||
use tui::widgets::{Block, Borders, Widget};
|
||||
|
||||
use helix_core::{
|
||||
unicode::segmentation::GraphemeCursor, unicode::width::UnicodeWidthStr, Position,
|
||||
};
|
||||
use helix_view::{
|
||||
use crate::{
|
||||
graphics::{CursorKind, Margin, Rect},
|
||||
Editor,
|
||||
};
|
||||
use helix_core::{
|
||||
unicode::segmentation::GraphemeCursor, unicode::width::UnicodeWidthStr, Position,
|
||||
};
|
||||
|
||||
pub type Completion = (RangeFrom<usize>, Cow<'static, str>);
|
||||
|
@ -1,6 +1,5 @@
|
||||
use helix_view::compositor::{Component, RenderContext};
|
||||
|
||||
use helix_view::graphics::Rect;
|
||||
use crate::compositor::{Component, RenderContext};
|
||||
use crate::graphics::Rect;
|
||||
|
||||
pub struct Text {
|
||||
pub(crate) contents: tui::text::Text<'static>,
|
Loading…
Reference in New Issue