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

Commit 755c41c

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 755c41c

File tree

10 files changed

+290
-84
lines changed

10 files changed

+290
-84
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/UnisonLocal/App.elm

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ type Modal
4848

4949

5050
type alias Model =
51-
{ navKey : Nav.Key
52-
, route : Route
51+
{ route : Route
5352
, codebaseTree : CodebaseTree.Model
5453
, workspace : Workspace.Model
5554
, perspectiveLanding : PerspectiveLanding.Model
@@ -63,8 +62,8 @@ type alias Model =
6362
}
6463

6564

66-
init : Env -> Route -> Nav.Key -> ( Model, Cmd Msg )
67-
init env route navKey =
65+
init : Env -> Route -> ( Model, Cmd Msg )
66+
init env route =
6867
let
6968
( workspace, workspaceCmd ) =
7069
case route of
@@ -84,8 +83,7 @@ init env route navKey =
8483
|> Maybe.withDefault Cmd.none
8584

8685
model =
87-
{ navKey = navKey
88-
, route = route
86+
{ route = route
8987
, workspace = workspace
9088
, perspectiveLanding = PerspectiveLanding.init
9189
, codebaseTree = codebaseTree
@@ -132,7 +130,7 @@ update msg ({ env } as model) =
132130
LinkClicked urlRequest ->
133131
case urlRequest of
134132
Browser.Internal url ->
135-
( model, Nav.pushUrl model.navKey (Url.toString url) )
133+
( model, Nav.pushUrl env.navKey (Url.toString url) )
136134

137135
-- External links are handled via target blank and never end up
138136
-- here
@@ -298,7 +296,7 @@ update msg ({ env } as model) =
298296

299297
navigateToDefinition : Model -> Reference -> ( Model, Cmd Msg )
300298
navigateToDefinition model ref =
301-
( model, Route.navigateToDefinition model.navKey model.route ref )
299+
( model, Route.navigateToDefinition model.env.navKey model.route ref )
302300

303301

304302
navigateToPerspective : Model -> Perspective -> ( Model, Cmd Msg )
@@ -318,7 +316,7 @@ navigateToPerspective model perspective =
318316
|> Maybe.withDefault model.route
319317

320318
changeRouteCmd =
321-
Route.replacePerspective model.navKey (Perspective.toParams perspective) focusedReferenceRoute
319+
Route.replacePerspective model.env.navKey (Perspective.toParams perspective) focusedReferenceRoute
322320
in
323321
( { model | workspace = workspace }, changeRouteCmd )
324322

@@ -351,7 +349,7 @@ fetchPerspectiveAndCodebaseTree oldPerspective ({ env } as model) =
351349

352350

353351
handleWorkspaceOutMsg : Model -> Workspace.OutMsg -> ( Model, Cmd Msg )
354-
handleWorkspaceOutMsg model out =
352+
handleWorkspaceOutMsg ({ env } as model) out =
355353
case out of
356354
Workspace.None ->
357355
( model, Cmd.none )
@@ -360,10 +358,10 @@ handleWorkspaceOutMsg model out =
360358
showFinder model withinNamespace
361359

362360
Workspace.Focused ref ->
363-
( model, Route.navigateToDefinition model.navKey model.route ref )
361+
( model, Route.navigateToDefinition env.navKey model.route ref )
364362

365363
Workspace.Emptied ->
366-
( model, Route.navigateToCurrentPerspective model.navKey model.route )
364+
( model, Route.navigateToCurrentPerspective env.navKey model.route )
367365

368366
Workspace.ChangePerspectiveToNamespace fqn ->
369367
fqn

src/UnisonLocal/PreApp.elm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ init flags url navKey =
4242
perspectiveToAppInit perspective =
4343
let
4444
env =
45-
Env.init preEnv.flags perspective
45+
Env.init preEnv.flags preEnv.navKey perspective
4646

4747
( app, cmd ) =
48-
App.init env preEnv.route preEnv.navKey
48+
App.init env preEnv.route
4949
in
5050
( Initialized app, Cmd.map AppMsg cmd )
5151

@@ -79,15 +79,15 @@ update msg model =
7979
Ok perspective ->
8080
let
8181
env =
82-
Env.init preEnv.flags perspective
82+
Env.init preEnv.flags preEnv.navKey perspective
8383

8484
newRoute =
8585
perspective
8686
|> Perspective.toParams
8787
|> Route.updatePerspectiveParams preEnv.route
8888

8989
( app, cmd ) =
90-
App.init env newRoute preEnv.navKey
90+
App.init env newRoute
9191
in
9292
( Initialized app, Cmd.map AppMsg cmd )
9393

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)