editor: Add actions for inserting UUIDs (#21656)

This PR adds two new actions for generating and inserting UUIDs into the
buffer:


https://github.com/user-attachments/assets/a3445a98-07e2-40b8-9773-fd750706cbcc

Release Notes:

- Added `editor: insert uuid v4` and `editor: insert uuid v7` actions
for inserting generated UUIDs into the editor.
This commit is contained in:
Marshall Bowers 2024-12-06 14:32:09 -05:00 committed by GitHub
parent 7a1a7929bd
commit 5142e38d2b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 42 additions and 1 deletions

View file

@ -12004,6 +12004,33 @@ impl Editor {
.detach();
}
pub fn insert_uuid_v4(&mut self, _: &InsertUuidV4, cx: &mut ViewContext<Self>) {
self.insert_uuid(UuidVersion::V4, cx);
}
pub fn insert_uuid_v7(&mut self, _: &InsertUuidV7, cx: &mut ViewContext<Self>) {
self.insert_uuid(UuidVersion::V7, cx);
}
fn insert_uuid(&mut self, version: UuidVersion, cx: &mut ViewContext<Self>) {
self.transact(cx, |this, cx| {
let edits = this
.selections
.all::<Point>(cx)
.into_iter()
.map(|selection| {
let uuid = match version {
UuidVersion::V4 => uuid::Uuid::new_v4(),
UuidVersion::V7 => uuid::Uuid::now_v7(),
};
(selection.range(), uuid.to_string())
});
this.edit(edits, cx);
this.refresh_inline_completion(true, false, cx);
});
}
/// Adds a row highlight for the given range. If a row has multiple highlights, the
/// last highlight added will be used.
///