Add line ending selector (#35392)
Partially addresses this issue #5294 Adds a selector between `LF` and `CRLF` for the buffer's line endings, the checkmark denotes the currently selected line ending. Selector <img width="487" height="66" alt="image" src="https://github.com/user-attachments/assets/13f2480f-4d2d-4afe-adf5-385aeb421393" /> Release Notes: - Added line ending selector. --------- Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
This commit is contained in:
co-authored by
Conrad Irwin
parent
638320b21e
commit
b3405c3bd1
@@ -284,6 +284,14 @@ pub enum Operation {
|
||||
/// The language server ID.
|
||||
server_id: LanguageServerId,
|
||||
},
|
||||
|
||||
/// An update to the line ending type of this buffer.
|
||||
UpdateLineEnding {
|
||||
/// The line ending type.
|
||||
line_ending: LineEnding,
|
||||
/// The buffer's lamport timestamp.
|
||||
lamport_timestamp: clock::Lamport,
|
||||
},
|
||||
}
|
||||
|
||||
/// An event that occurs in a buffer.
|
||||
@@ -1240,6 +1248,21 @@ impl Buffer {
|
||||
self.syntax_map.lock().language_registry()
|
||||
}
|
||||
|
||||
/// Assign the line ending type to the buffer.
|
||||
pub fn set_line_ending(&mut self, line_ending: LineEnding, cx: &mut Context<Self>) {
|
||||
self.text.set_line_ending(line_ending);
|
||||
|
||||
let lamport_timestamp = self.text.lamport_clock.tick();
|
||||
self.send_operation(
|
||||
Operation::UpdateLineEnding {
|
||||
line_ending,
|
||||
lamport_timestamp,
|
||||
},
|
||||
true,
|
||||
cx,
|
||||
);
|
||||
}
|
||||
|
||||
/// Assign the buffer a new [`Capability`].
|
||||
pub fn set_capability(&mut self, capability: Capability, cx: &mut Context<Self>) {
|
||||
if self.capability != capability {
|
||||
@@ -2557,7 +2580,7 @@ impl Buffer {
|
||||
Operation::UpdateSelections { selections, .. } => selections
|
||||
.iter()
|
||||
.all(|s| self.can_resolve(&s.start) && self.can_resolve(&s.end)),
|
||||
Operation::UpdateCompletionTriggers { .. } => true,
|
||||
Operation::UpdateCompletionTriggers { .. } | Operation::UpdateLineEnding { .. } => true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2623,6 +2646,13 @@ impl Buffer {
|
||||
}
|
||||
self.text.lamport_clock.observe(lamport_timestamp);
|
||||
}
|
||||
Operation::UpdateLineEnding {
|
||||
line_ending,
|
||||
lamport_timestamp,
|
||||
} => {
|
||||
self.text.set_line_ending(line_ending);
|
||||
self.text.lamport_clock.observe(lamport_timestamp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4814,6 +4844,9 @@ impl operation_queue::Operation for Operation {
|
||||
}
|
||||
| Operation::UpdateCompletionTriggers {
|
||||
lamport_timestamp, ..
|
||||
}
|
||||
| Operation::UpdateLineEnding {
|
||||
lamport_timestamp, ..
|
||||
} => *lamport_timestamp,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user