Skip to content
This repository was archived by the owner on Jul 19, 2022. It is now read-only.

Commit f184b84

Browse files
authored
Merge pull request #234 from unisonweb/code-on-top
Change the order of items to show code on top
2 parents 882505c + adc9943 commit f184b84

File tree

3 files changed

+67
-37
lines changed

3 files changed

+67
-37
lines changed

src/Workspace.elm

+1-13
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,7 @@ update env msg ({ workspaceItems } as model) =
9898
WorkspaceItem.Failure ref e
9999

100100
Ok i ->
101-
let
102-
zoom =
103-
if WorkspaceItem.isDocItem i then
104-
Zoom.Medium
105-
106-
else
107-
Zoom.Near
108-
in
109-
WorkspaceItem.Success ref
110-
{ item = i
111-
, zoom = zoom
112-
, docFoldToggles = Doc.emptyDocFoldToggles
113-
}
101+
WorkspaceItem.fromItem ref i
114102

115103
nextWorkspaceItems =
116104
WorkspaceItems.replace workspaceItems ref workspaceItem

src/Workspace/WorkspaceItem.elm

+65-23
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,23 @@ type WorkspaceItem
4040
}
4141

4242

43+
type alias WithDoc =
44+
{ doc : Maybe Doc }
45+
46+
4347
type alias TermDetailWithDoc =
44-
TermDetail { doc : Maybe Doc }
48+
TermDetail WithDoc
4549

4650

4751
type alias TypeDetailWithDoc =
48-
TypeDetail { doc : Maybe Doc }
52+
TypeDetail WithDoc
4953

5054

5155
type Item
5256
= TermItem TermDetailWithDoc
5357
| TypeItem TypeDetailWithDoc
58+
-- TODO: DataConstructorItem and AbilityConstructorItem are currently not
59+
-- rendered separate from TypeItem
5460
| DataConstructorItem DataConstructorDetail
5561
| AbilityConstructorItem AbilityConstructorDetail
5662

@@ -66,6 +72,27 @@ type Msg
6672
| FindWithinNamespace FQN
6773

6874

75+
fromItem : Reference -> Item -> WorkspaceItem
76+
fromItem ref item =
77+
let
78+
zoom =
79+
-- Doc items always have docs
80+
if isDocItem item then
81+
Medium
82+
83+
else if hasDoc item then
84+
Medium
85+
86+
else
87+
Near
88+
in
89+
Success ref
90+
{ item = item
91+
, zoom = zoom
92+
, docFoldToggles = Doc.emptyDocFoldToggles
93+
}
94+
95+
6996
reference : WorkspaceItem -> Reference
7097
reference item =
7198
case item of
@@ -99,6 +126,23 @@ isDocItem item =
99126
False
100127

101128

129+
hasDoc : Item -> Bool
130+
hasDoc item =
131+
let
132+
hasDoc_ details =
133+
MaybeE.isJust details.doc
134+
in
135+
case item of
136+
TermItem (Term _ _ d) ->
137+
hasDoc_ d
138+
139+
TypeItem (Type _ _ d) ->
140+
hasDoc_ d
141+
142+
_ ->
143+
False
144+
145+
102146

103147
-- VIEW
104148

@@ -289,7 +333,6 @@ viewItem :
289333
-> Html Msg
290334
viewItem ref data isFocused =
291335
let
292-
-- TODO: Support zoom level on the source
293336
( zoomClass, infoZoomToggle, sourceZoomToggle ) =
294337
case data.zoom of
295338
Far ->
@@ -304,52 +347,51 @@ viewItem ref data isFocused =
304347
attrs =
305348
[ class zoomClass, classList [ ( "focused", isFocused ) ] ]
306349

350+
sourceConfig =
351+
Source.Rich (OpenReference ref)
352+
307353
viewDoc_ doc =
308354
doc
309355
|> Maybe.map (viewDoc ref data.docFoldToggles)
310356
|> Maybe.withDefault UI.nothing
311357

312-
sourceConfig =
313-
Source.Rich (OpenReference ref)
358+
viewContent doc =
359+
[ viewSource data.zoom sourceZoomToggle sourceConfig data.item
360+
, ( UI.nothing, viewBuiltin data.item )
361+
, ( UI.nothing, viewDoc_ doc )
362+
]
363+
364+
viewInfo_ hash_ info cat =
365+
viewInfo data.zoom infoZoomToggle hash_ info cat
314366
in
315367
case data.item of
316368
TermItem (Term h category detail) ->
317369
viewClosableRow
318370
ref
319371
attrs
320-
(viewInfo data.zoom infoZoomToggle h detail.info (Category.Term category))
321-
[ ( UI.nothing, viewDoc_ detail.doc )
322-
, ( UI.nothing, viewBuiltin data.item )
323-
, viewSource data.zoom sourceZoomToggle sourceConfig data.item
324-
]
372+
(viewInfo_ h detail.info (Category.Term category))
373+
(viewContent detail.doc)
325374

326375
TypeItem (Type h category detail) ->
327376
viewClosableRow
328377
ref
329378
attrs
330-
(viewInfo data.zoom infoZoomToggle h detail.info (Category.Type category))
331-
[ ( UI.nothing, viewDoc_ detail.doc )
332-
, ( UI.nothing, viewBuiltin data.item )
333-
, viewSource data.zoom sourceZoomToggle sourceConfig data.item
334-
]
379+
(viewInfo_ h detail.info (Category.Type category))
380+
(viewContent detail.doc)
335381

336382
DataConstructorItem (DataConstructor h detail) ->
337383
viewClosableRow
338384
ref
339385
attrs
340-
(viewInfo data.zoom infoZoomToggle h detail.info (Category.Type Type.DataType))
341-
[ ( UI.nothing, viewBuiltin data.item )
342-
, viewSource data.zoom sourceZoomToggle sourceConfig data.item
343-
]
386+
(viewInfo_ h detail.info (Category.Type Type.DataType))
387+
(viewContent Nothing)
344388

345389
AbilityConstructorItem (AbilityConstructor h detail) ->
346390
viewClosableRow
347391
ref
348392
attrs
349-
(viewInfo data.zoom infoZoomToggle h detail.info (Category.Type Type.AbilityType))
350-
[ ( UI.nothing, viewBuiltin data.item )
351-
, viewSource data.zoom sourceZoomToggle sourceConfig data.item
352-
]
393+
(viewInfo_ h detail.info (Category.Type Type.AbilityType))
394+
(viewContent Nothing)
353395

354396

355397
view : WorkspaceItem -> Bool -> Html Msg

src/css/workspace-item.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@
179179
}
180180

181181
.workspace-item .content .workspace-item-definition-doc {
182-
margin-bottom: 1.5rem;
183182
padding-left: 1.5rem;
184183
width: var(--workspace-content-width);
185184
}
@@ -196,6 +195,7 @@
196195
.workspace-item .content .definition-source {
197196
position: relative;
198197
padding-left: 1.5rem;
198+
margin-bottom: 1.5rem;
199199
display: flex;
200200
flex-direction: row;
201201
background: var(--color-workspace-item-source-bg);

0 commit comments

Comments
 (0)