Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
399 changes: 395 additions & 4 deletions crates/base/src/input/base/element.rs

Large diffs are not rendered by default.

43 changes: 40 additions & 3 deletions crates/base/src/input/base/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@
//! reachable.

use std::cell::RefCell;
use std::collections::HashMap;
use std::rc::Rc;

use gpui::{Div, Entity, Stateful, Window};
use gpui::{Bounds, Div, Entity, Pixels, SharedString, Stateful, Window};
use ropey::Rope;

use super::decorations::DecorationCollections;
use super::decorations::{DecorationCollections, EditorAnnotations};
use super::lsp::{ContextMenuContent, HoverDefinition, InlineCompletion};
use crate::input::{
HighlightStyleResolver, InputEdit, InputHighlighter, SyntaxContext, TextDecoration,
GutterMarker, HighlightStyleResolver, InlineWidget, InputEdit, InputHighlighter,
RangeDecoration, SyntaxContext, TextDecoration,
};
use crate::input::{HoverPopoverState, Lsp};
use gpui::Task;
Expand Down Expand Up @@ -115,6 +117,36 @@ pub trait InputExtras: Default + 'static {
fn context_menu_capabilities(&self) -> (bool, bool) {
(false, false)
}

/// Feature-owned gutter markers anchored to logical rows.
fn gutter_markers(&self) -> &[GutterMarker] {
&[]
}

/// Whether the gutter marker lane has ever been used and stays reserved.
fn gutter_lane_reserved(&self) -> bool {
false
}

/// The application-owned presentation for gutter markers, if any.
fn gutter_marker_renderer(&self) -> Option<crate::input::GutterMarkerRenderer> {
None
}

/// Last-paint bounds per gutter marker, keyed by marker id.
fn gutter_marker_bounds(&self) -> Option<Rc<RefCell<HashMap<SharedString, Bounds<Pixels>>>>> {
None
}

/// Geometric range decorations to paint.
fn range_decorations(&self) -> &[RangeDecoration] {
&[]
}

/// Non-document inline widgets to paint at their offsets.
fn inline_widgets(&self) -> &[InlineWidget] {
&[]
}
}

/// A mode with nothing extra to render.
Expand Down Expand Up @@ -203,6 +235,9 @@ pub trait InputModeKind: sealed::Sealed + Sized + 'static {
) {
}

/// Records a successful document mutation after validation and normalization.
fn document_did_change(_state: &mut InputBaseState<Self>) {}

/// Refreshes language-server state after the text changed.
fn refresh_language_features(
_state: &mut InputBaseState<Self>,
Expand Down Expand Up @@ -341,6 +376,7 @@ pub struct EditorExtras {
pub(crate) hover_popover: Option<HoverPopoverState>,
pub(crate) hover_definition: HoverDefinition,
pub(crate) context_menu_task: Task<anyhow::Result<()>>,
pub(crate) annotations: EditorAnnotations,
}

impl Default for EditorExtras {
Expand All @@ -353,6 +389,7 @@ impl Default for EditorExtras {
hover_popover: None,
hover_definition: HoverDefinition::default(),
context_menu_task: Task::ready(Ok(())),
annotations: EditorAnnotations::default(),
}
}
}
31 changes: 23 additions & 8 deletions crates/base/src/input/base/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,16 @@ actions!(
#[derive(Clone)]
pub enum InputEvent {
Change,
PressEnter { secondary: bool, shift: bool },
PressEnter {
secondary: bool,
shift: bool,
},
Focus,
Blur,
GutterMarkerMouseDown {
marker_id: SharedString,
logical_row: usize,
},
}

pub(super) const CONTEXT: &str = "Input";
Expand Down Expand Up @@ -3485,6 +3492,7 @@ impl<M: InputModeKind> InputBaseState<M> {
self.text.replace(range.clone(), new_text);

M::adjust_annotations(self, range, new_text.len());
M::document_did_change(self);
recorded |= self.push_history(
&old_text,
range,
Expand Down Expand Up @@ -3830,12 +3838,16 @@ impl<M: InputModeKind> EntityInputHandler for InputBaseState<M> {
}
}

if mask_changed {
// Masking rewrites the whole document, so ranges recorded against
// the old text no longer point at anything.
M::reset_annotations(self);
} else {
M::adjust_annotations(self, &range, new_text.len());
let document_changed = old_text != self.text;
if document_changed {
if mask_changed {
// Masking rewrites the whole document, so ranges recorded against
// the old text no longer point at anything.
M::reset_annotations(self);
} else {
M::adjust_annotations(self, &range, new_text.len());
}
M::document_did_change(self);
}
if mask_changed {
// A segment-based history entry no longer matches the masked
Expand Down Expand Up @@ -3965,7 +3977,10 @@ impl<M: InputModeKind> EntityInputHandler for InputBaseState<M> {
}
}

M::adjust_annotations(self, &range, new_text.len());
if old_text != self.text {
M::adjust_annotations(self, &range, new_text.len());
M::document_did_change(self);
}
if let Some(diagnostics) = self.mode.diagnostics_mut() {
diagnostics.reset(&self.text)
}
Expand Down
Loading
Loading