summaryrefslogtreecommitdiff
path: root/source/features/edit-files-faster.tsx
blob: ae7d46299352ca7ef21232ada72cb062cbf283be (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
31
32
33
34
35
36
37
/*
Edit files straight from a repo’s list by clicking their icon.
*/

import './edit-files-faster.css';
import React from 'dom-chef';
import select from 'select-dom';
import features from '../libs/features';
import * as icons from '../libs/icons';
import {wrap} from '../libs/dom-utils';

function init(): void {
	for (const fileIcon of select.all('.files :not(a) > .octicon-file')) {
		const pathnameParts = fileIcon
			.closest('tr')!
			.querySelector<HTMLAnchorElement>('.js-navigation-open')!
			.pathname
			.split('/');

		pathnameParts[3] = 'edit'; // Replaces `/blob/`

		wrap(fileIcon,
			<a href={pathnameParts.join('/')} className="rgh-edit-files-faster">
				{icons.edit()}
			</a>
		);
	}
}

features.add({
	id: 'edit-files-faster',
	include: [
		features.isRepoTree
	],
	load: features.onFileListUpdate,
	init
});