mirror of https://github.com/helix-editor/helix
Remove a couple more unwraps
parent
19dccade7c
commit
23b5b1e25a
|
@ -1683,8 +1683,7 @@ fn search_next_or_prev_impl(cx: &mut Context, movement: Movement, direction: Dir
|
||||||
let scrolloff = config.scrolloff;
|
let scrolloff = config.scrolloff;
|
||||||
let (view, doc) = current!(cx.editor);
|
let (view, doc) = current!(cx.editor);
|
||||||
let registers = &cx.editor.registers;
|
let registers = &cx.editor.registers;
|
||||||
if let Some(query) = registers.read('/') {
|
if let Some(query) = registers.read('/').and_then(|query| query.last()) {
|
||||||
let query = query.last().unwrap();
|
|
||||||
let contents = doc.text().slice(..).to_string();
|
let contents = doc.text().slice(..).to_string();
|
||||||
let search_config = &config.search;
|
let search_config = &config.search;
|
||||||
let case_insensitive = if search_config.smart_case {
|
let case_insensitive = if search_config.smart_case {
|
||||||
|
@ -2124,7 +2123,11 @@ fn append_mode(cx: &mut Context) {
|
||||||
// Make sure there's room at the end of the document if the last
|
// Make sure there's room at the end of the document if the last
|
||||||
// selection butts up against it.
|
// selection butts up against it.
|
||||||
let end = text.len_chars();
|
let end = text.len_chars();
|
||||||
let last_range = doc.selection(view.id).iter().last().unwrap();
|
let last_range = doc
|
||||||
|
.selection(view.id)
|
||||||
|
.iter()
|
||||||
|
.last()
|
||||||
|
.expect("selection should always have at least one range");
|
||||||
if !last_range.is_empty() && last_range.head == end {
|
if !last_range.is_empty() && last_range.head == end {
|
||||||
let transaction = Transaction::change(
|
let transaction = Transaction::change(
|
||||||
doc.text(),
|
doc.text(),
|
||||||
|
|
|
@ -61,7 +61,14 @@ fn jump_to_location(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let _id = editor.open(&path, action).expect("editor.open failed");
|
match editor.open(&path, action) {
|
||||||
|
Ok(_) => (),
|
||||||
|
Err(err) => {
|
||||||
|
let err = format!("failed to open path: {:?}: {:?}", location.uri, err);
|
||||||
|
editor.set_error(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
let (view, doc) = current!(editor);
|
let (view, doc) = current!(editor);
|
||||||
let definition_pos = location.range.start;
|
let definition_pos = location.range.start;
|
||||||
// TODO: convert inside server
|
// TODO: convert inside server
|
||||||
|
@ -491,7 +498,7 @@ fn goto_impl(
|
||||||
locations: Vec<lsp::Location>,
|
locations: Vec<lsp::Location>,
|
||||||
offset_encoding: OffsetEncoding,
|
offset_encoding: OffsetEncoding,
|
||||||
) {
|
) {
|
||||||
let cwdir = std::env::current_dir().expect("couldn't determine current directory");
|
let cwdir = std::env::current_dir().unwrap_or_default();
|
||||||
|
|
||||||
match locations.as_slice() {
|
match locations.as_slice() {
|
||||||
[location] => {
|
[location] => {
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::ops::Deref;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use helix_view::editor::{Action, ConfigEvent};
|
use helix_view::editor::{Action, ConfigEvent};
|
||||||
|
@ -961,7 +963,7 @@ fn get_option(
|
||||||
let key = &args[0].to_lowercase();
|
let key = &args[0].to_lowercase();
|
||||||
let key_error = || anyhow::anyhow!("Unknown key `{}`", key);
|
let key_error = || anyhow::anyhow!("Unknown key `{}`", key);
|
||||||
|
|
||||||
let config = serde_json::to_value(&cx.editor.config().clone()).unwrap();
|
let config = serde_json::json!(cx.editor.config().deref());
|
||||||
let pointer = format!("/{}", key.replace('.', "/"));
|
let pointer = format!("/{}", key.replace('.', "/"));
|
||||||
let value = config.pointer(&pointer).ok_or_else(key_error)?;
|
let value = config.pointer(&pointer).ok_or_else(key_error)?;
|
||||||
|
|
||||||
|
@ -984,7 +986,7 @@ fn set_option(
|
||||||
let key_error = || anyhow::anyhow!("Unknown key `{}`", key);
|
let key_error = || anyhow::anyhow!("Unknown key `{}`", key);
|
||||||
let field_error = |_| anyhow::anyhow!("Could not parse field `{}`", arg);
|
let field_error = |_| anyhow::anyhow!("Could not parse field `{}`", arg);
|
||||||
|
|
||||||
let mut config = serde_json::to_value(&cx.editor.config().clone()).unwrap();
|
let mut config = serde_json::json!(&cx.editor.config().deref());
|
||||||
let pointer = format!("/{}", key.replace('.', "/"));
|
let pointer = format!("/{}", key.replace('.', "/"));
|
||||||
let value = config.pointer_mut(&pointer).ok_or_else(key_error)?;
|
let value = config.pointer_mut(&pointer).ok_or_else(key_error)?;
|
||||||
|
|
||||||
|
|
|
@ -263,8 +263,7 @@ pub mod completers {
|
||||||
|
|
||||||
pub fn setting(_editor: &Editor, input: &str) -> Vec<Completion> {
|
pub fn setting(_editor: &Editor, input: &str) -> Vec<Completion> {
|
||||||
static KEYS: Lazy<Vec<String>> = Lazy::new(|| {
|
static KEYS: Lazy<Vec<String>> = Lazy::new(|| {
|
||||||
serde_json::to_value(Config::default())
|
serde_json::json!(Config::default())
|
||||||
.unwrap()
|
|
||||||
.as_object()
|
.as_object()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.keys()
|
.keys()
|
||||||
|
|
|
@ -443,7 +443,7 @@ impl Prompt {
|
||||||
let input: Cow<str> = if self.line.is_empty() {
|
let input: Cow<str> = if self.line.is_empty() {
|
||||||
// latest value in the register list
|
// latest value in the register list
|
||||||
self.history_register
|
self.history_register
|
||||||
.and_then(|reg| cx.editor.registers.first(reg).cloned()) // TODO: can we avoid cloning?
|
.and_then(|reg| cx.editor.registers.first(reg))
|
||||||
.map(|entry| entry.into())
|
.map(|entry| entry.into())
|
||||||
.unwrap_or_else(|| Cow::from(""))
|
.unwrap_or_else(|| Cow::from(""))
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue