1
0
Fork 0

Handle posting draft with ctrl + enter.

This commit is contained in:
Nicolas Perriault 2017-07-17 15:34:42 +02:00
parent 885e0194c5
commit 575f6086cf
No known key found for this signature in database
GPG Key ID: DA5E4C83904F7A2A
5 changed files with 28 additions and 8 deletions

View File

@ -37,6 +37,7 @@ init { registration, clients } location =
, notificationFilter = NotificationAll , notificationFilter = NotificationAll
, confirm = Nothing , confirm = Nothing
, search = Search "" Nothing , search = Search "" Nothing
, ctrlPressed = False
} }
in in
model model

View File

@ -47,7 +47,10 @@ subscriptions { clients, currentView } =
Ports.uploadError (DraftEvent << UploadError) Ports.uploadError (DraftEvent << UploadError)
keyDownsSub = keyDownsSub =
Keyboard.downs KeyMsg Keyboard.downs (KeyMsg KeyDown)
keyUpsSub =
Keyboard.ups (KeyMsg KeyUp)
in in
Sub.batch Sub.batch
[ timeSub [ timeSub

View File

@ -90,6 +90,11 @@ type WebSocketMsg
| NewWebsocketUserMessage String | NewWebsocketUserMessage String
type KeyEvent
= KeyUp
| KeyDown
type Msg type Msg
= AddFavorite Status = AddFavorite Status
| AskConfirm String Msg Msg | AskConfirm String Msg Msg
@ -102,7 +107,7 @@ type Msg
| DraftEvent DraftMsg | DraftEvent DraftMsg
| FilterNotifications NotificationFilter | FilterNotifications NotificationFilter
| FollowAccount Account | FollowAccount Account
| KeyMsg Keyboard.KeyCode | KeyMsg KeyEvent Keyboard.KeyCode
| LogoutClient Client | LogoutClient Client
| TimelineLoadNext String String | TimelineLoadNext String String
| MastodonEvent MastodonMsg | MastodonEvent MastodonMsg
@ -255,6 +260,7 @@ type alias Model =
, notificationFilter : NotificationFilter , notificationFilter : NotificationFilter
, confirm : Maybe Confirm , confirm : Maybe Confirm
, search : Search , search : Search
, ctrlPressed : Bool
} }

View File

@ -55,20 +55,28 @@ update msg model =
} }
! [] ! []
KeyMsg code -> KeyMsg event code ->
case ( code, model.viewer ) of case ( event, code, model.viewer ) of
( 27, Just _ ) -> ( KeyDown, 27, Just _ ) ->
-- Esc -- Esc
update (ViewerEvent CloseViewer) model update (ViewerEvent CloseViewer) model
( 37, Just _ ) -> ( KeyDown, 37, Just _ ) ->
-- Left arrow -- Left arrow
update (ViewerEvent PrevAttachment) model update (ViewerEvent PrevAttachment) model
( 39, Just _ ) -> ( KeyDown, 39, Just _ ) ->
-- Right arrow -- Right arrow
update (ViewerEvent NextAttachment) model update (ViewerEvent NextAttachment) model
( KeyDown, 17, _ ) ->
-- Ctrl key down
{ model | ctrlPressed = True } ! []
( KeyUp, 17, _ ) ->
-- Ctrl key up
{ model | ctrlPressed = False } ! []
_ -> _ ->
model ! [] model ! []

View File

@ -139,7 +139,7 @@ visibilitySelector { visibility } =
draftView : Model -> Html Msg draftView : Model -> Html Msg
draftView ({ draft, currentUser } as model) = draftView ({ draft, currentUser, ctrlPressed } as model) =
let let
autoMenu = autoMenu =
if draft.showAutoMenu then if draft.showAutoMenu then
@ -197,6 +197,8 @@ draftView ({ draft, currentUser } as model) =
Ok NoOp Ok NoOp
else if code == 27 then else if code == 27 then
Ok <| DraftEvent CloseAutocomplete Ok <| DraftEvent CloseAutocomplete
else if code == 13 && ctrlPressed then
Ok SubmitDraft
else else
Err "not handling that key" Err "not handling that key"
) )