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

Change the order of items to show code on top #234

Merged
merged 1 commit into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions src/Workspace.elm
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,7 @@ update env msg ({ workspaceItems } as model) =
WorkspaceItem.Failure ref e

Ok i ->
let
zoom =
if WorkspaceItem.isDocItem i then
Zoom.Medium

else
Zoom.Near
in
WorkspaceItem.Success ref
{ item = i
, zoom = zoom
, docFoldToggles = Doc.emptyDocFoldToggles
}
WorkspaceItem.fromItem ref i

nextWorkspaceItems =
WorkspaceItems.replace workspaceItems ref workspaceItem
Expand Down
88 changes: 65 additions & 23 deletions src/Workspace/WorkspaceItem.elm
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,23 @@ type WorkspaceItem
}


type alias WithDoc =
{ doc : Maybe Doc }


type alias TermDetailWithDoc =
TermDetail { doc : Maybe Doc }
TermDetail WithDoc


type alias TypeDetailWithDoc =
TypeDetail { doc : Maybe Doc }
TypeDetail WithDoc


type Item
= TermItem TermDetailWithDoc
| TypeItem TypeDetailWithDoc
-- TODO: DataConstructorItem and AbilityConstructorItem are currently not
-- rendered separate from TypeItem
| DataConstructorItem DataConstructorDetail
| AbilityConstructorItem AbilityConstructorDetail

Expand All @@ -66,6 +72,27 @@ type Msg
| FindWithinNamespace FQN


fromItem : Reference -> Item -> WorkspaceItem
fromItem ref item =
let
zoom =
-- Doc items always have docs
if isDocItem item then
Medium

else if hasDoc item then
Medium

else
Near
in
Success ref
{ item = item
, zoom = zoom
, docFoldToggles = Doc.emptyDocFoldToggles
}


reference : WorkspaceItem -> Reference
reference item =
case item of
Expand Down Expand Up @@ -99,6 +126,23 @@ isDocItem item =
False


hasDoc : Item -> Bool
hasDoc item =
let
hasDoc_ details =
MaybeE.isJust details.doc
in
case item of
TermItem (Term _ _ d) ->
hasDoc_ d

TypeItem (Type _ _ d) ->
hasDoc_ d

_ ->
False



-- VIEW

Expand Down Expand Up @@ -289,7 +333,6 @@ viewItem :
-> Html Msg
viewItem ref data isFocused =
let
-- TODO: Support zoom level on the source
( zoomClass, infoZoomToggle, sourceZoomToggle ) =
case data.zoom of
Far ->
Expand All @@ -304,52 +347,51 @@ viewItem ref data isFocused =
attrs =
[ class zoomClass, classList [ ( "focused", isFocused ) ] ]

sourceConfig =
Source.Rich (OpenReference ref)

viewDoc_ doc =
doc
|> Maybe.map (viewDoc ref data.docFoldToggles)
|> Maybe.withDefault UI.nothing

sourceConfig =
Source.Rich (OpenReference ref)
viewContent doc =
[ viewSource data.zoom sourceZoomToggle sourceConfig data.item
, ( UI.nothing, viewBuiltin data.item )
, ( UI.nothing, viewDoc_ doc )
]

viewInfo_ hash_ info cat =
viewInfo data.zoom infoZoomToggle hash_ info cat
in
case data.item of
TermItem (Term h category detail) ->
viewClosableRow
ref
attrs
(viewInfo data.zoom infoZoomToggle h detail.info (Category.Term category))
[ ( UI.nothing, viewDoc_ detail.doc )
, ( UI.nothing, viewBuiltin data.item )
, viewSource data.zoom sourceZoomToggle sourceConfig data.item
]
(viewInfo_ h detail.info (Category.Term category))
(viewContent detail.doc)

TypeItem (Type h category detail) ->
viewClosableRow
ref
attrs
(viewInfo data.zoom infoZoomToggle h detail.info (Category.Type category))
[ ( UI.nothing, viewDoc_ detail.doc )
, ( UI.nothing, viewBuiltin data.item )
, viewSource data.zoom sourceZoomToggle sourceConfig data.item
]
(viewInfo_ h detail.info (Category.Type category))
(viewContent detail.doc)

DataConstructorItem (DataConstructor h detail) ->
viewClosableRow
ref
attrs
(viewInfo data.zoom infoZoomToggle h detail.info (Category.Type Type.DataType))
[ ( UI.nothing, viewBuiltin data.item )
, viewSource data.zoom sourceZoomToggle sourceConfig data.item
]
(viewInfo_ h detail.info (Category.Type Type.DataType))
(viewContent Nothing)

AbilityConstructorItem (AbilityConstructor h detail) ->
viewClosableRow
ref
attrs
(viewInfo data.zoom infoZoomToggle h detail.info (Category.Type Type.AbilityType))
[ ( UI.nothing, viewBuiltin data.item )
, viewSource data.zoom sourceZoomToggle sourceConfig data.item
]
(viewInfo_ h detail.info (Category.Type Type.AbilityType))
(viewContent Nothing)


view : WorkspaceItem -> Bool -> Html Msg
Expand Down
2 changes: 1 addition & 1 deletion src/css/workspace-item.css
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@
}

.workspace-item .content .workspace-item-definition-doc {
margin-bottom: 1.5rem;
padding-left: 1.5rem;
width: var(--workspace-content-width);
}
Expand All @@ -196,6 +195,7 @@
.workspace-item .content .definition-source {
position: relative;
padding-left: 1.5rem;
margin-bottom: 1.5rem;
display: flex;
flex-direction: row;
background: var(--color-workspace-item-source-bg);
Expand Down