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

Commit 8d8fe28

Browse files
committed
Add keyboard support to catalog search
When searching through the catalog support keyboard navigation with up and down arrows as well as selection with enter and indexed selection with ; followed by an index number. This mirrors the functionality of the Finder.
1 parent 2251b15 commit 8d8fe28

File tree

8 files changed

+276
-68
lines changed

8 files changed

+276
-68
lines changed

src/Env.elm

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module Env exposing (..)
22

33
import Api exposing (ApiBasePath(..))
4+
import Browser.Navigation as Nav
45
import Env.AppContext as AppContext exposing (AppContext)
56
import Perspective exposing (Perspective)
67

@@ -19,6 +20,7 @@ type alias Env =
1920
, basePath : String
2021
, apiBasePath : ApiBasePath
2122
, appContext : AppContext
23+
, navKey : Nav.Key
2224
, perspective : Perspective
2325
}
2426

@@ -31,12 +33,13 @@ type alias Flags =
3133
}
3234

3335

34-
init : Flags -> Perspective -> Env
35-
init flags perspective =
36+
init : Flags -> Nav.Key -> Perspective -> Env
37+
init flags navKey perspective =
3638
{ operatingSystem = operatingSystemFromString flags.operatingSystem
3739
, basePath = flags.basePath
3840
, apiBasePath = ApiBasePath flags.apiBasePath
3941
, appContext = AppContext.fromString flags.appContext
42+
, navKey = navKey
4043
, perspective = perspective
4144
}
4245

src/SearchResults.elm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module SearchResults exposing
22
( Matches
33
, SearchResults(..)
4+
, empty
45
, focus
56
, focusOn
67
, from
@@ -32,6 +33,11 @@ type SearchResults a
3233
| SearchResults (Matches a)
3334

3435

36+
empty : SearchResults a
37+
empty =
38+
Empty
39+
40+
3541
isEmpty : SearchResults a -> Bool
3642
isEmpty results =
3743
case results of

src/UnisonShare/App.elm

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ import Workspace.WorkspaceItems as WorkspaceItems
4040

4141

4242
type alias Model =
43-
{ navKey : Nav.Key
44-
, route : Route
43+
{ route : Route
4544
, codebaseTree : CodebaseTree.Model
4645
, workspace : Workspace.Model
4746
, perspectiveLanding : PerspectiveLanding.Model
@@ -56,8 +55,8 @@ type alias Model =
5655
}
5756

5857

59-
init : Env -> Route -> Nav.Key -> ( Model, Cmd Msg )
60-
init env route navKey =
58+
init : Env -> Route -> ( Model, Cmd Msg )
59+
init env route =
6160
let
6261
-- TODO: This whole thing should be route driven
6362
( workspace, workspaceCmd ) =
@@ -81,8 +80,7 @@ init env route navKey =
8180
Catalog.init env
8281

8382
model =
84-
{ navKey = navKey
85-
, route = route
83+
{ route = route
8684
, workspace = workspace
8785
, perspectiveLanding = PerspectiveLanding.init
8886
, codebaseTree = codebaseTree
@@ -131,7 +129,7 @@ update msg ({ env } as model) =
131129
( _, LinkClicked urlRequest ) ->
132130
case urlRequest of
133131
Browser.Internal url ->
134-
( model, Nav.pushUrl model.navKey (Url.toString url) )
132+
( model, Nav.pushUrl env.navKey (Url.toString url) )
135133

136134
-- External links are handled via target blank and never end up
137135
-- here
@@ -230,7 +228,7 @@ update msg ({ env } as model) =
230228
( Route.Catalog, CatalogMsg cMsg ) ->
231229
let
232230
( catalog, cmd ) =
233-
Catalog.update cMsg model.catalog
231+
Catalog.update env cMsg model.catalog
234232
in
235233
( { model | catalog = catalog }, Cmd.map CatalogMsg cmd )
236234

@@ -310,7 +308,7 @@ update msg ({ env } as model) =
310308

311309
navigateToDefinition : Model -> Reference -> ( Model, Cmd Msg )
312310
navigateToDefinition model ref =
313-
( model, Route.navigateToDefinition model.navKey model.route ref )
311+
( model, Route.navigateToDefinition model.env.navKey model.route ref )
314312

315313

316314
navigateToPerspective : Model -> Perspective -> ( Model, Cmd Msg )
@@ -330,7 +328,7 @@ navigateToPerspective model perspective =
330328
|> Maybe.withDefault model.route
331329

332330
changeRouteCmd =
333-
Route.replacePerspective model.navKey (Perspective.toParams perspective) focusedReferenceRoute
331+
Route.replacePerspective model.env.navKey (Perspective.toParams perspective) focusedReferenceRoute
334332
in
335333
( { model | workspace = workspace }, changeRouteCmd )
336334

@@ -363,7 +361,7 @@ fetchPerspectiveAndCodebaseTree oldPerspective ({ env } as model) =
363361

364362

365363
handleWorkspaceOutMsg : Model -> Workspace.OutMsg -> ( Model, Cmd Msg )
366-
handleWorkspaceOutMsg model out =
364+
handleWorkspaceOutMsg ({ env } as model) out =
367365
case out of
368366
Workspace.None ->
369367
( model, Cmd.none )
@@ -372,14 +370,14 @@ handleWorkspaceOutMsg model out =
372370
showFinder model withinNamespace
373371

374372
Workspace.Focused ref ->
375-
( model, Route.navigateToDefinition model.navKey model.route ref )
373+
( model, Route.navigateToDefinition env.navKey model.route ref )
376374

377375
Workspace.Emptied ->
378-
( model, Route.navigateToCurrentPerspective model.navKey model.route )
376+
( model, Route.navigateToCurrentPerspective env.navKey model.route )
379377

380378
Workspace.ChangePerspectiveToNamespace fqn ->
381379
fqn
382-
|> Perspective.toNamespacePerspective model.env.perspective
380+
|> Perspective.toNamespacePerspective env.perspective
383381
|> navigateToPerspective model
384382

385383

0 commit comments

Comments
 (0)