Handle posting draft with ctrl + enter.
This commit is contained in:
parent
885e0194c5
commit
575f6086cf
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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 ! []
|
||||||
|
|
||||||
|
|
|
@ -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"
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue