@@ -27,7 +27,7 @@ import Perspective exposing (Perspective)
2727import Task
2828import UI.Button as Button
2929import UI.Icon as Icon
30- import Workspace.WorkspaceItem as WorkspaceItem exposing (Item , WorkspaceItem (..) )
30+ import Workspace.WorkspaceItem as WorkspaceItem exposing (Item , WorkspaceItem )
3131import Workspace.WorkspaceItems as WorkspaceItems exposing (WorkspaceItems )
3232
3333
@@ -55,7 +55,7 @@ init env mRef =
5555
5656 Just ref ->
5757 let
58- ( m, c, _ ) =
58+ ( m, c ) =
5959 open env model ref
6060 in
6161 ( m, c )
@@ -116,7 +116,7 @@ update env msg ({ workspaceItems } as model) =
116116 in
117117 ( { model | workspaceItems = nextWorkspaceItems }
118118 , cmd
119- , openDefinitionsFocusToOutMsg nextWorkspaceItems
119+ , None
120120 )
121121
122122 IsDocCropped ref res ->
@@ -157,7 +157,7 @@ update env msg ({ workspaceItems } as model) =
157157 WorkspaceItemMsg wiMsg ->
158158 case wiMsg of
159159 WorkspaceItem . OpenReference relativeToRef ref ->
160- openItem env model ( Just relativeToRef) ref
160+ openReference env model relativeToRef ref
161161
162162 WorkspaceItem . Close ref ->
163163 let
@@ -218,11 +218,6 @@ type alias WithWorkspaceItems m =
218218 { m | workspaceItems : WorkspaceItems }
219219
220220
221- open : Env -> WithWorkspaceItems m -> Reference -> ( WithWorkspaceItems m , Cmd Msg , OutMsg )
222- open env model ref =
223- openItem env model Nothing ref
224-
225-
226221replaceWorkspaceItemReferencesWithHashOnly : Model -> Model
227222replaceWorkspaceItemReferencesWithHashOnly model =
228223 let
@@ -232,7 +227,29 @@ replaceWorkspaceItemReferencesWithHashOnly model =
232227 { model | workspaceItems = workspaceItems }
233228
234229
235- openItem : Env -> WithWorkspaceItems m -> Maybe Reference -> Reference -> ( WithWorkspaceItems m , Cmd Msg , OutMsg )
230+ open : Env -> WithWorkspaceItems m -> Reference -> ( WithWorkspaceItems m , Cmd Msg )
231+ open env model ref =
232+ openItem env model Nothing ref
233+
234+
235+ {- | openReference opens a definition relative to another definition. This is
236+ done within Workspace, as opposed to from the outside via a URL change. This
237+ function returns a Focused command for the newly opened reference and as such
238+ changes the URL.
239+ -}
240+ openReference : Env -> WithWorkspaceItems m -> Reference -> Reference -> ( WithWorkspaceItems m , Cmd Msg , OutMsg )
241+ openReference env model relativeToRef ref =
242+ let
243+ ( newModel, cmd ) =
244+ openItem env model ( Just relativeToRef) ref
245+
246+ out =
247+ openDefinitionsFocusToOutMsg newModel. workspaceItems
248+ in
249+ ( newModel, cmd, out )
250+
251+
252+ openItem : Env -> WithWorkspaceItems m -> Maybe Reference -> Reference -> ( WithWorkspaceItems m , Cmd Msg )
236253openItem env ( { workspaceItems } as model) relativeToRef ref =
237254 -- We don't want to refetch or replace any already open definitions, but we
238255 -- do want to focus and scroll to it
@@ -243,7 +260,6 @@ openItem env ({ workspaceItems } as model) relativeToRef ref =
243260 in
244261 ( { model | workspaceItems = nextWorkspaceItems }
245262 , scrollToDefinition ref
246- , openDefinitionsFocusToOutMsg nextWorkspaceItems
247263 )
248264
249265 else
@@ -261,24 +277,14 @@ openItem env ({ workspaceItems } as model) relativeToRef ref =
261277 in
262278 ( { model | workspaceItems = nextWorkspaceItems }
263279 , Cmd . batch [ Api . perform env. apiBasePath ( fetchDefinition env. perspective ref) , scrollToDefinition ref ]
264- , openDefinitionsFocusToOutMsg nextWorkspaceItems
265280 )
266281
267282
268283openDefinitionsFocusToOutMsg : WorkspaceItems -> OutMsg
269284openDefinitionsFocusToOutMsg openDefs =
270- let
271- toFocusedOut workspaceItem =
272- case workspaceItem of
273- Success ref _ ->
274- Focused ref
275-
276- _ ->
277- None
278- in
279285 openDefs
280- |> WorkspaceItems . focus
281- |> Maybe . map toFocusedOut
286+ |> WorkspaceItems . focusedReference
287+ |> Maybe . map Focused
282288 |> Maybe . withDefault Emptied
283289
284290
0 commit comments