Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
72e91d7a
Commit
72e91d7a
authored
Jan 25, 2017
by
Eric Eastwood
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add keyboard shortcut to move to file permalink
Fix
https://gitlab.com/gitlab-org/gitlab-ce/issues/8082
parent
1b273710
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
87 additions
and
32 deletions
+87
-32
app/assets/javascripts/dispatcher.js.es6
app/assets/javascripts/dispatcher.js.es6
+8
-2
app/assets/javascripts/shortcuts_blob.js
app/assets/javascripts/shortcuts_blob.js
+0
-29
app/assets/javascripts/shortcuts_blob.js.es6
app/assets/javascripts/shortcuts_blob.js.es6
+29
-0
app/views/help/_shortcuts.html.haml
app/views/help/_shortcuts.html.haml
+8
-0
app/views/projects/blob/_actions.html.haml
app/views/projects/blob/_actions.html.haml
+1
-1
changelogs/unreleased/8082-permalink-to-file.yml
changelogs/unreleased/8082-permalink-to-file.yml
+4
-0
spec/features/projects/blobs/shortcuts_blob_spec.rb
spec/features/projects/blobs/shortcuts_blob_spec.rb
+37
-0
No files found.
app/assets/javascripts/dispatcher.js.es6
View file @
72e91d7a
...
...
@@ -19,7 +19,6 @@
/* global UsersSelect */
/* global GroupAvatar */
/* global LineHighlighter */
/* global ShortcutsBlob */
/* global ProjectFork */
/* global BuildArtifacts */
/* global GroupsSelect */
...
...
@@ -38,6 +37,8 @@
/* global WeightSelect */
/* global AdminEmailSelect */
const ShortcutsBlob = require('./shortcuts_blob');
(function() {
var Dispatcher;
...
...
@@ -228,7 +229,12 @@
case 'projects:blame:show':
new LineHighlighter();
shortcut_handler = new ShortcutsNavigation();
new ShortcutsBlob(true);
const fileBlobPermalinkUrlElement = document.querySelector('.js-data-file-blob-permalink-url');
const fileBlobPermalinkUrl = fileBlobPermalinkUrlElement && fileBlobPermalinkUrlElement.getAttribute('href');
new ShortcutsBlob({
skipResetBindings: true,
fileBlobPermalinkUrl,
});
break;
case 'groups:labels:new':
case 'groups:labels:edit':
...
...
app/assets/javascripts/shortcuts_blob.js
deleted
100644 → 0
View file @
1b273710
/* eslint-disable func-names, space-before-function-paren, max-len, one-var, no-var, no-restricted-syntax, vars-on-top, no-use-before-define, no-param-reassign, new-cap, no-underscore-dangle, wrap-iife, consistent-return */
/* global Shortcuts */
/* global Mousetrap */
require
(
'
./shortcuts
'
);
(
function
()
{
var
extend
=
function
(
child
,
parent
)
{
for
(
var
key
in
parent
)
{
if
(
hasProp
.
call
(
parent
,
key
))
child
[
key
]
=
parent
[
key
];
}
function
ctor
()
{
this
.
constructor
=
child
;
}
ctor
.
prototype
=
parent
.
prototype
;
child
.
prototype
=
new
ctor
();
child
.
__super__
=
parent
.
prototype
;
return
child
;
},
hasProp
=
{}.
hasOwnProperty
;
this
.
ShortcutsBlob
=
(
function
(
superClass
)
{
extend
(
ShortcutsBlob
,
superClass
);
function
ShortcutsBlob
(
skipResetBindings
)
{
ShortcutsBlob
.
__super__
.
constructor
.
call
(
this
,
skipResetBindings
);
Mousetrap
.
bind
(
'
y
'
,
ShortcutsBlob
.
copyToClipboard
);
}
ShortcutsBlob
.
copyToClipboard
=
function
()
{
var
clipboardButton
;
clipboardButton
=
$
(
'
.btn-clipboard
'
);
if
(
clipboardButton
)
{
return
clipboardButton
.
click
();
}
};
return
ShortcutsBlob
;
})(
Shortcuts
);
}).
call
(
this
);
app/assets/javascripts/shortcuts_blob.js.es6
0 → 100644
View file @
72e91d7a
/* global Mousetrap */
/* global Shortcuts */
require('./shortcuts');
const defaults = {
skipResetBindings: false,
fileBlobPermalinkUrl: null,
};
class ShortcutsBlob extends Shortcuts {
constructor(opts) {
const options = Object.assign({}, defaults, opts);
super(options.skipResetBindings);
this.options = options;
Mousetrap.bind('y', this.moveToFilePermalink.bind(this));
}
moveToFilePermalink() {
if (this.options.fileBlobPermalinkUrl) {
const hash = gl.utils.getLocationHash();
const hashUrlString = hash ? `#${hash}` : '';
gl.utils.visitUrl(`${this.options.fileBlobPermalinkUrl}${hashUrlString}`);
}
}
}
module.exports = ShortcutsBlob;
app/views/help/_shortcuts.html.haml
View file @
72e91d7a
...
...
@@ -79,6 +79,14 @@
%td
.shortcut
.key
esc
%td
Go back
%tbody
%tr
%th
%th
Project File
%tr
%td
.shortcut
.key
y
%td
Go to file permalink
.col-lg-4
%table
.shortcut-mappings
...
...
app/views/projects/blob/_actions.html.haml
View file @
72e91d7a
...
...
@@ -12,7 +12,7 @@
=
link_to
'History'
,
namespace_project_commits_path
(
@project
.
namespace
,
@project
,
@id
),
class:
'btn btn-sm'
=
link_to
'Permalink'
,
namespace_project_blob_path
(
@project
.
namespace
,
@project
,
tree_join
(
@commit
.
sha
,
@path
)),
class:
'btn btn-sm'
tree_join
(
@commit
.
sha
,
@path
)),
class:
'btn btn-sm
js-data-file-blob-permalink-url
'
-
if
current_user
.btn-group
{
role:
"group"
}
...
...
changelogs/unreleased/8082-permalink-to-file.yml
0 → 100644
View file @
72e91d7a
---
title
:
Add `y` keyboard shortcut to move to file permalink
merge_request
:
author
:
spec/features/projects/blobs/shortcuts_blob_spec.rb
0 → 100644
View file @
72e91d7a
require
'spec_helper'
feature
'Blob shortcuts'
,
feature:
true
do
include
TreeHelper
let
(
:project
)
{
create
(
:project
,
:public
,
:repository
)
}
let
(
:path
)
{
project
.
repository
.
ls_files
(
project
.
repository
.
root_ref
)[
0
]
}
let
(
:sha
)
{
project
.
repository
.
commit
.
sha
}
describe
'On a file(blob)'
,
js:
true
do
def
get_absolute_url
(
path
=
""
)
"http://
#{
page
.
server
.
host
}
:
#{
page
.
server
.
port
}#{
path
}
"
end
def
visit_blob
(
fragment
=
nil
)
visit
namespace_project_blob_path
(
project
.
namespace
,
project
,
tree_join
(
'master'
,
path
),
anchor:
fragment
)
end
describe
'pressing "y"'
do
it
'redirects to permalink with commit sha'
do
visit_blob
find
(
'body'
).
native
.
send_key
(
'y'
)
expect
(
page
).
to
have_current_path
(
get_absolute_url
(
namespace_project_blob_path
(
project
.
namespace
,
project
,
tree_join
(
sha
,
path
))),
url:
true
)
end
it
'maintains fragment hash when redirecting'
do
fragment
=
"L1"
visit_blob
(
fragment
)
find
(
'body'
).
native
.
send_key
(
'y'
)
expect
(
page
).
to
have_current_path
(
get_absolute_url
(
namespace_project_blob_path
(
project
.
namespace
,
project
,
tree_join
(
sha
,
path
),
anchor:
fragment
)),
url:
true
)
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment