@@ -27,7 +27,7 @@ import Perspective exposing (Perspective)
27
27
import Task
28
28
import UI.Button as Button
29
29
import UI.Icon as Icon
30
- import Workspace.WorkspaceItem as WorkspaceItem exposing (Item , WorkspaceItem (..) )
30
+ import Workspace.WorkspaceItem as WorkspaceItem exposing (Item , WorkspaceItem )
31
31
import Workspace.WorkspaceItems as WorkspaceItems exposing (WorkspaceItems )
32
32
33
33
@@ -55,7 +55,7 @@ init env mRef =
55
55
56
56
Just ref ->
57
57
let
58
- ( m, c, _ ) =
58
+ ( m, c ) =
59
59
open env model ref
60
60
in
61
61
( m, c )
@@ -116,7 +116,7 @@ update env msg ({ workspaceItems } as model) =
116
116
in
117
117
( { model | workspaceItems = nextWorkspaceItems }
118
118
, cmd
119
- , openDefinitionsFocusToOutMsg nextWorkspaceItems
119
+ , None
120
120
)
121
121
122
122
IsDocCropped ref res ->
@@ -157,7 +157,7 @@ update env msg ({ workspaceItems } as model) =
157
157
WorkspaceItemMsg wiMsg ->
158
158
case wiMsg of
159
159
WorkspaceItem . OpenReference relativeToRef ref ->
160
- openItem env model ( Just relativeToRef) ref
160
+ openReference env model relativeToRef ref
161
161
162
162
WorkspaceItem . Close ref ->
163
163
let
@@ -218,11 +218,6 @@ type alias WithWorkspaceItems m =
218
218
{ m | workspaceItems : WorkspaceItems }
219
219
220
220
221
- open : Env -> WithWorkspaceItems m -> Reference -> ( WithWorkspaceItems m , Cmd Msg , OutMsg )
222
- open env model ref =
223
- openItem env model Nothing ref
224
-
225
-
226
221
replaceWorkspaceItemReferencesWithHashOnly : Model -> Model
227
222
replaceWorkspaceItemReferencesWithHashOnly model =
228
223
let
@@ -232,7 +227,29 @@ replaceWorkspaceItemReferencesWithHashOnly model =
232
227
{ model | workspaceItems = workspaceItems }
233
228
234
229
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 )
236
253
openItem env ( { workspaceItems } as model) relativeToRef ref =
237
254
-- We don't want to refetch or replace any already open definitions, but we
238
255
-- do want to focus and scroll to it
@@ -243,7 +260,6 @@ openItem env ({ workspaceItems } as model) relativeToRef ref =
243
260
in
244
261
( { model | workspaceItems = nextWorkspaceItems }
245
262
, scrollToDefinition ref
246
- , openDefinitionsFocusToOutMsg nextWorkspaceItems
247
263
)
248
264
249
265
else
@@ -261,24 +277,14 @@ openItem env ({ workspaceItems } as model) relativeToRef ref =
261
277
in
262
278
( { model | workspaceItems = nextWorkspaceItems }
263
279
, Cmd . batch [ Api . perform env. apiBasePath ( fetchDefinition env. perspective ref) , scrollToDefinition ref ]
264
- , openDefinitionsFocusToOutMsg nextWorkspaceItems
265
280
)
266
281
267
282
268
283
openDefinitionsFocusToOutMsg : WorkspaceItems -> OutMsg
269
284
openDefinitionsFocusToOutMsg openDefs =
270
- let
271
- toFocusedOut workspaceItem =
272
- case workspaceItem of
273
- Success ref _ ->
274
- Focused ref
275
-
276
- _ ->
277
- None
278
- in
279
285
openDefs
280
- |> WorkspaceItems . focus
281
- |> Maybe . map toFocusedOut
286
+ |> WorkspaceItems . focusedReference
287
+ |> Maybe . map Focused
282
288
|> Maybe . withDefault Emptied
283
289
284
290
0 commit comments