blob: 838e7a89fdc023dff7d58a8f37d4d8f0df506d30 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
import * as pageDetect from 'github-url-detection';
import features from '../feature-manager.js';
import {isEditable} from '../helpers/dom-utils.js';
function isLineSelected(): boolean {
// Example hashes:
// #L1
// #L1-L7
// #diff-1030ad175a393516333e18ea51c415caR1
return /^#L|^#diff-[\da-f]+R\d+/.test(location.hash);
}
function listener({key, target}: KeyboardEvent): void {
if (key === 'Escape' && isLineSelected() && !isEditable(target)) {
location.hash = '#no-line'; // Update UI, without `scroll-to-top` behavior
history.replaceState(undefined, document.title, location.pathname); // Drop remaining # from url
}
}
function init(signal: AbortSignal): void {
document.body.addEventListener('keyup', listener, {signal});
}
void features.add(import.meta.url, {
include: [
pageDetect.hasCode,
],
init,
});
|