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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
af24645d
Commit
af24645d
authored
Mar 07, 2016
by
Florent Baldino
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add shortcut to toggle markdown preview
parent
be1ae2d6
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
7 deletions
+59
-7
CHANGELOG
CHANGELOG
+1
-0
app/assets/javascripts/markdown_preview.js.coffee
app/assets/javascripts/markdown_preview.js.coffee
+39
-7
app/assets/javascripts/shortcuts.js.coffee
app/assets/javascripts/shortcuts.js.coffee
+15
-0
app/views/help/_shortcuts.html.haml
app/views/help/_shortcuts.html.haml
+4
-0
No files found.
CHANGELOG
View file @
af24645d
...
...
@@ -12,6 +12,7 @@ v 8.6.0 (unreleased)
- Allow search for logged out users
- Don't show Issues/MRs from archived projects in Groups view
- Increase the notes polling timeout over time (Roberto Dip)
- Add shortcut to toggle markdown preview (Florent Baldino)
v 8.5.4
- Do not cache requests for badges (including builds badge)
...
...
app/assets/javascripts/markdown_preview.js.coffee
View file @
af24645d
...
...
@@ -6,6 +6,7 @@
class
@
MarkdownPreview
# Minimum number of users referenced before triggering a warning
referenceThreshold
:
10
ajaxCache
:
{}
showPreview
:
(
form
)
->
preview
=
form
.
find
(
'.js-md-preview'
)
...
...
@@ -24,12 +25,16 @@ class @MarkdownPreview
renderMarkdown
:
(
text
,
success
)
->
return
unless
window
.
markdown_preview_path
return
success
(
@
ajaxCache
[
text
])
if
@
ajaxCache
[
text
]
$
.
ajax
type
:
'POST'
url
:
window
.
markdown_preview_path
data
:
{
text
:
text
}
dataType
:
'json'
success
:
success
success
:
(
response
)
=>
@
ajaxCache
[
text
]
=
response
success
(
response
)
hideReferencedUsers
:
(
form
)
->
referencedUsers
=
form
.
find
(
'.referenced-users'
)
...
...
@@ -49,6 +54,7 @@ markdownPreview = new MarkdownPreview()
previewButtonSelector
=
'.js-md-preview-button'
writeButtonSelector
=
'.js-md-write-button'
lastTextareaPreviewed
=
null
$
.
fn
.
setupMarkdownPreview
=
->
$form
=
$
(
this
)
...
...
@@ -58,10 +64,10 @@ $.fn.setupMarkdownPreview = ->
form_textarea
.
on
'input'
,
->
markdownPreview
.
hideReferencedUsers
(
$form
)
form_textarea
.
on
'blur'
,
->
markdownPreview
.
showPreview
(
$form
)
$
(
document
).
on
'
click'
,
previewButtonSelector
,
(
e
)
->
e
.
preventDefault
()
$
(
document
).
on
'
markdown-preview:show'
,
(
e
,
$form
)
->
return
unless
$form
$form
=
$
(
this
).
closest
(
'form
'
)
lastTextareaPreviewed
=
$form
.
find
(
'textarea.markdown-area
'
)
# toggle tabs
$form
.
find
(
writeButtonSelector
).
parent
().
removeClass
(
'active'
)
...
...
@@ -73,10 +79,10 @@ $(document).on 'click', previewButtonSelector, (e) ->
markdownPreview
.
showPreview
(
$form
)
$
(
document
).
on
'
click'
,
writeButtonSelector
,
(
e
)
->
e
.
preventDefault
()
$
(
document
).
on
'
markdown-preview:hide'
,
(
e
,
$form
)
->
return
unless
$form
$form
=
$
(
this
).
closest
(
'form'
)
lastTextareaPreviewed
=
null
# toggle tabs
$form
.
find
(
writeButtonSelector
).
parent
().
addClass
(
'active'
)
...
...
@@ -84,4 +90,30 @@ $(document).on 'click', writeButtonSelector, (e) ->
# toggle content
$form
.
find
(
'.md-write-holder'
).
show
()
$form
.
find
(
'textarea.markdown-area'
).
focus
()
$form
.
find
(
'.md-preview-holder'
).
hide
()
$
(
document
).
on
'markdown-preview:toggle'
,
(
e
,
keyboardEvent
)
->
$target
=
$
(
keyboardEvent
.
target
)
if
$target
.
is
(
'textarea.markdown-area'
)
$
(
document
).
triggerHandler
(
'markdown-preview:show'
,
[
$target
.
closest
(
'form'
)])
keyboardEvent
.
preventDefault
()
else
if
lastTextareaPreviewed
$target
=
lastTextareaPreviewed
$
(
document
).
triggerHandler
(
'markdown-preview:hide'
,
[
$target
.
closest
(
'form'
)])
keyboardEvent
.
preventDefault
()
$
(
document
).
on
'click'
,
previewButtonSelector
,
(
e
)
->
e
.
preventDefault
()
$form
=
$
(
this
).
closest
(
'form'
)
$
(
document
).
triggerHandler
(
'markdown-preview:show'
,
[
$form
])
$
(
document
).
on
'click'
,
writeButtonSelector
,
(
e
)
->
e
.
preventDefault
()
$form
=
$
(
this
).
closest
(
'form'
)
$
(
document
).
triggerHandler
(
'markdown-preview:hide'
,
[
$form
])
app/assets/javascripts/shortcuts.js.coffee
View file @
af24645d
...
...
@@ -4,11 +4,15 @@ class @Shortcuts
Mousetrap
.
reset
()
Mousetrap
.
bind
(
'?'
,
@
selectiveHelp
)
Mousetrap
.
bind
(
's'
,
Shortcuts
.
focusSearch
)
Mousetrap
.
bind
([
'ctrl+shift+p'
,
'command+shift+p'
],
@
toggleMarkdownPreview
)
Mousetrap
.
bind
(
't'
,
->
Turbolinks
.
visit
(
findFileURL
))
if
findFileURL
?
selectiveHelp
:
(
e
)
=>
Shortcuts
.
showHelp
(
e
,
@
enabledHelp
)
toggleMarkdownPreview
:
(
e
)
=>
$
(
document
).
triggerHandler
(
'markdown-preview:toggle'
,
[
e
])
@
showHelp
:
(
e
,
location
)
->
if
$
(
'#modal-shortcuts'
).
length
>
0
$
(
'#modal-shortcuts'
).
modal
(
'show'
)
...
...
@@ -35,3 +39,14 @@ $(document).on 'click.more_help', '.js-more-help-button', (e) ->
$
(
@
).
remove
()
$
(
'.hidden-shortcut'
).
show
()
e
.
preventDefault
()
Mousetrap
.
stopCallback
=
(
->
defaultStopCallback
=
Mousetrap
.
stopCallback
return
(
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
(
@
,
arguments
)
)()
app/views/help/_shortcuts.html.haml
View file @
af24645d
...
...
@@ -22,6 +22,10 @@
%td
.shortcut
.key
?
%td
Show this dialog
%tr
%td
.shortcut
.key
ctrl shift p
%td
Toggle Markdown preview
%tbody
%tr
%th
...
...
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