Skip to content

Commit

Permalink
Add close button to minimap
Browse files Browse the repository at this point in the history
  • Loading branch information
hojberg committed Mar 29, 2024
1 parent 0d88449 commit d8d7826
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
14 changes: 14 additions & 0 deletions src/Code/Workspace.elm
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ type Msg
| WorkspaceItemMsg WorkspaceItem.Msg
| DefinitionSummaryTooltipMsg DefinitionSummaryTooltip.Msg
| SelectItem WorkspaceItem
| CloseItem WorkspaceItem
| CloseAll
| ToggleMinimap

Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -616,6 +629,7 @@ toMinimap model =
{ keyboardShortcut = model.keyboardShortcut
, workspaceItems = model.workspaceItems
, selectItemMsg = SelectItem
, closeItemMsg = CloseItem
, closeAllMsg = CloseAll
, isToggled = model.isMinimapToggled
, toggleMinimapMsg = ToggleMinimap
Expand Down
16 changes: 7 additions & 9 deletions src/Code/Workspace/WorkspaceMinimap.elm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type alias Minimap msg =
, workspaceItems : WorkspaceItems
, selectItemMsg : WorkspaceItem -> msg
, closeAllMsg : msg
, closeItemMsg : WorkspaceItem -> msg
, isToggled : Bool
, toggleMinimapMsg : msg
}
Expand Down Expand Up @@ -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 =
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion src/css/code/workspace-minimap.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions storybook/stories/Stories/Code/WorkspaceMinimap.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -48,6 +49,7 @@ init _ =
|> List.map loadingItem
)
, selectItemMsg = SelectItem
, closeItemMsg = CloseItem
, closeAllMsg = CloseAll
, isToggled = False
, toggleMinimapMsg = ToggleMinimap
Expand Down Expand Up @@ -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 =
Expand Down

0 comments on commit d8d7826

Please sign in to comment.