From d8d782607a15b4ea94bbc690e63d62da0ea1290e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8jberg?= Date: Fri, 29 Mar 2024 11:11:29 -0400 Subject: [PATCH] Add close button to minimap --- src/Code/Workspace.elm | 14 ++++++++++++++ src/Code/Workspace/WorkspaceMinimap.elm | 16 +++++++--------- src/css/code/workspace-minimap.css | 10 +++++++++- .../stories/Stories/Code/WorkspaceMinimap.elm | 13 +++++++++++++ 4 files changed, 43 insertions(+), 10 deletions(-) diff --git a/src/Code/Workspace.elm b/src/Code/Workspace.elm index 5e364b0a..c1bd8f82 100644 --- a/src/Code/Workspace.elm +++ b/src/Code/Workspace.elm @@ -78,6 +78,7 @@ type Msg | WorkspaceItemMsg WorkspaceItem.Msg | DefinitionSummaryTooltipMsg DefinitionSummaryTooltip.Msg | SelectItem WorkspaceItem + | CloseItem WorkspaceItem | CloseAll | ToggleMinimap @@ -311,6 +312,18 @@ update config viewMode msg ({ workspaceItems } as model) = , openDefinitionsFocusToOutMsg nextWorkspaceItems ) + CloseItem item -> + let + nextWorkspaceItems = + item + |> WorkspaceItem.reference + |> WorkspaceItems.remove model.workspaceItems + in + ( { model | workspaceItems = nextWorkspaceItems } + , Cmd.none + , openDefinitionsFocusToOutMsg nextWorkspaceItems + ) + CloseAll -> let nextWorkspaceItems = @@ -616,6 +629,7 @@ toMinimap model = { keyboardShortcut = model.keyboardShortcut , workspaceItems = model.workspaceItems , selectItemMsg = SelectItem + , closeItemMsg = CloseItem , closeAllMsg = CloseAll , isToggled = model.isMinimapToggled , toggleMinimapMsg = ToggleMinimap diff --git a/src/Code/Workspace/WorkspaceMinimap.elm b/src/Code/Workspace/WorkspaceMinimap.elm index f9039ce5..058d001e 100644 --- a/src/Code/Workspace/WorkspaceMinimap.elm +++ b/src/Code/Workspace/WorkspaceMinimap.elm @@ -25,6 +25,7 @@ type alias Minimap msg = , workspaceItems : WorkspaceItems , selectItemMsg : WorkspaceItem -> msg , closeAllMsg : msg + , closeItemMsg : WorkspaceItem -> msg , isToggled : Bool , toggleMinimapMsg : msg } @@ -53,11 +54,7 @@ viewCollapsed model = [ Button.icon model.toggleMinimapMsg Icon.unfoldedMap |> Button.small |> Button.view - , viewItem - model.selectItemMsg - model.keyboardShortcut - focusIndex - ( item, True ) + , viewItem model focusIndex ( item, True ) ] content = @@ -78,7 +75,7 @@ viewExpanded model = entries = model.workspaceItems |> mapToList Tuple.pair - |> List.indexedMap (viewItem model.selectItemMsg model.keyboardShortcut) + |> List.indexedMap (viewItem model) |> div [ class "workspace-minimap_entries" ] in div @@ -101,8 +98,8 @@ viewHeader toggleMinimapMsg closeAllMsg = ] -viewItem : (WorkspaceItem -> msg) -> KeyboardShortcut.Model -> Int -> ( WorkspaceItem, Bool ) -> Html msg -viewItem selectItem keyboardShortcut index ( item, focused ) = +viewItem : Minimap msg -> Int -> ( WorkspaceItem, Bool ) -> Html msg +viewItem { selectItemMsg, closeItemMsg, keyboardShortcut } index ( item, focused ) = let content = case item of @@ -138,9 +135,10 @@ viewItem selectItem keyboardShortcut index ( item, focused ) = in div [ classList [ ( "workspace-minimap_item", True ), ( "focused", focused ) ] - , onClick (selectItem item) + , onClick (selectItemMsg item) ] [ content + , Button.icon (closeItemMsg item) Icon.x |> Button.small |> Button.subdued |> Button.view , div [ hidden True ] -- currently hidden as feature is not supported yet diff --git a/src/css/code/workspace-minimap.css b/src/css/code/workspace-minimap.css index 590ba4a8..9c3bdd7b 100644 --- a/src/css/code/workspace-minimap.css +++ b/src/css/code/workspace-minimap.css @@ -88,10 +88,14 @@ cursor: pointer; border-radius: var(--border-radius-base); color: var(--c-color_workspace-minimap_text_subdued); - padding: 0 0.5rem; + padding: 0 0.25rem 0 0.5rem; transition: all 0.2s; } +.workspace-minimap_item .button { + display: none; +} + .workspace-minimap_collapsed .workspace-minimap_item { height: 1.5rem; } @@ -100,6 +104,10 @@ background: var(--c-color_workspace-minimap_item_selected); } +.workspace-minimap_expanded .workspace-minimap_item:hover .button { + display: inline-flex; +} + .workspace-minimap_item:not(.focused):hover { background: var(--c-color_workspace-minimap_item_hovered); --u-color_text: var(--c-color_workspace-minimap_interactive); diff --git a/storybook/stories/Stories/Code/WorkspaceMinimap.elm b/storybook/stories/Stories/Code/WorkspaceMinimap.elm index f43555a9..264c52e6 100644 --- a/storybook/stories/Stories/Code/WorkspaceMinimap.elm +++ b/storybook/stories/Stories/Code/WorkspaceMinimap.elm @@ -19,6 +19,7 @@ type alias Model = type Msg = SelectItem WorkspaceItem.WorkspaceItem + | CloseItem WorkspaceItem.WorkspaceItem | CloseAll | ToggleMinimap | GotItem Reference.Reference (Result Http.Error WorkspaceItem.Item) @@ -48,6 +49,7 @@ init _ = |> List.map loadingItem ) , selectItemMsg = SelectItem + , closeItemMsg = CloseItem , closeAllMsg = CloseAll , isToggled = False , toggleMinimapMsg = ToggleMinimap @@ -105,6 +107,17 @@ update message model = , Cmd.none ) + CloseItem item -> + let + nextWorkspaceItems = + item + |> WorkspaceItem.reference + |> WorkspaceItems.remove model.workspaceItems + in + ( { model | workspaceItems = nextWorkspaceItems } + , Cmd.none + ) + CloseAll -> let nextWorkspaceItems =