Skip to content

Commit 7b775a8

Browse files
authored
Merge pull request matrix-org#4271 from aaronraimist/esc-mark-as-read
Mark room as read when escape is pressed
2 parents e56ce8d + 73e5f13 commit 7b775a8

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

src/components/structures/RoomView.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ export default createReactClass({
425425
}
426426
this.onResize();
427427

428-
document.addEventListener("keydown", this.onKeyDown);
428+
document.addEventListener("keydown", this.onNativeKeyDown);
429429
},
430430

431431
shouldComponentUpdate: function(nextProps, nextState) {
@@ -508,7 +508,7 @@ export default createReactClass({
508508
this.props.resizeNotifier.removeListener("middlePanelResized", this.onResize);
509509
}
510510

511-
document.removeEventListener("keydown", this.onKeyDown);
511+
document.removeEventListener("keydown", this.onNativeKeyDown);
512512

513513
// Remove RoomStore listener
514514
if (this._roomStoreToken) {
@@ -550,7 +550,8 @@ export default createReactClass({
550550
}
551551
},
552552

553-
onKeyDown: function(ev) {
553+
// we register global shortcuts here, they *must not conflict* with local shortcuts elsewhere or both will fire
554+
onNativeKeyDown: function(ev) {
554555
let handled = false;
555556
const ctrlCmdOnly = isOnlyCtrlOrCmdKeyEvent(ev);
556557

@@ -576,6 +577,25 @@ export default createReactClass({
576577
}
577578
},
578579

580+
onReactKeyDown: function(ev) {
581+
let handled = false;
582+
583+
switch (ev.key) {
584+
case Key.ESCAPE:
585+
if (!ev.altKey && !ev.ctrlKey && !ev.shiftKey && !ev.metaKey) {
586+
this._messagePanel.forgetReadMarker();
587+
this.jumpToLiveTimeline();
588+
handled = true;
589+
}
590+
break;
591+
}
592+
593+
if (handled) {
594+
ev.stopPropagation();
595+
ev.preventDefault();
596+
}
597+
},
598+
579599
onAction: function(payload) {
580600
switch (payload.action) {
581601
case 'message_send_failed':
@@ -2008,9 +2028,13 @@ export default createReactClass({
20082028
mx_RoomView_timeline_rr_enabled: this.state.showReadReceipts,
20092029
});
20102030

2031+
const mainClasses = classNames("mx_RoomView", {
2032+
mx_RoomView_inCall: inCall,
2033+
});
2034+
20112035
return (
20122036
<RoomContext.Provider value={this.state}>
2013-
<main className={"mx_RoomView" + (inCall ? " mx_RoomView_inCall" : "")} ref={this._roomView}>
2037+
<main className={mainClasses} ref={this._roomView} onKeyDown={this.onReactKeyDown}>
20142038
<ErrorBoundary>
20152039
<RoomHeader
20162040
room={this.state.room}

0 commit comments

Comments
 (0)