Add cursor blink setting and replicate cursor shape to remote collaborators
This commit is contained in:
parent
318b923bac
commit
40c3e925ad
15 changed files with 128 additions and 63 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -5828,6 +5828,7 @@ dependencies = [
|
||||||
"futures 0.3.24",
|
"futures 0.3.24",
|
||||||
"gpui",
|
"gpui",
|
||||||
"itertools",
|
"itertools",
|
||||||
|
"language",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"libc",
|
"libc",
|
||||||
"mio-extras",
|
"mio-extras",
|
||||||
|
|
|
@ -69,6 +69,8 @@
|
||||||
// The column at which to soft-wrap lines, for buffers where soft-wrap
|
// The column at which to soft-wrap lines, for buffers where soft-wrap
|
||||||
// is enabled.
|
// is enabled.
|
||||||
"preferred_line_length": 80,
|
"preferred_line_length": 80,
|
||||||
|
// Whether the cursor blinks in the editor.
|
||||||
|
"cursor_blink": true,
|
||||||
// Whether to indent lines using tab characters, as opposed to multiple
|
// Whether to indent lines using tab characters, as opposed to multiple
|
||||||
// spaces.
|
// spaces.
|
||||||
"hard_tabs": false,
|
"hard_tabs": false,
|
||||||
|
|
|
@ -42,9 +42,9 @@ use hover_popover::{hide_hover, HoverState};
|
||||||
pub use items::MAX_TAB_TITLE_LEN;
|
pub use items::MAX_TAB_TITLE_LEN;
|
||||||
pub use language::{char_kind, CharKind};
|
pub use language::{char_kind, CharKind};
|
||||||
use language::{
|
use language::{
|
||||||
AutoindentMode, BracketPair, Buffer, CodeAction, CodeLabel, Completion, Diagnostic,
|
AutoindentMode, BracketPair, Buffer, CodeAction, CodeLabel, Completion, CursorShape,
|
||||||
DiagnosticSeverity, IndentKind, IndentSize, Language, OffsetRangeExt, OffsetUtf16, Point,
|
Diagnostic, DiagnosticSeverity, IndentKind, IndentSize, Language, OffsetRangeExt, OffsetUtf16,
|
||||||
Selection, SelectionGoal, TransactionId,
|
Point, Selection, SelectionGoal, TransactionId,
|
||||||
};
|
};
|
||||||
use link_go_to_definition::{hide_link_definition, LinkGoToDefinitionState};
|
use link_go_to_definition::{hide_link_definition, LinkGoToDefinitionState};
|
||||||
pub use multi_buffer::{
|
pub use multi_buffer::{
|
||||||
|
@ -1478,6 +1478,7 @@ impl Editor {
|
||||||
buffer.set_active_selections(
|
buffer.set_active_selections(
|
||||||
&self.selections.disjoint_anchors(),
|
&self.selections.disjoint_anchors(),
|
||||||
self.selections.line_mode,
|
self.selections.line_mode,
|
||||||
|
self.cursor_shape,
|
||||||
cx,
|
cx,
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
@ -6145,7 +6146,17 @@ impl Editor {
|
||||||
|
|
||||||
fn blink_cursors(&mut self, epoch: usize, cx: &mut ViewContext<Self>) {
|
fn blink_cursors(&mut self, epoch: usize, cx: &mut ViewContext<Self>) {
|
||||||
if epoch == self.blink_epoch && self.focused && !self.blinking_paused {
|
if epoch == self.blink_epoch && self.focused && !self.blinking_paused {
|
||||||
self.show_local_cursors = !self.show_local_cursors;
|
let newest_head = self.selections.newest::<usize>(cx).head();
|
||||||
|
let language_name = self
|
||||||
|
.buffer
|
||||||
|
.read(cx)
|
||||||
|
.language_at(newest_head, cx)
|
||||||
|
.map(|l| l.name());
|
||||||
|
|
||||||
|
self.show_local_cursors = !self.show_local_cursors
|
||||||
|
|| !cx
|
||||||
|
.global::<Settings>()
|
||||||
|
.cursor_blink(language_name.as_deref());
|
||||||
cx.notify();
|
cx.notify();
|
||||||
|
|
||||||
let epoch = self.next_blink_epoch();
|
let epoch = self.next_blink_epoch();
|
||||||
|
@ -6466,9 +6477,7 @@ impl View for Editor {
|
||||||
}
|
}
|
||||||
|
|
||||||
Stack::new()
|
Stack::new()
|
||||||
.with_child(
|
.with_child(EditorElement::new(self.handle.clone(), style.clone()).boxed())
|
||||||
EditorElement::new(self.handle.clone(), style.clone(), self.cursor_shape).boxed(),
|
|
||||||
)
|
|
||||||
.with_child(ChildView::new(&self.mouse_context_menu, cx).boxed())
|
.with_child(ChildView::new(&self.mouse_context_menu, cx).boxed())
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
}
|
||||||
|
@ -6491,6 +6500,7 @@ impl View for Editor {
|
||||||
buffer.set_active_selections(
|
buffer.set_active_selections(
|
||||||
&self.selections.disjoint_anchors(),
|
&self.selections.disjoint_anchors(),
|
||||||
self.selections.line_mode,
|
self.selections.line_mode,
|
||||||
|
self.cursor_shape,
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ use gpui::{
|
||||||
WeakViewHandle,
|
WeakViewHandle,
|
||||||
};
|
};
|
||||||
use json::json;
|
use json::json;
|
||||||
use language::{Bias, DiagnosticSeverity, OffsetUtf16, Point, Selection};
|
use language::{Bias, CursorShape, DiagnosticSeverity, OffsetUtf16, Point, Selection};
|
||||||
use project::ProjectPath;
|
use project::ProjectPath;
|
||||||
use settings::{GitGutter, Settings};
|
use settings::{GitGutter, Settings};
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
|
@ -56,6 +56,7 @@ struct DiffHunkLayout {
|
||||||
|
|
||||||
struct SelectionLayout {
|
struct SelectionLayout {
|
||||||
head: DisplayPoint,
|
head: DisplayPoint,
|
||||||
|
cursor_shape: CursorShape,
|
||||||
range: Range<DisplayPoint>,
|
range: Range<DisplayPoint>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,6 +64,7 @@ impl SelectionLayout {
|
||||||
fn new<T: ToPoint + ToDisplayPoint + Clone>(
|
fn new<T: ToPoint + ToDisplayPoint + Clone>(
|
||||||
selection: Selection<T>,
|
selection: Selection<T>,
|
||||||
line_mode: bool,
|
line_mode: bool,
|
||||||
|
cursor_shape: CursorShape,
|
||||||
map: &DisplaySnapshot,
|
map: &DisplaySnapshot,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
if line_mode {
|
if line_mode {
|
||||||
|
@ -70,6 +72,7 @@ impl SelectionLayout {
|
||||||
let point_range = map.expand_to_line(selection.range());
|
let point_range = map.expand_to_line(selection.range());
|
||||||
Self {
|
Self {
|
||||||
head: selection.head().to_display_point(map),
|
head: selection.head().to_display_point(map),
|
||||||
|
cursor_shape,
|
||||||
range: point_range.start.to_display_point(map)
|
range: point_range.start.to_display_point(map)
|
||||||
..point_range.end.to_display_point(map),
|
..point_range.end.to_display_point(map),
|
||||||
}
|
}
|
||||||
|
@ -77,6 +80,7 @@ impl SelectionLayout {
|
||||||
let selection = selection.map(|p| p.to_display_point(map));
|
let selection = selection.map(|p| p.to_display_point(map));
|
||||||
Self {
|
Self {
|
||||||
head: selection.head(),
|
head: selection.head(),
|
||||||
|
cursor_shape,
|
||||||
range: selection.range(),
|
range: selection.range(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,19 +91,13 @@ impl SelectionLayout {
|
||||||
pub struct EditorElement {
|
pub struct EditorElement {
|
||||||
view: WeakViewHandle<Editor>,
|
view: WeakViewHandle<Editor>,
|
||||||
style: Arc<EditorStyle>,
|
style: Arc<EditorStyle>,
|
||||||
cursor_shape: CursorShape,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EditorElement {
|
impl EditorElement {
|
||||||
pub fn new(
|
pub fn new(view: WeakViewHandle<Editor>, style: EditorStyle) -> Self {
|
||||||
view: WeakViewHandle<Editor>,
|
|
||||||
style: EditorStyle,
|
|
||||||
cursor_shape: CursorShape,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
Self {
|
||||||
view,
|
view,
|
||||||
style: Arc::new(style),
|
style: Arc::new(style),
|
||||||
cursor_shape,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -723,7 +721,7 @@ impl EditorElement {
|
||||||
if block_width == 0.0 {
|
if block_width == 0.0 {
|
||||||
block_width = layout.position_map.em_width;
|
block_width = layout.position_map.em_width;
|
||||||
}
|
}
|
||||||
let block_text = if let CursorShape::Block = self.cursor_shape {
|
let block_text = if let CursorShape::Block = selection.cursor_shape {
|
||||||
layout
|
layout
|
||||||
.position_map
|
.position_map
|
||||||
.snapshot
|
.snapshot
|
||||||
|
@ -759,7 +757,7 @@ impl EditorElement {
|
||||||
block_width,
|
block_width,
|
||||||
origin: vec2f(x, y),
|
origin: vec2f(x, y),
|
||||||
line_height: layout.position_map.line_height,
|
line_height: layout.position_map.line_height,
|
||||||
shape: self.cursor_shape,
|
shape: selection.cursor_shape,
|
||||||
block_text,
|
block_text,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1648,7 +1646,7 @@ impl Element for EditorElement {
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut remote_selections = HashMap::default();
|
let mut remote_selections = HashMap::default();
|
||||||
for (replica_id, line_mode, selection) in display_map
|
for (replica_id, line_mode, cursor_shape, selection) in display_map
|
||||||
.buffer_snapshot
|
.buffer_snapshot
|
||||||
.remote_selections_in_range(&(start_anchor.clone()..end_anchor.clone()))
|
.remote_selections_in_range(&(start_anchor.clone()..end_anchor.clone()))
|
||||||
{
|
{
|
||||||
|
@ -1659,7 +1657,12 @@ impl Element for EditorElement {
|
||||||
remote_selections
|
remote_selections
|
||||||
.entry(replica_id)
|
.entry(replica_id)
|
||||||
.or_insert(Vec::new())
|
.or_insert(Vec::new())
|
||||||
.push(SelectionLayout::new(selection, line_mode, &display_map));
|
.push(SelectionLayout::new(
|
||||||
|
selection,
|
||||||
|
line_mode,
|
||||||
|
cursor_shape,
|
||||||
|
&display_map,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
selections.extend(remote_selections);
|
selections.extend(remote_selections);
|
||||||
|
|
||||||
|
@ -1691,7 +1694,12 @@ impl Element for EditorElement {
|
||||||
local_selections
|
local_selections
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|selection| {
|
.map(|selection| {
|
||||||
SelectionLayout::new(selection, view.selections.line_mode, &display_map)
|
SelectionLayout::new(
|
||||||
|
selection,
|
||||||
|
view.selections.line_mode,
|
||||||
|
view.cursor_shape,
|
||||||
|
&display_map,
|
||||||
|
)
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
));
|
));
|
||||||
|
@ -2094,20 +2102,6 @@ fn layout_line(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
|
||||||
pub enum CursorShape {
|
|
||||||
Bar,
|
|
||||||
Block,
|
|
||||||
Underscore,
|
|
||||||
Hollow,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for CursorShape {
|
|
||||||
fn default() -> Self {
|
|
||||||
CursorShape::Bar
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Cursor {
|
pub struct Cursor {
|
||||||
origin: Vector2F,
|
origin: Vector2F,
|
||||||
|
@ -2348,11 +2342,7 @@ mod tests {
|
||||||
let (window_id, editor) = cx.add_window(Default::default(), |cx| {
|
let (window_id, editor) = cx.add_window(Default::default(), |cx| {
|
||||||
Editor::new(EditorMode::Full, buffer, None, None, cx)
|
Editor::new(EditorMode::Full, buffer, None, None, cx)
|
||||||
});
|
});
|
||||||
let element = EditorElement::new(
|
let element = EditorElement::new(editor.downgrade(), editor.read(cx).style(cx));
|
||||||
editor.downgrade(),
|
|
||||||
editor.read(cx).style(cx),
|
|
||||||
CursorShape::Bar,
|
|
||||||
);
|
|
||||||
|
|
||||||
let layouts = editor.update(cx, |editor, cx| {
|
let layouts = editor.update(cx, |editor, cx| {
|
||||||
let snapshot = editor.snapshot(cx);
|
let snapshot = editor.snapshot(cx);
|
||||||
|
@ -2388,11 +2378,7 @@ mod tests {
|
||||||
cx.blur();
|
cx.blur();
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut element = EditorElement::new(
|
let mut element = EditorElement::new(editor.downgrade(), editor.read(cx).style(cx));
|
||||||
editor.downgrade(),
|
|
||||||
editor.read(cx).style(cx),
|
|
||||||
CursorShape::Bar,
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut scene = Scene::new(1.0);
|
let mut scene = Scene::new(1.0);
|
||||||
let mut presenter = cx.build_presenter(window_id, 30., Default::default());
|
let mut presenter = cx.build_presenter(window_id, 30., Default::default());
|
||||||
|
|
|
@ -120,6 +120,7 @@ impl FollowableItem for Editor {
|
||||||
buffer.set_active_selections(
|
buffer.set_active_selections(
|
||||||
&self.selections.disjoint_anchors(),
|
&self.selections.disjoint_anchors(),
|
||||||
self.selections.line_mode,
|
self.selections.line_mode,
|
||||||
|
self.cursor_shape,
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ use git::diff::DiffHunk;
|
||||||
use gpui::{AppContext, Entity, ModelContext, ModelHandle, Task};
|
use gpui::{AppContext, Entity, ModelContext, ModelHandle, Task};
|
||||||
pub use language::Completion;
|
pub use language::Completion;
|
||||||
use language::{
|
use language::{
|
||||||
char_kind, AutoindentMode, Buffer, BufferChunks, BufferSnapshot, CharKind, Chunk,
|
char_kind, AutoindentMode, Buffer, BufferChunks, BufferSnapshot, CharKind, Chunk, CursorShape,
|
||||||
DiagnosticEntry, Event, File, IndentSize, Language, OffsetRangeExt, OffsetUtf16, Outline,
|
DiagnosticEntry, Event, File, IndentSize, Language, OffsetRangeExt, OffsetUtf16, Outline,
|
||||||
OutlineItem, Point, PointUtf16, Selection, TextDimension, ToOffset as _, ToOffsetUtf16 as _,
|
OutlineItem, Point, PointUtf16, Selection, TextDimension, ToOffset as _, ToOffsetUtf16 as _,
|
||||||
ToPoint as _, ToPointUtf16 as _, TransactionId,
|
ToPoint as _, ToPointUtf16 as _, TransactionId,
|
||||||
|
@ -604,6 +604,7 @@ impl MultiBuffer {
|
||||||
&mut self,
|
&mut self,
|
||||||
selections: &[Selection<Anchor>],
|
selections: &[Selection<Anchor>],
|
||||||
line_mode: bool,
|
line_mode: bool,
|
||||||
|
cursor_shape: CursorShape,
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) {
|
) {
|
||||||
let mut selections_by_buffer: HashMap<usize, Vec<Selection<text::Anchor>>> =
|
let mut selections_by_buffer: HashMap<usize, Vec<Selection<text::Anchor>>> =
|
||||||
|
@ -668,7 +669,7 @@ impl MultiBuffer {
|
||||||
}
|
}
|
||||||
Some(selection)
|
Some(selection)
|
||||||
}));
|
}));
|
||||||
buffer.set_active_selections(merged_selections, line_mode, cx);
|
buffer.set_active_selections(merged_selections, line_mode, cursor_shape, cx);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2698,7 +2699,7 @@ impl MultiBufferSnapshot {
|
||||||
pub fn remote_selections_in_range<'a>(
|
pub fn remote_selections_in_range<'a>(
|
||||||
&'a self,
|
&'a self,
|
||||||
range: &'a Range<Anchor>,
|
range: &'a Range<Anchor>,
|
||||||
) -> impl 'a + Iterator<Item = (ReplicaId, bool, Selection<Anchor>)> {
|
) -> impl 'a + Iterator<Item = (ReplicaId, bool, CursorShape, Selection<Anchor>)> {
|
||||||
let mut cursor = self.excerpts.cursor::<Option<&ExcerptId>>();
|
let mut cursor = self.excerpts.cursor::<Option<&ExcerptId>>();
|
||||||
cursor.seek(&Some(&range.start.excerpt_id), Bias::Left, &());
|
cursor.seek(&Some(&range.start.excerpt_id), Bias::Left, &());
|
||||||
cursor
|
cursor
|
||||||
|
@ -2715,7 +2716,7 @@ impl MultiBufferSnapshot {
|
||||||
excerpt
|
excerpt
|
||||||
.buffer
|
.buffer
|
||||||
.remote_selections_in_range(query_range)
|
.remote_selections_in_range(query_range)
|
||||||
.flat_map(move |(replica_id, line_mode, selections)| {
|
.flat_map(move |(replica_id, line_mode, cursor_shape, selections)| {
|
||||||
selections.map(move |selection| {
|
selections.map(move |selection| {
|
||||||
let mut start = Anchor {
|
let mut start = Anchor {
|
||||||
buffer_id: Some(excerpt.buffer_id),
|
buffer_id: Some(excerpt.buffer_id),
|
||||||
|
@ -2737,6 +2738,7 @@ impl MultiBufferSnapshot {
|
||||||
(
|
(
|
||||||
replica_id,
|
replica_id,
|
||||||
line_mode,
|
line_mode,
|
||||||
|
cursor_shape,
|
||||||
Selection {
|
Selection {
|
||||||
id: selection.id,
|
id: selection.id,
|
||||||
start,
|
start,
|
||||||
|
|
|
@ -111,9 +111,19 @@ pub enum IndentKind {
|
||||||
Tab,
|
Tab,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
|
||||||
|
pub enum CursorShape {
|
||||||
|
#[default]
|
||||||
|
Bar,
|
||||||
|
Block,
|
||||||
|
Underscore,
|
||||||
|
Hollow,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
struct SelectionSet {
|
struct SelectionSet {
|
||||||
line_mode: bool,
|
line_mode: bool,
|
||||||
|
cursor_shape: CursorShape,
|
||||||
selections: Arc<[Selection<Anchor>]>,
|
selections: Arc<[Selection<Anchor>]>,
|
||||||
lamport_timestamp: clock::Lamport,
|
lamport_timestamp: clock::Lamport,
|
||||||
}
|
}
|
||||||
|
@ -161,6 +171,7 @@ pub enum Operation {
|
||||||
selections: Arc<[Selection<Anchor>]>,
|
selections: Arc<[Selection<Anchor>]>,
|
||||||
lamport_timestamp: clock::Lamport,
|
lamport_timestamp: clock::Lamport,
|
||||||
line_mode: bool,
|
line_mode: bool,
|
||||||
|
cursor_shape: CursorShape,
|
||||||
},
|
},
|
||||||
UpdateCompletionTriggers {
|
UpdateCompletionTriggers {
|
||||||
triggers: Vec<String>,
|
triggers: Vec<String>,
|
||||||
|
@ -395,6 +406,7 @@ impl Buffer {
|
||||||
selections: set.selections.clone(),
|
selections: set.selections.clone(),
|
||||||
lamport_timestamp: set.lamport_timestamp,
|
lamport_timestamp: set.lamport_timestamp,
|
||||||
line_mode: set.line_mode,
|
line_mode: set.line_mode,
|
||||||
|
cursor_shape: set.cursor_shape,
|
||||||
})
|
})
|
||||||
}));
|
}));
|
||||||
operations.push(proto::serialize_operation(&Operation::UpdateDiagnostics {
|
operations.push(proto::serialize_operation(&Operation::UpdateDiagnostics {
|
||||||
|
@ -1227,6 +1239,7 @@ impl Buffer {
|
||||||
&mut self,
|
&mut self,
|
||||||
selections: Arc<[Selection<Anchor>]>,
|
selections: Arc<[Selection<Anchor>]>,
|
||||||
line_mode: bool,
|
line_mode: bool,
|
||||||
|
cursor_shape: CursorShape,
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) {
|
) {
|
||||||
let lamport_timestamp = self.text.lamport_clock.tick();
|
let lamport_timestamp = self.text.lamport_clock.tick();
|
||||||
|
@ -1236,6 +1249,7 @@ impl Buffer {
|
||||||
selections: selections.clone(),
|
selections: selections.clone(),
|
||||||
lamport_timestamp,
|
lamport_timestamp,
|
||||||
line_mode,
|
line_mode,
|
||||||
|
cursor_shape,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
self.send_operation(
|
self.send_operation(
|
||||||
|
@ -1243,13 +1257,14 @@ impl Buffer {
|
||||||
selections,
|
selections,
|
||||||
line_mode,
|
line_mode,
|
||||||
lamport_timestamp,
|
lamport_timestamp,
|
||||||
|
cursor_shape,
|
||||||
},
|
},
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_active_selections(&mut self, cx: &mut ModelContext<Self>) {
|
pub fn remove_active_selections(&mut self, cx: &mut ModelContext<Self>) {
|
||||||
self.set_active_selections(Arc::from([]), false, cx);
|
self.set_active_selections(Arc::from([]), false, Default::default(), cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_text<T>(&mut self, text: T, cx: &mut ModelContext<Self>) -> Option<clock::Local>
|
pub fn set_text<T>(&mut self, text: T, cx: &mut ModelContext<Self>) -> Option<clock::Local>
|
||||||
|
@ -1474,6 +1489,7 @@ impl Buffer {
|
||||||
selections,
|
selections,
|
||||||
lamport_timestamp,
|
lamport_timestamp,
|
||||||
line_mode,
|
line_mode,
|
||||||
|
cursor_shape,
|
||||||
} => {
|
} => {
|
||||||
if let Some(set) = self.remote_selections.get(&lamport_timestamp.replica_id) {
|
if let Some(set) = self.remote_selections.get(&lamport_timestamp.replica_id) {
|
||||||
if set.lamport_timestamp > lamport_timestamp {
|
if set.lamport_timestamp > lamport_timestamp {
|
||||||
|
@ -1487,6 +1503,7 @@ impl Buffer {
|
||||||
selections,
|
selections,
|
||||||
lamport_timestamp,
|
lamport_timestamp,
|
||||||
line_mode,
|
line_mode,
|
||||||
|
cursor_shape,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
self.text.lamport_clock.observe(lamport_timestamp);
|
self.text.lamport_clock.observe(lamport_timestamp);
|
||||||
|
@ -2236,6 +2253,7 @@ impl BufferSnapshot {
|
||||||
Item = (
|
Item = (
|
||||||
ReplicaId,
|
ReplicaId,
|
||||||
bool,
|
bool,
|
||||||
|
CursorShape,
|
||||||
impl Iterator<Item = &Selection<Anchor>> + '_,
|
impl Iterator<Item = &Selection<Anchor>> + '_,
|
||||||
),
|
),
|
||||||
> + '_ {
|
> + '_ {
|
||||||
|
@ -2259,6 +2277,7 @@ impl BufferSnapshot {
|
||||||
(
|
(
|
||||||
*replica_id,
|
*replica_id,
|
||||||
set.line_mode,
|
set.line_mode,
|
||||||
|
set.cursor_shape,
|
||||||
set.selections[start_ix..end_ix].iter(),
|
set.selections[start_ix..end_ix].iter(),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
|
@ -1283,7 +1283,7 @@ fn test_random_collaboration(cx: &mut MutableAppContext, mut rng: StdRng) {
|
||||||
selections
|
selections
|
||||||
);
|
);
|
||||||
active_selections.insert(replica_id, selections.clone());
|
active_selections.insert(replica_id, selections.clone());
|
||||||
buffer.set_active_selections(selections, false, cx);
|
buffer.set_active_selections(selections, false, Default::default(), cx);
|
||||||
});
|
});
|
||||||
mutation_count -= 1;
|
mutation_count -= 1;
|
||||||
}
|
}
|
||||||
|
@ -1448,7 +1448,7 @@ fn test_random_collaboration(cx: &mut MutableAppContext, mut rng: StdRng) {
|
||||||
let buffer = buffer.read(cx).snapshot();
|
let buffer = buffer.read(cx).snapshot();
|
||||||
let actual_remote_selections = buffer
|
let actual_remote_selections = buffer
|
||||||
.remote_selections_in_range(Anchor::MIN..Anchor::MAX)
|
.remote_selections_in_range(Anchor::MIN..Anchor::MAX)
|
||||||
.map(|(replica_id, _, selections)| (replica_id, selections.collect::<Vec<_>>()))
|
.map(|(replica_id, _, _, selections)| (replica_id, selections.collect::<Vec<_>>()))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
let expected_remote_selections = active_selections
|
let expected_remote_selections = active_selections
|
||||||
.iter()
|
.iter()
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
diagnostic_set::DiagnosticEntry, CodeAction, CodeLabel, Completion, Diagnostic, Language,
|
diagnostic_set::DiagnosticEntry, CodeAction, CodeLabel, Completion, CursorShape, Diagnostic,
|
||||||
|
Language,
|
||||||
};
|
};
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use clock::ReplicaId;
|
use clock::ReplicaId;
|
||||||
|
@ -52,11 +53,13 @@ pub fn serialize_operation(operation: &crate::Operation) -> proto::Operation {
|
||||||
selections,
|
selections,
|
||||||
line_mode,
|
line_mode,
|
||||||
lamport_timestamp,
|
lamport_timestamp,
|
||||||
|
cursor_shape,
|
||||||
} => proto::operation::Variant::UpdateSelections(proto::operation::UpdateSelections {
|
} => proto::operation::Variant::UpdateSelections(proto::operation::UpdateSelections {
|
||||||
replica_id: lamport_timestamp.replica_id as u32,
|
replica_id: lamport_timestamp.replica_id as u32,
|
||||||
lamport_timestamp: lamport_timestamp.value,
|
lamport_timestamp: lamport_timestamp.value,
|
||||||
selections: serialize_selections(selections),
|
selections: serialize_selections(selections),
|
||||||
line_mode: *line_mode,
|
line_mode: *line_mode,
|
||||||
|
cursor_shape: serialize_cursor_shape(cursor_shape) as i32,
|
||||||
}),
|
}),
|
||||||
crate::Operation::UpdateDiagnostics {
|
crate::Operation::UpdateDiagnostics {
|
||||||
diagnostics,
|
diagnostics,
|
||||||
|
@ -125,6 +128,24 @@ pub fn serialize_selection(selection: &Selection<Anchor>) -> proto::Selection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn serialize_cursor_shape(cursor_shape: &CursorShape) -> proto::CursorShape {
|
||||||
|
match cursor_shape {
|
||||||
|
CursorShape::Bar => proto::CursorShape::CursorBar,
|
||||||
|
CursorShape::Block => proto::CursorShape::CursorBlock,
|
||||||
|
CursorShape::Underscore => proto::CursorShape::CursorUnderscore,
|
||||||
|
CursorShape::Hollow => proto::CursorShape::CursorHollow,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn deserialize_cursor_shape(cursor_shape: proto::CursorShape) -> CursorShape {
|
||||||
|
match cursor_shape {
|
||||||
|
proto::CursorShape::CursorBar => CursorShape::Bar,
|
||||||
|
proto::CursorShape::CursorBlock => CursorShape::Block,
|
||||||
|
proto::CursorShape::CursorUnderscore => CursorShape::Underscore,
|
||||||
|
proto::CursorShape::CursorHollow => CursorShape::Hollow,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn serialize_diagnostics<'a>(
|
pub fn serialize_diagnostics<'a>(
|
||||||
diagnostics: impl IntoIterator<Item = &'a DiagnosticEntry<Anchor>>,
|
diagnostics: impl IntoIterator<Item = &'a DiagnosticEntry<Anchor>>,
|
||||||
) -> Vec<proto::Diagnostic> {
|
) -> Vec<proto::Diagnostic> {
|
||||||
|
@ -223,6 +244,10 @@ pub fn deserialize_operation(message: proto::Operation) -> Result<crate::Operati
|
||||||
},
|
},
|
||||||
selections: Arc::from(selections),
|
selections: Arc::from(selections),
|
||||||
line_mode: message.line_mode,
|
line_mode: message.line_mode,
|
||||||
|
cursor_shape: deserialize_cursor_shape(
|
||||||
|
proto::CursorShape::from_i32(message.cursor_shape)
|
||||||
|
.ok_or_else(|| anyhow!("Missing cursor shape"))?,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
proto::operation::Variant::UpdateDiagnostics(message) => {
|
proto::operation::Variant::UpdateDiagnostics(message) => {
|
||||||
|
|
|
@ -908,6 +908,7 @@ message SelectionSet {
|
||||||
repeated Selection selections = 2;
|
repeated Selection selections = 2;
|
||||||
uint32 lamport_timestamp = 3;
|
uint32 lamport_timestamp = 3;
|
||||||
bool line_mode = 4;
|
bool line_mode = 4;
|
||||||
|
CursorShape cursor_shape = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
message Selection {
|
message Selection {
|
||||||
|
@ -917,6 +918,13 @@ message Selection {
|
||||||
bool reversed = 4;
|
bool reversed = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum CursorShape {
|
||||||
|
CursorBar = 0;
|
||||||
|
CursorBlock = 1;
|
||||||
|
CursorUnderscore = 2;
|
||||||
|
CursorHollow = 3;
|
||||||
|
}
|
||||||
|
|
||||||
message Anchor {
|
message Anchor {
|
||||||
uint32 replica_id = 1;
|
uint32 replica_id = 1;
|
||||||
uint32 local_timestamp = 2;
|
uint32 local_timestamp = 2;
|
||||||
|
@ -982,6 +990,7 @@ message Operation {
|
||||||
uint32 lamport_timestamp = 2;
|
uint32 lamport_timestamp = 2;
|
||||||
repeated Selection selections = 3;
|
repeated Selection selections = 3;
|
||||||
bool line_mode = 4;
|
bool line_mode = 4;
|
||||||
|
CursorShape cursor_shape = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
message UpdateCompletionTriggers {
|
message UpdateCompletionTriggers {
|
||||||
|
|
|
@ -79,6 +79,7 @@ pub struct GitGutterConfig {}
|
||||||
pub struct EditorSettings {
|
pub struct EditorSettings {
|
||||||
pub tab_size: Option<NonZeroU32>,
|
pub tab_size: Option<NonZeroU32>,
|
||||||
pub hard_tabs: Option<bool>,
|
pub hard_tabs: Option<bool>,
|
||||||
|
pub cursor_blink: Option<bool>,
|
||||||
pub soft_wrap: Option<SoftWrap>,
|
pub soft_wrap: Option<SoftWrap>,
|
||||||
pub preferred_line_length: Option<u32>,
|
pub preferred_line_length: Option<u32>,
|
||||||
pub format_on_save: Option<FormatOnSave>,
|
pub format_on_save: Option<FormatOnSave>,
|
||||||
|
@ -301,6 +302,7 @@ impl Settings {
|
||||||
editor_defaults: EditorSettings {
|
editor_defaults: EditorSettings {
|
||||||
tab_size: required(defaults.editor.tab_size),
|
tab_size: required(defaults.editor.tab_size),
|
||||||
hard_tabs: required(defaults.editor.hard_tabs),
|
hard_tabs: required(defaults.editor.hard_tabs),
|
||||||
|
cursor_blink: required(defaults.editor.cursor_blink),
|
||||||
soft_wrap: required(defaults.editor.soft_wrap),
|
soft_wrap: required(defaults.editor.soft_wrap),
|
||||||
preferred_line_length: required(defaults.editor.preferred_line_length),
|
preferred_line_length: required(defaults.editor.preferred_line_length),
|
||||||
format_on_save: required(defaults.editor.format_on_save),
|
format_on_save: required(defaults.editor.format_on_save),
|
||||||
|
@ -390,6 +392,10 @@ impl Settings {
|
||||||
self.language_setting(language, |settings| settings.hard_tabs)
|
self.language_setting(language, |settings| settings.hard_tabs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn cursor_blink(&self, language: Option<&str>) -> bool {
|
||||||
|
self.language_setting(language, |settings| settings.cursor_blink)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn soft_wrap(&self, language: Option<&str>) -> SoftWrap {
|
pub fn soft_wrap(&self, language: Option<&str>) -> SoftWrap {
|
||||||
self.language_setting(language, |settings| settings.soft_wrap)
|
self.language_setting(language, |settings| settings.soft_wrap)
|
||||||
}
|
}
|
||||||
|
@ -444,6 +450,7 @@ impl Settings {
|
||||||
editor_defaults: EditorSettings {
|
editor_defaults: EditorSettings {
|
||||||
tab_size: Some(4.try_into().unwrap()),
|
tab_size: Some(4.try_into().unwrap()),
|
||||||
hard_tabs: Some(false),
|
hard_tabs: Some(false),
|
||||||
|
cursor_blink: Some(true),
|
||||||
soft_wrap: Some(SoftWrap::None),
|
soft_wrap: Some(SoftWrap::None),
|
||||||
preferred_line_length: Some(80),
|
preferred_line_length: Some(80),
|
||||||
format_on_save: Some(FormatOnSave::On),
|
format_on_save: Some(FormatOnSave::On),
|
||||||
|
|
|
@ -8,16 +8,17 @@ path = "src/terminal.rs"
|
||||||
doctest = false
|
doctest = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
context_menu = { path = "../context_menu" }
|
||||||
|
editor = { path = "../editor" }
|
||||||
|
language = { path = "../language" }
|
||||||
|
gpui = { path = "../gpui" }
|
||||||
|
project = { path = "../project" }
|
||||||
|
settings = { path = "../settings" }
|
||||||
|
theme = { path = "../theme" }
|
||||||
|
util = { path = "../util" }
|
||||||
|
workspace = { path = "../workspace" }
|
||||||
alacritty_terminal = { git = "https://github.com/zed-industries/alacritty", rev = "a51dbe25d67e84d6ed4261e640d3954fbdd9be45" }
|
alacritty_terminal = { git = "https://github.com/zed-industries/alacritty", rev = "a51dbe25d67e84d6ed4261e640d3954fbdd9be45" }
|
||||||
procinfo = { git = "https://github.com/zed-industries/wezterm", rev = "5cd757e5f2eb039ed0c6bb6512223e69d5efc64d", default-features = false }
|
procinfo = { git = "https://github.com/zed-industries/wezterm", rev = "5cd757e5f2eb039ed0c6bb6512223e69d5efc64d", default-features = false }
|
||||||
editor = { path = "../editor" }
|
|
||||||
util = { path = "../util" }
|
|
||||||
gpui = { path = "../gpui" }
|
|
||||||
theme = { path = "../theme" }
|
|
||||||
settings = { path = "../settings" }
|
|
||||||
workspace = { path = "../workspace" }
|
|
||||||
project = { path = "../project" }
|
|
||||||
context_menu = { path = "../context_menu" }
|
|
||||||
smallvec = { version = "1.6", features = ["union"] }
|
smallvec = { version = "1.6", features = ["union"] }
|
||||||
smol = "1.2.5"
|
smol = "1.2.5"
|
||||||
mio-extras = "2.0.6"
|
mio-extras = "2.0.6"
|
||||||
|
|
|
@ -4,7 +4,7 @@ use alacritty_terminal::{
|
||||||
index::Point,
|
index::Point,
|
||||||
term::{cell::Flags, TermMode},
|
term::{cell::Flags, TermMode},
|
||||||
};
|
};
|
||||||
use editor::{Cursor, CursorShape, HighlightedRange, HighlightedRangeLine};
|
use editor::{Cursor, HighlightedRange, HighlightedRangeLine};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
color::Color,
|
color::Color,
|
||||||
elements::{Empty, Overlay},
|
elements::{Empty, Overlay},
|
||||||
|
@ -20,6 +20,7 @@ use gpui::{
|
||||||
WeakViewHandle,
|
WeakViewHandle,
|
||||||
};
|
};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
use language::CursorShape;
|
||||||
use ordered_float::OrderedFloat;
|
use ordered_float::OrderedFloat;
|
||||||
use settings::Settings;
|
use settings::Settings;
|
||||||
use theme::TerminalStyle;
|
use theme::TerminalStyle;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use editor::CursorShape;
|
|
||||||
use gpui::keymap::Context;
|
use gpui::keymap::Context;
|
||||||
|
use language::CursorShape;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize)]
|
||||||
|
|
|
@ -12,8 +12,9 @@ mod visual;
|
||||||
|
|
||||||
use collections::HashMap;
|
use collections::HashMap;
|
||||||
use command_palette::CommandPaletteFilter;
|
use command_palette::CommandPaletteFilter;
|
||||||
use editor::{Bias, Cancel, CursorShape, Editor};
|
use editor::{Bias, Cancel, Editor};
|
||||||
use gpui::{impl_actions, MutableAppContext, Subscription, ViewContext, WeakViewHandle};
|
use gpui::{impl_actions, MutableAppContext, Subscription, ViewContext, WeakViewHandle};
|
||||||
|
use language::CursorShape;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
use settings::Settings;
|
use settings::Settings;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue