Repository: lapce/lapce
File: lapce-ui/src/tab.rs (Rust)

Code before:
                    }
                    LapceUICommand::OpenFile(path, same_tab) => {
                        data.main_split.jump_to_location(
                            ctx,
                            None,
                            *same_tab,
                            EditorLocation {
                                path: path.clone(),
                                position: None::<usize>,
                                scroll_offset: None,
                                history: None,
                            },
                            &data.config,
                        );
                        ctx.set_handled();
                    }
                    LapceUICommand::RevealInFileExplorer(path) => {
                        // TODO: replace with proper implementation from druid that
                        // highlights items in file explorer
                        let path = if path.is_file() {
                            path.parent().unwrap_or_else(|| std::path::Path::new(""))
                        } else {
                            path
                        };
                        let path = path.to_str().unwrap_or("");
                        if !path.is_empty() {
                            ctx.submit_command(Command::new(
                                LAPCE_UI_COMMAND,
                                LapceUICommand::OpenURI(path.to_string()),
                                Target::Auto,
                            ));
                        }
                        ctx.set_handled();
                    }
                    LapceUICommand::GoToLocation(
                        editor_view_id,
                        location,
                        same_tab,
                    ) => {
                        data.main_split.go_to_location(
                            ctx,
                            *editor_view_id,
                            *same_tab,
                            location.clone(),
                            &data.config,
                        );
                        ctx.set_handled();
                    }
                    LapceUICommand::JumpToPosition(
                        editor_view_id,
                        position,

Review comment (suggestion):
This feels a bit clunky to me. Logically, we want to check if the path exists, not that it is not an invalid value. I admit that a double system call (is_file and exists) isn't ideal, but it can be replaced by a single metadata lookup instead.

It's up to you, again, but I think this command handler would look a lot nicer without empty strings.

Code after:
                    }
                    LapceUICommand::OpenFile(path, same_tab) => {
                        data.main_split.jump_to_location(
                            ctx,
                            None,
                            *same_tab,
                            EditorLocation {
                                path: path.clone(),
                                position: None::<usize>,
                                scroll_offset: None,
                                history: None,
                            },
                            &data.config,
                        );
                        ctx.set_handled();
                    }
                    LapceUICommand::RevealInFileExplorer(path) => {
                        // TODO: replace with proper implementation from druid that
                        // highlights items in file explorer
                        let path = match path.parent() {
                            Some(p) => p,
                            None => path,
                        };
                        if path.exists() {
                            ctx.submit_command(Command::new(
                                LAPCE_UI_COMMAND,
                                LapceUICommand::OpenURI(
                                    path.to_str().unwrap().to_string(),
                                ),
                                Target::Auto,
                            ));
                        }
                        ctx.set_handled();
                    }
                    LapceUICommand::GoToLocation(
                        editor_view_id,
                        location,
                        same_tab,
                    ) => {
                        data.main_split.go_to_location(
                            ctx,
                            *editor_view_id,
                            *same_tab,
                            location.clone(),
                            &data.config,
                        );
                        ctx.set_handled();
                    }
                    LapceUICommand::JumpToPosition(
                        editor_view_id,
                        position,