MCPcopy Create free account
hub / github.com/PerroEngine/Perro / select_related_node

Function select_related_node

perro_editor/res/scripts/scene/editor_nav.rs:877–941  ·  view source on GitHub ↗
(
    ctx: &mut ScriptContext<'_, API>,
    relation: &str,
)

Source from the content-addressed store, hash-verified

875 .unwrap_or(false);
876 if changed {
877 refresh_all(ctx);
878 }
879}
880
881pub fn select_related_node<API: ScriptAPI + ?Sized>(
882 ctx: &mut ScriptContext<'_, API>,
883 relation: &str,
884) {
885 let changed = with_state_mut!(ctx.run, EditorState, ctx.id, |state| {
886 let Some(key) = state.selected_key else {
887 return false;
888 };
889 if state.doc_text.is_empty() {
890 return false;
891 }
892 let doc = cached_scene_doc_shared(&state.doc_text);
893 let Some(node) = cached_scene_node(&state.doc_text, key) else {
894 return false;
895 };
896 let next = match relation {
897 "parent" => node.parent.map(|parent| parent.as_u32()),
898 "child" => doc
899 .scene
900 .nodes
901 .iter()
902 .find(|child| child.parent.map(|parent| parent.as_u32()) == Some(key))
903 .map(|child| child.key.as_u32()),
904 "prev" | "next" => {
905 let parent = node.parent.map(|parent| parent.as_u32());
906 let siblings = doc
907 .scene
908 .nodes
909 .iter()
910 .filter(|item| item.parent.map(|parent| parent.as_u32()) == parent)
911 .map(|item| item.key.as_u32())
912 .collect::<Vec<_>>();
913 let Some(pos) = siblings.iter().position(|item| *item == key) else {
914 return false;
915 };
916 if relation == "prev" {
917 pos.checked_sub(1)
918 .and_then(|idx| siblings.get(idx).copied())
919 } else {
920 siblings.get(pos + 1).copied()
921 }
922 }
923 _ => None,
924 };
925 let Some(next) = next else {
926 state.log = format!("select {relation}\nnone");
927 return false;
928 };
929 state.selected_key = Some(next);
930 state.sidebar_mode = "scene".to_string();
931 state.activity_mode = "scene".to_string();
932 if let Some(mode) = selected_node_viewport_mode(&state.doc_text, next) {
933 state.viewport_mode = mode.to_string();
934 }

Callers 2

update_editor_shortcutsFunction · 0.85
nav_sidebar_parentFunction · 0.85

Calls 1

refresh_allFunction · 0.85

Tested by

no test coverage detected