From eed42fd2952361f5009fd3fd1578621ac9eff1d2 Mon Sep 17 00:00:00 2001 From: Alexei Anoshenko Date: Thu, 26 May 2022 10:18:11 +0300 Subject: [PATCH] Update viewByID.go --- viewByID.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/viewByID.go b/viewByID.go index 2714c0a..de98db5 100644 --- a/viewByID.go +++ b/viewByID.go @@ -1,5 +1,7 @@ package rui +import "strings" + // ViewByID return a View with id equal to the argument of the function or nil if there is no such View func ViewByID(rootView View, id string) View { if rootView == nil { @@ -9,11 +11,23 @@ func ViewByID(rootView View, id string) View { if rootView.ID() == id { return rootView } + if container, ok := rootView.(ParanetView); ok { if view := viewByID(container, id); view != nil { return view } } + + if index := strings.IndexRune(id, '/'); index > 0 { + if view2 := ViewByID(rootView, id[:index]); view2 != nil { + if view := ViewByID(view2, id[index+1:]); view != nil { + return view + } + return nil + } + return nil + } + ErrorLog(`ViewByID(_, "` + id + `"): View not found`) return nil }