diff options
author | 2019-04-19 01:36:18 +0800 | |
---|---|---|
committer | 2019-04-19 01:36:18 +0800 | |
commit | a1658a51352da7bf56fab873cbb81fd6788c0244 (patch) | |
tree | e9dea5b7ed90e0fd2c436dffa0684063cdd914e3 /source/features/edit-files-faster.tsx | |
parent | 4d293018f258ac9d51fd78bc6ff48da5ecdc274f (diff) | |
download | refined-github-a1658a51352da7bf56fab873cbb81fd6788c0244.tar.gz refined-github-a1658a51352da7bf56fab873cbb81fd6788c0244.tar.zst refined-github-a1658a51352da7bf56fab873cbb81fd6788c0244.zip |
Add `edit-files-faster` feature (#1939)
Diffstat (limited to 'source/features/edit-files-faster.tsx')
-rw-r--r-- | source/features/edit-files-faster.tsx | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/source/features/edit-files-faster.tsx b/source/features/edit-files-faster.tsx new file mode 100644 index 00000000..bce1e325 --- /dev/null +++ b/source/features/edit-files-faster.tsx @@ -0,0 +1,36 @@ +/* +Edit files straight from a repo’s list by clicking their icon. +*/ + +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() { + 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-comments-faster', + include: [ + features.isRepoTree + ], + load: features.onFileListUpdate, + init +}); |