diff --git a/src/Init.elm b/src/Init.elm index d4b6770..ced0081 100644 --- a/src/Init.elm +++ b/src/Init.elm @@ -37,6 +37,7 @@ init { registration, clients } location = , notificationFilter = NotificationAll , confirm = Nothing , search = Search "" Nothing + , ctrlPressed = False } in model diff --git a/src/Subscription.elm b/src/Subscription.elm index fe16ecc..7aa6930 100644 --- a/src/Subscription.elm +++ b/src/Subscription.elm @@ -47,7 +47,10 @@ subscriptions { clients, currentView } = Ports.uploadError (DraftEvent << UploadError) keyDownsSub = - Keyboard.downs KeyMsg + Keyboard.downs (KeyMsg KeyDown) + + keyUpsSub = + Keyboard.ups (KeyMsg KeyUp) in Sub.batch [ timeSub diff --git a/src/Types.elm b/src/Types.elm index c387111..67df36e 100644 --- a/src/Types.elm +++ b/src/Types.elm @@ -90,6 +90,11 @@ type WebSocketMsg | NewWebsocketUserMessage String +type KeyEvent + = KeyUp + | KeyDown + + type Msg = AddFavorite Status | AskConfirm String Msg Msg @@ -102,7 +107,7 @@ type Msg | DraftEvent DraftMsg | FilterNotifications NotificationFilter | FollowAccount Account - | KeyMsg Keyboard.KeyCode + | KeyMsg KeyEvent Keyboard.KeyCode | LogoutClient Client | TimelineLoadNext String String | MastodonEvent MastodonMsg @@ -255,6 +260,7 @@ type alias Model = , notificationFilter : NotificationFilter , confirm : Maybe Confirm , search : Search + , ctrlPressed : Bool } diff --git a/src/Update/Main.elm b/src/Update/Main.elm index 309573e..d4a0464 100644 --- a/src/Update/Main.elm +++ b/src/Update/Main.elm @@ -55,20 +55,28 @@ update msg model = } ! [] - KeyMsg code -> - case ( code, model.viewer ) of - ( 27, Just _ ) -> + KeyMsg event code -> + case ( event, code, model.viewer ) of + ( KeyDown, 27, Just _ ) -> -- Esc update (ViewerEvent CloseViewer) model - ( 37, Just _ ) -> + ( KeyDown, 37, Just _ ) -> -- Left arrow update (ViewerEvent PrevAttachment) model - ( 39, Just _ ) -> + ( KeyDown, 39, Just _ ) -> -- Right arrow update (ViewerEvent NextAttachment) model + ( KeyDown, 17, _ ) -> + -- Ctrl key down + { model | ctrlPressed = True } ! [] + + ( KeyUp, 17, _ ) -> + -- Ctrl key up + { model | ctrlPressed = False } ! [] + _ -> model ! [] diff --git a/src/View/Draft.elm b/src/View/Draft.elm index 73bd136..8a89dd7 100644 --- a/src/View/Draft.elm +++ b/src/View/Draft.elm @@ -139,7 +139,7 @@ visibilitySelector { visibility } = draftView : Model -> Html Msg -draftView ({ draft, currentUser } as model) = +draftView ({ draft, currentUser, ctrlPressed } as model) = let autoMenu = if draft.showAutoMenu then @@ -197,6 +197,8 @@ draftView ({ draft, currentUser } as model) = Ok NoOp else if code == 27 then Ok <| DraftEvent CloseAutocomplete + else if code == 13 && ctrlPressed then + Ok SubmitDraft else Err "not handling that key" )