diff --git a/Cargo.lock b/Cargo.lock index b17b55957d1adc706a081d861174f3a7dd4d5e79..09930893337d77b50b96f77ad9ef22a71635122f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3957,6 +3957,7 @@ dependencies = [ "unindent", "url", "util", + "uuid", "workspace", ] diff --git a/Cargo.toml b/Cargo.toml index a21a65c8feab34e427dad3a106b6dde1ad9947ae..7ff0ad6ce3534db3526d3c48eab8c3f0aa3b34d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -506,7 +506,7 @@ unindent = "0.1.7" unicode-segmentation = "1.10" unicode-script = "0.5.7" url = "2.2" -uuid = { version = "1.1.2", features = ["v4", "v5", "serde"] } +uuid = { version = "1.1.2", features = ["v4", "v5", "v7", "serde"] } wasmparser = "0.215" wasm-encoder = "0.215" wasmtime = { version = "24", default-features = false, features = [ diff --git a/crates/editor/Cargo.toml b/crates/editor/Cargo.toml index 166e7383fcdbb91716544620776c96c5dfbe0976..a728ea86a2e38ebc7dd653eb50a6373288b597b3 100644 --- a/crates/editor/Cargo.toml +++ b/crates/editor/Cargo.toml @@ -85,6 +85,7 @@ unindent = { workspace = true, optional = true } ui.workspace = true url.workspace = true util.workspace = true +uuid.workspace = true workspace.workspace = true [dev-dependencies] diff --git a/crates/editor/src/actions.rs b/crates/editor/src/actions.rs index 99e7c6cd0be7fe008aaf5f5982baf0e6976e6acc..eb0fcaa1e5002829753e8f0f3ae831d2f86bd2ef 100644 --- a/crates/editor/src/actions.rs +++ b/crates/editor/src/actions.rs @@ -105,6 +105,7 @@ pub struct MoveDownByLines { #[serde(default)] pub(super) lines: u32, } + #[derive(PartialEq, Clone, Deserialize, Default)] pub struct SelectUpByLines { #[serde(default)] @@ -166,6 +167,13 @@ pub struct SpawnNearestTask { pub reveal: task::RevealStrategy, } +#[derive(Debug, PartialEq, Eq, Clone, Copy, Deserialize, Default)] +pub enum UuidVersion { + #[default] + V4, + V7, +} + impl_actions!( editor, [ @@ -271,6 +279,8 @@ gpui::actions!( HalfPageUp, Hover, Indent, + InsertUuidV4, + InsertUuidV7, JoinLines, KillRingCut, KillRingYank, diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 132a5e04fb7f29ba2288fffdaf479752e23c8e7a..0bd30465d9ffc059f0832382c10043909c49c6cf 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -12004,6 +12004,33 @@ impl Editor { .detach(); } + pub fn insert_uuid_v4(&mut self, _: &InsertUuidV4, cx: &mut ViewContext) { + self.insert_uuid(UuidVersion::V4, cx); + } + + pub fn insert_uuid_v7(&mut self, _: &InsertUuidV7, cx: &mut ViewContext) { + self.insert_uuid(UuidVersion::V7, cx); + } + + fn insert_uuid(&mut self, version: UuidVersion, cx: &mut ViewContext) { + self.transact(cx, |this, cx| { + let edits = this + .selections + .all::(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. /// diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 198ecf682637021456ba8fc49bf243bc33b094da..2df6d66b6a4b116acc72eb4d07a00bc8b1603cdc 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -456,6 +456,8 @@ impl EditorElement { register_action(view, cx, Editor::open_active_item_in_terminal); register_action(view, cx, Editor::reload_file); register_action(view, cx, Editor::spawn_nearest_task); + register_action(view, cx, Editor::insert_uuid_v4); + register_action(view, cx, Editor::insert_uuid_v7); } fn register_key_listeners(&self, cx: &mut WindowContext, layout: &EditorLayout) {