summaryrefslogtreecommitdiff
path: root/source/features/edit-files-faster.tsx
diff options
context:
space:
mode:
authorGravatar Federico Brigante <github@bfred.it> 2019-04-19 01:36:18 +0800
committerGravatar GitHub <noreply@github.com> 2019-04-19 01:36:18 +0800
commita1658a51352da7bf56fab873cbb81fd6788c0244 (patch)
treee9dea5b7ed90e0fd2c436dffa0684063cdd914e3 /source/features/edit-files-faster.tsx
parent4d293018f258ac9d51fd78bc6ff48da5ecdc274f (diff)
downloadrefined-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.tsx36
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
+});