Remove Input action, detect ignored input in vim via an event

This commit is contained in:
Max Brunsfeld 2022-07-21 13:40:48 -07:00
parent beeaec8647
commit 2142fca673
5 changed files with 34 additions and 27 deletions

View file

@ -98,9 +98,6 @@ pub struct Jump {
anchor: language::Anchor,
}
#[derive(Clone, Deserialize, PartialEq)]
pub struct Input(pub String);
#[derive(Clone, Deserialize, PartialEq)]
pub struct SelectToBeginningOfLine {
#[serde(default)]
@ -214,7 +211,6 @@ actions!(
impl_actions!(
editor,
[
Input,
SelectNext,
SelectToBeginningOfLine,
SelectToEndOfLine,
@ -5772,6 +5768,7 @@ pub enum Event {
SelectionsChanged { local: bool },
ScrollPositionChanged { local: bool },
Closed,
IgnoredInput,
}
pub struct EditorFocused(pub ViewHandle<Editor>);
@ -5916,6 +5913,11 @@ impl View for Editor {
text: &str,
cx: &mut ViewContext<Self>,
) {
if !self.input_enabled {
cx.emit(Event::IgnoredInput);
return;
}
self.transact(cx, |this, cx| {
if let Some(range) = range_utf16.or_else(|| this.marked_text_range(cx)) {
this.change_selections(None, cx, |selections| {
@ -5934,6 +5936,11 @@ impl View for Editor {
new_selected_range_utf16: Option<Range<usize>>,
cx: &mut ViewContext<Self>,
) {
if !self.input_enabled {
cx.emit(Event::IgnoredInput);
return;
}
self.transact(cx, |this, cx| {
let range_to_replace = if let Some(mut marked_range) = this.marked_text_range(cx) {
if let Some(relative_range_utf16) = range_utf16.as_ref() {