diff options
Diffstat (limited to 'helix-term')
-rw-r--r-- | helix-term/src/commands.rs | 11 | ||||
-rw-r--r-- | helix-term/src/keymap.rs | 2 | ||||
-rw-r--r-- | helix-term/src/main.rs | 34 |
3 files changed, 28 insertions, 19 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 3dba9333..7b30168a 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -473,10 +473,10 @@ fn scroll(cx: &mut Context, offset: usize, direction: Direction) { let last_line = view.last_line(doc); // clamp into viewport - let line = cursor.row.clamp( - view.first_line + scrolloff, - last_line.saturating_sub(scrolloff), - ); + let line = cursor + .row + .min(view.first_line + scrolloff) + .max(last_line.saturating_sub(scrolloff)); let text = doc.text().slice(..); let pos = pos_at_coords(text, Position::new(line, cursor.col)); // this func will properly truncate to line end @@ -1031,6 +1031,9 @@ pub fn command_mode(cx: &mut Context) { } let parts = input.split_ascii_whitespace().collect::<Vec<&str>>(); + if parts.is_empty() { + return; + } if let Some(cmd) = cmd::COMMANDS.get(parts[0]) { (cmd.fun)(editor, &parts[1..], event); diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs index 044d97eb..fc7bb86e 100644 --- a/helix-term/src/keymap.rs +++ b/helix-term/src/keymap.rs @@ -240,10 +240,12 @@ pub fn default() -> Keymaps { code: KeyCode::PageUp, modifiers: KeyModifiers::NONE } => commands::page_up, + ctrl!('b') => commands::page_up, KeyEvent { code: KeyCode::PageDown, modifiers: KeyModifiers::NONE } => commands::page_down, + ctrl!('f') => commands::page_down, ctrl!('u') => commands::half_page_up, ctrl!('d') => commands::half_page_down, diff --git a/helix-term/src/main.rs b/helix-term/src/main.rs index ac060bbe..3a0f4d20 100644 --- a/helix-term/src/main.rs +++ b/helix-term/src/main.rs @@ -8,11 +8,13 @@ mod ui; use application::Application; +use helix_core::config_dir; + use std::path::PathBuf; -use anyhow::Error; +use anyhow::{Context, Result}; -fn setup_logging(verbosity: u64) -> Result<(), fern::InitError> { +fn setup_logging(verbosity: u64) -> Result<()> { let mut base_config = fern::Dispatch::new(); // Let's say we depend on something which whose "info" level messages are too @@ -27,8 +29,6 @@ fn setup_logging(verbosity: u64) -> Result<(), fern::InitError> { _3_or_more => base_config.level(log::LevelFilter::Trace), }; - let home = dirs_next::home_dir().expect("can't find the home directory"); - // Separate file config so we can include year, month and day in file logs let file_config = fern::Dispatch::new() .format(|out, message, record| { @@ -40,7 +40,7 @@ fn setup_logging(verbosity: u64) -> Result<(), fern::InitError> { message )) }) - .chain(fern::log_file(home.join("helix.log"))?); + .chain(fern::log_file(config_dir().join("helix.log"))?); base_config.chain(file_config).apply()?; @@ -51,7 +51,7 @@ pub struct Args { files: Vec<PathBuf>, } -fn main() { +fn main() -> Result<()> { let help = format!( "\ {} {} @@ -89,14 +89,19 @@ FLAGS: verbosity = 1; } - setup_logging(verbosity).expect("failed to initialize logging."); + let conf_dir = config_dir(); + + if !conf_dir.exists() { + std::fs::create_dir(&conf_dir); + } + + setup_logging(verbosity).context("failed to initialize logging")?; let args = Args { files: pargs.finish().into_iter().map(|arg| arg.into()).collect(), }; // initialize language registry - use helix_core::config_dir; use helix_core::syntax::{Loader, LOADER}; // load $HOME/.config/helix/languages.toml, fallback to default config @@ -105,17 +110,16 @@ FLAGS: .as_deref() .unwrap_or(include_bytes!("../../languages.toml")); - LOADER.get_or_init(|| { - let config = toml::from_slice(toml).expect("Could not parse languages.toml"); - Loader::new(config) - }); + let config = toml::from_slice(toml).context("Could not parse languages.toml")?; + LOADER.get_or_init(|| Loader::new(config)); - let runtime = tokio::runtime::Runtime::new().unwrap(); + let runtime = tokio::runtime::Runtime::new().context("unable to start tokio runtime")?; // TODO: use the thread local executor to spawn the application task separately from the work pool + let mut app = Application::new(args).context("unable to create new appliction")?; runtime.block_on(async move { - let mut app = Application::new(args).unwrap(); - app.run().await; }); + + Ok(()) } |