From adc9943b3ad7ad55dfb53a556dd05d90cff085f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8jberg?= Date: Mon, 4 Oct 2021 14:51:25 -0400 Subject: [PATCH] Change the order of items to show code on top Move the code to the top of workspace items and adjust the rules for when the source is folded or not: 1. If the definition is a Doc, fold the source 2. If the definition has a Doc, fold the source 3. Otherwise unfold the source and show it in full --- src/Workspace.elm | 14 +----- src/Workspace/WorkspaceItem.elm | 88 ++++++++++++++++++++++++--------- src/css/workspace-item.css | 2 +- 3 files changed, 67 insertions(+), 37 deletions(-) diff --git a/src/Workspace.elm b/src/Workspace.elm index 65b97a7..18c3aac 100644 --- a/src/Workspace.elm +++ b/src/Workspace.elm @@ -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 diff --git a/src/Workspace/WorkspaceItem.elm b/src/Workspace/WorkspaceItem.elm index 0a50889..cdde70b 100644 --- a/src/Workspace/WorkspaceItem.elm +++ b/src/Workspace/WorkspaceItem.elm @@ -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 @@ -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 @@ -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 @@ -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 -> @@ -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 diff --git a/src/css/workspace-item.css b/src/css/workspace-item.css index ca5d440..8d543c2 100644 --- a/src/css/workspace-item.css +++ b/src/css/workspace-item.css @@ -179,7 +179,6 @@ } .workspace-item .content .workspace-item-definition-doc { - margin-bottom: 1.5rem; padding-left: 1.5rem; width: var(--workspace-content-width); } @@ -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);