diff options
author | Dmitry Sharshakov | 2021-08-28 11:59:26 +0000 |
---|---|---|
committer | Dmitry Sharshakov | 2021-08-28 11:59:26 +0000 |
commit | e3153946311b189bd5e10e816acbdda508ded31c (patch) | |
tree | 304e0b8c0b869cc239d8c0ce9b0f328fe589bd93 /helix-view/src | |
parent | 8df6739759396b45d06356dd78c39117590b062b (diff) | |
parent | d6a9c2c0f6f4af98146b52d1c886a1ca99d15676 (diff) |
Merge remote-tracking branch 'origin/master' into debug
Diffstat (limited to 'helix-view/src')
-rw-r--r-- | helix-view/src/document.rs | 17 | ||||
-rw-r--r-- | helix-view/src/input.rs | 4 |
2 files changed, 7 insertions, 14 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index a238644a..e890a336 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -102,7 +102,7 @@ pub struct Document { language_server: Option<Arc<helix_lsp::Client>>, } -use std::fmt; +use std::{fmt, mem}; impl fmt::Debug for Document { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Document") @@ -301,20 +301,13 @@ pub async fn to_writer<'a, W: tokio::io::AsyncWriteExt + Unpin + ?Sized>( Ok(()) } -/// Like std::mem::replace() except it allows the replacement value to be mapped from the -/// original value. -fn take_with<T, F>(mut_ref: &mut T, closure: F) +fn take_with<T, F>(mut_ref: &mut T, f: F) where + T: Default, F: FnOnce(T) -> T, { - use std::{panic, ptr}; - - unsafe { - let old_t = ptr::read(mut_ref); - let new_t = panic::catch_unwind(panic::AssertUnwindSafe(|| closure(old_t))) - .unwrap_or_else(|_| ::std::process::abort()); - ptr::write(mut_ref, new_t); - } + let t = mem::take(mut_ref); + let _ = mem::replace(mut_ref, f(t)); } use helix_lsp::lsp; diff --git a/helix-view/src/input.rs b/helix-view/src/input.rs index 28b204bb..1e0ddfe2 100644 --- a/helix-view/src/input.rs +++ b/helix-view/src/input.rs @@ -15,10 +15,10 @@ pub struct KeyEvent { } impl KeyEvent { - /// If a character was pressed (without modifiers), return it. + /// If a character was pressed, return it. pub fn char(&self) -> Option<char> { match self.code { - KeyCode::Char(ch) if self.modifiers.is_empty() => Some(ch), + KeyCode::Char(ch) => Some(ch), _ => None, } } |