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
299da4ca
Commit
299da4ca
authored
Oct 10, 2017
by
Phil Hughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove shortcut JS classes from global namespace
parent
5843a43c
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
239 additions
and
317 deletions
+239
-317
app/assets/javascripts/dispatcher.js
app/assets/javascripts/dispatcher.js
+4
-5
app/assets/javascripts/main.js
app/assets/javascripts/main.js
+0
-9
app/assets/javascripts/network/network_bundle.js
app/assets/javascripts/network/network_bundle.js
+1
-1
app/assets/javascripts/shortcuts.js
app/assets/javascripts/shortcuts.js
+106
-118
app/assets/javascripts/shortcuts_blob.js
app/assets/javascripts/shortcuts_blob.js
+1
-2
app/assets/javascripts/shortcuts_find_file.js
app/assets/javascripts/shortcuts_find_file.js
+24
-32
app/assets/javascripts/shortcuts_issuable.js
app/assets/javascripts/shortcuts_issuable.js
+65
-91
app/assets/javascripts/shortcuts_navigation.js
app/assets/javascripts/shortcuts_navigation.js
+21
-30
app/assets/javascripts/shortcuts_network.js
app/assets/javascripts/shortcuts_network.js
+13
-24
app/assets/javascripts/shortcuts_wiki.js
app/assets/javascripts/shortcuts_wiki.js
+1
-1
spec/javascripts/shortcuts_issuable_spec.js
spec/javascripts/shortcuts_issuable_spec.js
+1
-3
spec/javascripts/shortcuts_spec.js
spec/javascripts/shortcuts_spec.js
+2
-1
No files found.
app/assets/javascripts/dispatcher.js
View file @
299da4ca
/* eslint-disable func-names, space-before-function-paren, no-var, prefer-arrow-callback, wrap-iife, no-shadow, consistent-return, one-var, one-var-declaration-per-line, camelcase, default-case, no-new, quotes, no-duplicate-case, no-case-declarations, no-fallthrough, max-len */
/* global ProjectSelect */
/* global ShortcutsNavigation */
/* global IssuableIndex */
/* global ShortcutsIssuable */
/* global Milestone */
/* global IssuableForm */
/* global LabelsSelect */
...
...
@@ -31,10 +29,7 @@ import CILintEditor from './ci_lint_editor';
/* global ProjectImport */
import
Labels
from
'
./labels
'
;
import
LabelManager
from
'
./label_manager
'
;
/* global Shortcuts */
/* global ShortcutsFindFile */
/* global Sidebar */
/* global ShortcutsWiki */
import
CommitsList
from
'
./commits
'
;
import
Issue
from
'
./issue
'
;
...
...
@@ -83,6 +78,10 @@ import { ajaxGet, convertPermissionToBoolean } from './lib/utils/common_utils';
import
AjaxLoadingSpinner
from
'
./ajax_loading_spinner
'
;
import
GlFieldErrors
from
'
./gl_field_errors
'
;
import
GLForm
from
'
./gl_form
'
;
import
Shortcuts
from
'
./shortcuts
'
;
import
ShortcutsNavigation
from
'
./shortcuts_navigation
'
;
import
ShortcutsFindFile
from
'
./shortcuts_find_file
'
;
import
ShortcutsIssuable
from
'
./shortcuts_issuable
'
;
import
U2FAuthenticate
from
'
./u2f/authenticate
'
;
import
Members
from
'
./members
'
;
import
memberExpirationDate
from
'
./member_expiration_date
'
;
...
...
app/assets/javascripts/main.js
View file @
299da4ca
...
...
@@ -21,15 +21,6 @@ window._ = _;
window
.
Dropzone
=
Dropzone
;
window
.
Sortable
=
Sortable
;
// shortcuts
import
'
./shortcuts
'
;
import
'
./shortcuts_blob
'
;
import
'
./shortcuts_dashboard_navigation
'
;
import
'
./shortcuts_navigation
'
;
import
'
./shortcuts_find_file
'
;
import
'
./shortcuts_issuable
'
;
import
'
./shortcuts_network
'
;
// templates
import
'
./templates/issuable_template_selector
'
;
import
'
./templates/issuable_template_selectors
'
;
...
...
app/assets/javascripts/network/network_bundle.js
View file @
299da4ca
/* eslint-disable func-names, space-before-function-paren, prefer-arrow-callback, quotes, no-var, vars-on-top, camelcase, comma-dangle, consistent-return, max-len */
/* global ShortcutsNetwork */
import
ShortcutsNetwork
from
'
../shortcuts_network
'
;
import
Network
from
'
./network
'
;
$
(
function
()
{
...
...
app/assets/javascripts/shortcuts.js
View file @
299da4ca
/* eslint-disable func-names, space-before-function-paren, no-var, prefer-rest-params, wrap-iife, quotes, prefer-arrow-callback, consistent-return, object-shorthand, no-unused-vars, one-var, one-var-declaration-per-line, no-else-return, comma-dangle, max-len */
/* global Mousetrap */
import
Cookies
from
'
js-cookie
'
;
import
Mousetrap
from
'
mousetrap
'
;
import
findAndFollowLink
from
'
./shortcuts_dashboard_navigation
'
;
(
function
()
{
this
.
Shortcuts
=
(
function
()
{
function
Shortcuts
(
skipResetBindings
)
{
this
.
onToggleHelp
=
this
.
onToggleHelp
.
bind
(
this
);
this
.
enabledHelp
=
[];
if
(
!
skipResetBindings
)
{
Mousetrap
.
reset
();
}
Mousetrap
.
bind
(
'
?
'
,
this
.
onToggleHelp
);
Mousetrap
.
bind
(
'
s
'
,
Shortcuts
.
focusSearch
);
Mousetrap
.
bind
(
'
f
'
,
(
e
=>
this
.
focusFilter
(
e
)));
Mousetrap
.
bind
(
'
p b
'
,
this
.
onTogglePerfBar
);
const
findFileURL
=
document
.
body
.
dataset
.
findFile
;
Mousetrap
.
bind
(
'
shift+t
'
,
()
=>
findAndFollowLink
(
'
.shortcuts-todos
'
));
Mousetrap
.
bind
(
'
shift+a
'
,
()
=>
findAndFollowLink
(
'
.dashboard-shortcuts-activity
'
));
Mousetrap
.
bind
(
'
shift+i
'
,
()
=>
findAndFollowLink
(
'
.dashboard-shortcuts-issues
'
));
Mousetrap
.
bind
(
'
shift+m
'
,
()
=>
findAndFollowLink
(
'
.dashboard-shortcuts-merge_requests
'
));
Mousetrap
.
bind
(
'
shift+p
'
,
()
=>
findAndFollowLink
(
'
.dashboard-shortcuts-projects
'
));
Mousetrap
.
bind
(
'
shift+g
'
,
()
=>
findAndFollowLink
(
'
.dashboard-shortcuts-groups
'
));
Mousetrap
.
bind
(
'
shift+l
'
,
()
=>
findAndFollowLink
(
'
.dashboard-shortcuts-milestones
'
));
Mousetrap
.
bind
(
'
shift+s
'
,
()
=>
findAndFollowLink
(
'
.dashboard-shortcuts-snippets
'
));
Mousetrap
.
bind
([
'
ctrl+shift+p
'
,
'
command+shift+p
'
],
this
.
toggleMarkdownPreview
);
if
(
typeof
findFileURL
!==
"
undefined
"
&&
findFileURL
!==
null
)
{
Mousetrap
.
bind
(
'
t
'
,
function
()
{
return
gl
.
utils
.
visitUrl
(
findFileURL
);
});
}
const
defaultStopCallback
=
Mousetrap
.
stopCallback
;
Mousetrap
.
stopCallback
=
(
e
,
element
,
combo
)
=>
{
if
([
'
ctrl+shift+p
'
,
'
command+shift+p
'
].
indexOf
(
combo
)
!==
-
1
)
{
return
false
;
}
return
defaultStopCallback
(
e
,
element
,
combo
);
};
export
default
class
Shortcuts
{
constructor
(
skipResetBindings
)
{
this
.
onToggleHelp
=
this
.
onToggleHelp
.
bind
(
this
);
this
.
enabledHelp
=
[];
if
(
!
skipResetBindings
)
{
Mousetrap
.
reset
();
}
Mousetrap
.
bind
(
'
?
'
,
this
.
onToggleHelp
);
Mousetrap
.
bind
(
'
s
'
,
Shortcuts
.
focusSearch
);
Mousetrap
.
bind
(
'
f
'
,
this
.
focusFilter
.
bind
(
this
));
Mousetrap
.
bind
(
'
p b
'
,
Shortcuts
.
onTogglePerfBar
);
Shortcuts
.
prototype
.
onToggleHelp
=
function
(
e
)
{
e
.
preventDefault
();
return
Shortcuts
.
toggleHelp
(
this
.
enabledHelp
);
};
const
findFileURL
=
document
.
body
.
dataset
.
findFile
;
Mousetrap
.
bind
(
'
shift+t
'
,
()
=>
findAndFollowLink
(
'
.shortcuts-todos
'
));
Mousetrap
.
bind
(
'
shift+a
'
,
()
=>
findAndFollowLink
(
'
.dashboard-shortcuts-activity
'
));
Mousetrap
.
bind
(
'
shift+i
'
,
()
=>
findAndFollowLink
(
'
.dashboard-shortcuts-issues
'
));
Mousetrap
.
bind
(
'
shift+m
'
,
()
=>
findAndFollowLink
(
'
.dashboard-shortcuts-merge_requests
'
));
Mousetrap
.
bind
(
'
shift+p
'
,
()
=>
findAndFollowLink
(
'
.dashboard-shortcuts-projects
'
));
Mousetrap
.
bind
(
'
shift+g
'
,
()
=>
findAndFollowLink
(
'
.dashboard-shortcuts-groups
'
));
Mousetrap
.
bind
(
'
shift+l
'
,
()
=>
findAndFollowLink
(
'
.dashboard-shortcuts-milestones
'
));
Mousetrap
.
bind
(
'
shift+s
'
,
()
=>
findAndFollowLink
(
'
.dashboard-shortcuts-snippets
'
));
Mousetrap
.
bind
([
'
ctrl+shift+p
'
,
'
command+shift+p
'
],
Shortcuts
.
toggleMarkdownPreview
);
Shortcuts
.
prototype
.
onTogglePerfBar
=
function
(
e
)
{
if
(
typeof
findFileURL
!==
'
undefined
'
&&
findFileURL
!==
null
)
{
Mousetrap
.
bind
(
'
t
'
,
()
=>
{
gl
.
utils
.
visitUrl
(
findFileURL
);
});
}
$
(
document
).
on
(
'
click.more_help
'
,
'
.js-more-help-button
'
,
function
clickMoreHelp
(
e
)
{
$
(
this
).
remove
();
$
(
'
.hidden-shortcut
'
).
show
();
e
.
preventDefault
();
const
performanceBarCookieName
=
'
perf_bar_enabled
'
;
if
(
Cookies
.
get
(
performanceBarCookieName
)
===
'
true
'
)
{
Cookies
.
remove
(
performanceBarCookieName
,
{
path
:
'
/
'
});
}
else
{
Cookies
.
set
(
performanceBarCookieName
,
'
true
'
,
{
path
:
'
/
'
});
}
gl
.
utils
.
refreshCurrentPage
();
};
Shortcuts
.
prototype
.
toggleMarkdownPreview
=
function
(
e
)
{
// Check if short-cut was triggered while in Write Mode
const
$target
=
$
(
e
.
target
);
const
$form
=
$target
.
closest
(
'
form
'
);
if
(
$target
.
hasClass
(
'
js-note-text
'
))
{
$
(
'
.js-md-preview-button
'
,
$form
).
focus
();
}
return
$
(
document
).
triggerHandler
(
'
markdown-preview:toggle
'
,
[
e
]);
};
Shortcuts
.
toggleHelp
=
function
(
location
)
{
var
$modal
;
$modal
=
$
(
'
#modal-shortcuts
'
);
if
(
$modal
.
length
)
{
$modal
.
modal
(
'
toggle
'
);
return
;
}
return
$
.
ajax
({
url
:
gon
.
shortcuts_path
,
dataType
:
'
script
'
,
success
:
function
(
e
)
{
var
i
,
l
,
len
,
results
;
if
(
location
&&
location
.
length
>
0
)
{
results
=
[];
for
(
i
=
0
,
len
=
location
.
length
;
i
<
len
;
i
+=
1
)
{
l
=
location
[
i
];
results
.
push
(
$
(
l
).
show
());
}
return
results
;
}
else
{
$
(
'
.hidden-shortcut
'
).
show
();
return
$
(
'
.js-more-help-button
'
).
remove
();
});
}
onToggleHelp
(
e
)
{
e
.
preventDefault
();
Shortcuts
.
toggleHelp
(
this
.
enabledHelp
);
}
static
onTogglePerfBar
(
e
)
{
e
.
preventDefault
();
const
performanceBarCookieName
=
'
perf_bar_enabled
'
;
if
(
Cookies
.
get
(
performanceBarCookieName
)
===
'
true
'
)
{
Cookies
.
remove
(
performanceBarCookieName
,
{
path
:
'
/
'
});
}
else
{
Cookies
.
set
(
performanceBarCookieName
,
'
true
'
,
{
path
:
'
/
'
});
}
gl
.
utils
.
refreshCurrentPage
();
}
static
toggleMarkdownPreview
(
e
)
{
// Check if short-cut was triggered while in Write Mode
const
$target
=
$
(
e
.
target
);
const
$form
=
$target
.
closest
(
'
form
'
);
if
(
$target
.
hasClass
(
'
js-note-text
'
))
{
$
(
'
.js-md-preview-button
'
,
$form
).
focus
();
}
$
(
document
).
triggerHandler
(
'
markdown-preview:toggle
'
,
[
e
]);
}
static
toggleHelp
(
location
)
{
const
$modal
=
$
(
'
#modal-shortcuts
'
);
if
(
$modal
.
length
)
{
$modal
.
modal
(
'
toggle
'
);
}
$
.
ajax
({
url
:
gon
.
shortcuts_path
,
dataType
:
'
script
'
,
success
()
{
if
(
location
&&
location
.
length
>
0
)
{
const
results
=
[];
for
(
let
i
=
0
,
len
=
location
.
length
;
i
<
len
;
i
+=
1
)
{
results
.
push
(
$
(
location
[
i
]).
show
());
}
return
results
;
}
});
};
Shortcuts
.
prototype
.
focusFilter
=
function
(
e
)
{
if
(
this
.
filterInput
==
null
)
{
this
.
filterInput
=
$
(
'
input[type=search]
'
,
'
.nav-controls
'
);
}
this
.
filterInput
.
focus
();
return
e
.
preventDefault
();
};
Shortcuts
.
focusSearch
=
function
(
e
)
{
$
(
'
#search
'
).
focus
();
return
e
.
preventDefault
();
};
return
Shortcuts
;
})();
$
(
document
).
on
(
'
click.more_help
'
,
'
.js-more-help-button
'
,
function
(
e
)
{
$
(
this
).
remove
();
$
(
'
.hidden-shortcut
'
).
show
();
return
e
.
preventDefault
();
});
Mousetrap
.
stopCallback
=
(
function
()
{
var
defaultStopCallback
;
defaultStopCallback
=
Mousetrap
.
stopCallback
;
return
function
(
e
,
element
,
combo
)
{
// allowed shortcuts if textarea, input, contenteditable are focused
if
([
'
ctrl+shift+p
'
,
'
command+shift+p
'
].
indexOf
(
combo
)
!==
-
1
)
{
return
false
;
}
else
{
return
defaultStopCallback
.
apply
(
this
,
arguments
);
}
};
})();
}).
call
(
window
);
$
(
'
.hidden-shortcut
'
).
show
();
return
$
(
'
.js-more-help-button
'
).
remove
();
},
});
}
focusFilter
(
e
)
{
if
(
!
this
.
filterInput
)
{
this
.
filterInput
=
$
(
'
input[type=search]
'
,
'
.nav-controls
'
);
}
this
.
filterInput
.
focus
();
e
.
preventDefault
();
}
static
focusSearch
(
e
)
{
$
(
'
#search
'
).
focus
();
e
.
preventDefault
();
}
}
app/assets/javascripts/shortcuts_blob.js
View file @
299da4ca
/* global Mousetrap */
/* global Shortcuts */
import
'
./shortcuts
'
;
import
Shortcuts
from
'
./shortcuts
'
;
const
defaults
=
{
skipResetBindings
:
false
,
...
...
app/assets/javascripts/shortcuts_find_file.js
View file @
299da4ca
/* 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 */
/* global Mousetrap */
/* global ShortcutsNavigation */
import
'
./shortcuts_navigation
'
;
import
ShortcutsNavigation
from
'
./shortcuts_navigation
'
;
(
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
;
export
default
class
ShortcutsFindFile
extends
ShortcutsNavigation
{
constructor
(
projectFindFile
)
{
super
()
;
this
.
ShortcutsFindFile
=
(
function
(
superClass
)
{
extend
(
ShortcutsFindFile
,
superClass
)
;
const
oldStopCallback
=
Mousetrap
.
stopCallback
;
this
.
projectFindFile
=
projectFindFile
;
function
ShortcutsFindFile
(
projectFindFile
)
{
var
_oldStopCallback
;
this
.
projectFindFile
=
projectFindFile
;
ShortcutsFindFile
.
__super__
.
constructor
.
call
(
this
);
_oldStopCallback
=
Mousetrap
.
stopCallback
;
Mousetrap
.
stopCallback
=
(
function
(
_this
)
{
// override to fire shortcuts action when focus in textbox
return
function
(
event
,
element
,
combo
)
{
if
(
element
===
_this
.
projectFindFile
.
inputElement
[
0
]
&&
(
combo
===
'
up
'
||
combo
===
'
down
'
||
combo
===
'
esc
'
||
combo
===
'
enter
'
))
{
// when press up/down key in textbox, cusor prevent to move to home/end
event
.
preventDefault
();
return
false
;
}
return
_oldStopCallback
(
event
,
element
,
combo
);
};
})(
this
);
Mousetrap
.
bind
(
'
up
'
,
this
.
projectFindFile
.
selectRowUp
);
Mousetrap
.
bind
(
'
down
'
,
this
.
projectFindFile
.
selectRowDown
);
Mousetrap
.
bind
(
'
esc
'
,
this
.
projectFindFile
.
goToTree
);
Mousetrap
.
bind
(
'
enter
'
,
this
.
projectFindFile
.
goToBlob
);
}
Mousetrap
.
stopCallback
=
(
e
,
element
,
combo
)
=>
{
if
(
element
===
this
.
projectFindFile
.
inputElement
[
0
]
&&
(
combo
===
'
up
'
||
combo
===
'
down
'
||
combo
===
'
esc
'
||
combo
===
'
enter
'
)
)
{
// when press up/down key in textbox, cusor prevent to move to home/end
event
.
preventDefault
();
return
false
;
}
return
ShortcutsFindFile
;
})(
ShortcutsNavigation
);
}).
call
(
window
);
return
oldStopCallback
(
e
,
element
,
combo
);
};
Mousetrap
.
bind
(
'
up
'
,
this
.
projectFindFile
.
selectRowUp
);
Mousetrap
.
bind
(
'
down
'
,
this
.
projectFindFile
.
selectRowDown
);
Mousetrap
.
bind
(
'
esc
'
,
this
.
projectFindFile
.
goToTree
);
Mousetrap
.
bind
(
'
enter
'
,
this
.
projectFindFile
.
goToBlob
);
}
}
app/assets/javascripts/shortcuts_issuable.js
View file @
299da4ca
/* eslint-disable func-names, space-before-function-paren, max-len, no-var, one-var, no-restricted-syntax, vars-on-top, no-use-before-define, no-param-reassign, new-cap, no-underscore-dangle, wrap-iife, one-var-declaration-per-line, quotes, prefer-arrow-callback, consistent-return, prefer-template, no-mixed-operators */
/* global Mousetrap */
/* global ShortcutsNavigation */
/* global sidebar */
import
_
from
'
underscore
'
;
import
'
mousetrap
'
;
import
'
./shortcuts_navigation
'
;
(
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
.
ShortcutsIssuable
=
(
function
(
superClass
)
{
extend
(
ShortcutsIssuable
,
superClass
);
function
ShortcutsIssuable
(
isMergeRequest
)
{
ShortcutsIssuable
.
__super__
.
constructor
.
call
(
this
);
Mousetrap
.
bind
(
'
a
'
,
this
.
openSidebarDropdown
.
bind
(
this
,
'
assignee
'
));
Mousetrap
.
bind
(
'
m
'
,
this
.
openSidebarDropdown
.
bind
(
this
,
'
milestone
'
));
Mousetrap
.
bind
(
'
r
'
,
(
function
(
_this
)
{
return
function
()
{
_this
.
replyWithSelectedText
(
isMergeRequest
);
return
false
;
};
})(
this
));
Mousetrap
.
bind
(
'
e
'
,
(
function
(
_this
)
{
return
function
()
{
_this
.
editIssue
();
return
false
;
};
})(
this
));
Mousetrap
.
bind
(
'
l
'
,
this
.
openSidebarDropdown
.
bind
(
this
,
'
labels
'
));
if
(
isMergeRequest
)
{
this
.
enabledHelp
.
push
(
'
.hidden-shortcut.merge_requests
'
);
}
else
{
this
.
enabledHelp
.
push
(
'
.hidden-shortcut.issues
'
);
}
import
ShortcutsNavigation
from
'
./shortcuts_navigation
'
;
export
default
class
ShortcutsIssuable
extends
ShortcutsNavigation
{
constructor
(
isMergeRequest
)
{
super
();
this
.
$replyField
=
isMergeRequest
?
$
(
'
.js-main-target-form #note_note
'
)
:
$
(
'
.js-main-target-form .js-vue-comment-form
'
);
this
.
editBtn
=
document
.
querySelector
(
'
.issuable-edit
'
);
Mousetrap
.
bind
(
'
a
'
,
()
=>
ShortcutsIssuable
.
openSidebarDropdown
(
'
assignee
'
));
Mousetrap
.
bind
(
'
m
'
,
()
=>
ShortcutsIssuable
.
openSidebarDropdown
(
'
milestone
'
));
Mousetrap
.
bind
(
'
l
'
,
()
=>
ShortcutsIssuable
.
openSidebarDropdown
(
'
labels
'
));
Mousetrap
.
bind
(
'
r
'
,
this
.
replyWithSelectedText
.
bind
(
this
));
Mousetrap
.
bind
(
'
e
'
,
this
.
editIssue
.
bind
(
this
));
if
(
isMergeRequest
)
{
this
.
enabledHelp
.
push
(
'
.hidden-shortcut.merge_requests
'
);
}
else
{
this
.
enabledHelp
.
push
(
'
.hidden-shortcut.issues
'
);
}
}
replyWithSelectedText
()
{
const
documentFragment
=
window
.
gl
.
utils
.
getSelectedFragment
();
if
(
!
documentFragment
)
{
this
.
$replyField
.
focus
();
return
false
;
}
const
el
=
window
.
gl
.
CopyAsGFM
.
transformGFMSelection
(
documentFragment
.
cloneNode
(
true
));
const
selected
=
window
.
gl
.
CopyAsGFM
.
nodeToGFM
(
el
);
ShortcutsIssuable
.
prototype
.
replyWithSelectedText
=
function
(
isMergeRequest
)
{
var
quote
,
documentFragment
,
el
,
selected
,
separator
;
let
replyField
;
if
(
isMergeRequest
)
{
replyField
=
$
(
'
.js-main-target-form #note_note
'
);
}
else
{
replyField
=
$
(
'
.js-main-target-form .js-vue-comment-form
'
);
}
documentFragment
=
window
.
gl
.
utils
.
getSelectedFragment
();
if
(
!
documentFragment
)
{
replyField
.
focus
();
return
;
}
el
=
window
.
gl
.
CopyAsGFM
.
transformGFMSelection
(
documentFragment
.
cloneNode
(
true
));
selected
=
window
.
gl
.
CopyAsGFM
.
nodeToGFM
(
el
);
if
(
selected
.
trim
()
===
""
)
{
return
;
}
quote
=
_
.
map
(
selected
.
split
(
"
\n
"
),
function
(
val
)
{
return
(
"
>
"
+
val
).
trim
()
+
"
\n
"
;
});
// If replyField already has some content, add a newline before our quote
separator
=
replyField
.
val
().
trim
()
!==
""
&&
"
\n\n
"
||
''
;
replyField
.
val
(
function
(
a
,
current
)
{
return
current
+
separator
+
quote
.
join
(
''
)
+
"
\n
"
;
});
// Trigger autosave
replyField
.
trigger
(
'
input
'
).
trigger
(
'
change
'
);
// Trigger autosize
var
event
=
document
.
createEvent
(
'
Event
'
);
event
.
initEvent
(
'
autosize:update
'
,
true
,
false
);
replyField
.
get
(
0
).
dispatchEvent
(
event
);
// Focus the input field
return
replyField
.
focus
();
};
ShortcutsIssuable
.
prototype
.
editIssue
=
function
()
{
var
$editBtn
;
$editBtn
=
$
(
'
.issuable-edit
'
);
// Need to click the element as on issues, editing is inline
// on merge request, editing is on a different page
$editBtn
.
get
(
0
).
click
();
};
ShortcutsIssuable
.
prototype
.
openSidebarDropdown
=
function
(
name
)
{
sidebar
.
openDropdown
(
name
);
if
(
selected
.
trim
()
===
''
)
{
return
false
;
};
}
const
quote
=
_
.
map
(
selected
.
split
(
'
\n
'
),
val
=>
`>
${
val
.
trim
()}
\n`
);
// If replyField already has some content, add a newline before our quote
const
separator
=
(
this
.
$replyField
.
val
().
trim
()
!==
''
&&
'
\n\n
'
)
||
''
;
this
.
$replyField
.
val
((
a
,
current
)
=>
`
${
current
}${
separator
}${
quote
.
join
(
''
)}
\n`
)
.
trigger
(
'
input
'
)
.
trigger
(
'
change
'
);
// Trigger autosize
const
event
=
document
.
createEvent
(
'
Event
'
);
event
.
initEvent
(
'
autosize:update
'
,
true
,
false
);
this
.
$replyField
.
get
(
0
).
dispatchEvent
(
event
);
// Focus the input field
this
.
$replyField
.
focus
();
return
false
;
}
editIssue
()
{
// Need to click the element as on issues, editing is inline
// on merge request, editing is on a different page
this
.
editBtn
.
click
();
return
false
;
}
return
ShortcutsIssuable
;
})(
ShortcutsNavigation
);
}).
call
(
window
);
static
openSidebarDropdown
(
name
)
{
sidebar
.
openDropdown
(
name
);
return
false
;
}
}
app/assets/javascripts/shortcuts_navigation.js
View file @
299da4ca
/* eslint-disable func-names, space-before-function-paren, max-len, no-var, one-var, no-restricted-syntax, vars-on-top, no-use-before-define, no-param-reassign, new-cap, no-underscore-dangle, wrap-iife, prefer-arrow-callback, consistent-return, no-return-assign */
/* global Mousetrap */
/* global Shortcuts */
import
findAndFollowLink
from
'
./shortcuts_dashboard_navigation
'
;
import
'
./shortcuts
'
;
import
Shortcuts
from
'
./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
;
export
default
class
ShortcutsNavigation
extends
Shortcuts
{
constructor
()
{
super
()
;
this
.
ShortcutsNavigation
=
(
function
(
superClass
)
{
extend
(
ShortcutsNavigation
,
superClass
);
Mousetrap
.
bind
(
'
g p
'
,
()
=>
findAndFollowLink
(
'
.shortcuts-project
'
));
Mousetrap
.
bind
(
'
g e
'
,
()
=>
findAndFollowLink
(
'
.shortcuts-project-activity
'
));
Mousetrap
.
bind
(
'
g f
'
,
()
=>
findAndFollowLink
(
'
.shortcuts-tree
'
));
Mousetrap
.
bind
(
'
g c
'
,
()
=>
findAndFollowLink
(
'
.shortcuts-commits
'
));
Mousetrap
.
bind
(
'
g j
'
,
()
=>
findAndFollowLink
(
'
.shortcuts-builds
'
));
Mousetrap
.
bind
(
'
g n
'
,
()
=>
findAndFollowLink
(
'
.shortcuts-network
'
));
Mousetrap
.
bind
(
'
g d
'
,
()
=>
findAndFollowLink
(
'
.shortcuts-repository-charts
'
));
Mousetrap
.
bind
(
'
g i
'
,
()
=>
findAndFollowLink
(
'
.shortcuts-issues
'
));
Mousetrap
.
bind
(
'
g b
'
,
()
=>
findAndFollowLink
(
'
.shortcuts-issue-boards
'
));
Mousetrap
.
bind
(
'
g m
'
,
()
=>
findAndFollowLink
(
'
.shortcuts-merge_requests
'
));
Mousetrap
.
bind
(
'
g t
'
,
()
=>
findAndFollowLink
(
'
.shortcuts-todos
'
));
Mousetrap
.
bind
(
'
g w
'
,
()
=>
findAndFollowLink
(
'
.shortcuts-wiki
'
));
Mousetrap
.
bind
(
'
g s
'
,
()
=>
findAndFollowLink
(
'
.shortcuts-snippets
'
));
Mousetrap
.
bind
(
'
i
'
,
()
=>
findAndFollowLink
(
'
.shortcuts-new-issue
'
));
function
ShortcutsNavigation
()
{
ShortcutsNavigation
.
__super__
.
constructor
.
call
(
this
);
Mousetrap
.
bind
(
'
g p
'
,
()
=>
findAndFollowLink
(
'
.shortcuts-project
'
));
Mousetrap
.
bind
(
'
g e
'
,
()
=>
findAndFollowLink
(
'
.shortcuts-project-activity
'
));
Mousetrap
.
bind
(
'
g f
'
,
()
=>
findAndFollowLink
(
'
.shortcuts-tree
'
));
Mousetrap
.
bind
(
'
g c
'
,
()
=>
findAndFollowLink
(
'
.shortcuts-commits
'
));
Mousetrap
.
bind
(
'
g j
'
,
()
=>
findAndFollowLink
(
'
.shortcuts-builds
'
));
Mousetrap
.
bind
(
'
g n
'
,
()
=>
findAndFollowLink
(
'
.shortcuts-network
'
));
Mousetrap
.
bind
(
'
g d
'
,
()
=>
findAndFollowLink
(
'
.shortcuts-repository-charts
'
));
Mousetrap
.
bind
(
'
g i
'
,
()
=>
findAndFollowLink
(
'
.shortcuts-issues
'
));
Mousetrap
.
bind
(
'
g b
'
,
()
=>
findAndFollowLink
(
'
.shortcuts-issue-boards
'
));
Mousetrap
.
bind
(
'
g m
'
,
()
=>
findAndFollowLink
(
'
.shortcuts-merge_requests
'
));
Mousetrap
.
bind
(
'
g t
'
,
()
=>
findAndFollowLink
(
'
.shortcuts-todos
'
));
Mousetrap
.
bind
(
'
g w
'
,
()
=>
findAndFollowLink
(
'
.shortcuts-wiki
'
));
Mousetrap
.
bind
(
'
g s
'
,
()
=>
findAndFollowLink
(
'
.shortcuts-snippets
'
));
Mousetrap
.
bind
(
'
i
'
,
()
=>
findAndFollowLink
(
'
.shortcuts-new-issue
'
));
this
.
enabledHelp
.
push
(
'
.hidden-shortcut.project
'
);
}
return
ShortcutsNavigation
;
})(
Shortcuts
);
}).
call
(
window
);
this
.
enabledHelp
.
push
(
'
.hidden-shortcut.project
'
);
}
}
app/assets/javascripts/shortcuts_network.js
View file @
299da4ca
/* eslint-disable func-names, space-before-function-paren, max-len, no-var, one-var, no-restricted-syntax, vars-on-top, no-use-before-define, no-param-reassign, new-cap, no-underscore-dangle, wrap-iife, max-len */
/* global Mousetrap */
/* global ShortcutsNavigation */
import
ShortcutsNavigation
from
'
./shortcuts_navigation
'
;
import
'
./shortcuts_navigation
'
;
export
default
class
ShortcutsNetwork
extends
ShortcutsNavigation
{
constructor
(
graph
)
{
super
();
(
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
;
Mousetrap
.
bind
([
'
left
'
,
'
h
'
],
graph
.
scrollLeft
);
Mousetrap
.
bind
([
'
right
'
,
'
l
'
],
graph
.
scrollRight
);
Mousetrap
.
bind
([
'
up
'
,
'
k
'
],
graph
.
scrollUp
);
Mousetrap
.
bind
([
'
down
'
,
'
j
'
],
graph
.
scrollDown
);
Mousetrap
.
bind
([
'
shift+up
'
,
'
shift+k
'
],
graph
.
scrollTop
);
Mousetrap
.
bind
([
'
shift+down
'
,
'
shift+j
'
],
graph
.
scrollBottom
);
this
.
ShortcutsNetwork
=
(
function
(
superClass
)
{
extend
(
ShortcutsNetwork
,
superClass
);
function
ShortcutsNetwork
(
graph
)
{
this
.
graph
=
graph
;
ShortcutsNetwork
.
__super__
.
constructor
.
call
(
this
);
Mousetrap
.
bind
([
'
left
'
,
'
h
'
],
this
.
graph
.
scrollLeft
);
Mousetrap
.
bind
([
'
right
'
,
'
l
'
],
this
.
graph
.
scrollRight
);
Mousetrap
.
bind
([
'
up
'
,
'
k
'
],
this
.
graph
.
scrollUp
);
Mousetrap
.
bind
([
'
down
'
,
'
j
'
],
this
.
graph
.
scrollDown
);
Mousetrap
.
bind
([
'
shift+up
'
,
'
shift+k
'
],
this
.
graph
.
scrollTop
);
Mousetrap
.
bind
([
'
shift+down
'
,
'
shift+j
'
],
this
.
graph
.
scrollBottom
);
this
.
enabledHelp
.
push
(
'
.hidden-shortcut.network
'
);
}
return
ShortcutsNetwork
;
})(
ShortcutsNavigation
);
}).
call
(
window
);
this
.
enabledHelp
.
push
(
'
.hidden-shortcut.network
'
);
}
}
app/assets/javascripts/shortcuts_wiki.js
View file @
299da4ca
/* eslint-disable class-methods-use-this */
/* global Mousetrap */
/* global ShortcutsNavigation */
import
ShortcutsNavigation
from
'
./shortcuts_navigation
'
;
import
findAndFollowLink
from
'
./shortcuts_dashboard_navigation
'
;
export
default
class
ShortcutsWiki
extends
ShortcutsNavigation
{
...
...
spec/javascripts/shortcuts_issuable_spec.js
View file @
299da4ca
/* global ShortcutsIssuable */
import
'
~/copy_as_gfm
'
;
import
'
~/shortcuts_issuable
'
;
import
ShortcutsIssuable
from
'
~/shortcuts_issuable
'
;
describe
(
'
ShortcutsIssuable
'
,
()
=>
{
const
fixtureName
=
'
merge_requests/diff_comment.html.raw
'
;
...
...
spec/javascripts/shortcuts_spec.js
View file @
299da4ca
/* global Shortcuts */
import
Shortcuts
from
'
~/shortcuts
'
;
describe
(
'
Shortcuts
'
,
()
=>
{
const
fixtureName
=
'
merge_requests/diff_comment.html.raw
'
;
const
createEvent
=
(
type
,
target
)
=>
$
.
Event
(
type
,
{
...
...
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