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)
...
@@ -12,6 +12,7 @@ v 8.6.0 (unreleased)
- Allow search for logged out users
- Allow search for logged out users
- Don't show Issues/MRs from archived projects in Groups view
- Don't show Issues/MRs from archived projects in Groups view
- Increase the notes polling timeout over time (Roberto Dip)
- Increase the notes polling timeout over time (Roberto Dip)
- Add shortcut to toggle markdown preview (Florent Baldino)
v 8.5.4
v 8.5.4
- Do not cache requests for badges (including builds badge)
- Do not cache requests for badges (including builds badge)
...
...
app/assets/javascripts/markdown_preview.js.coffee
View file @
af24645d
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
class
@
MarkdownPreview
class
@
MarkdownPreview
# Minimum number of users referenced before triggering a warning
# Minimum number of users referenced before triggering a warning
referenceThreshold
:
10
referenceThreshold
:
10
ajaxCache
:
{}
showPreview
:
(
form
)
->
showPreview
:
(
form
)
->
preview
=
form
.
find
(
'.js-md-preview'
)
preview
=
form
.
find
(
'.js-md-preview'
)
...
@@ -24,12 +25,16 @@ class @MarkdownPreview
...
@@ -24,12 +25,16 @@ class @MarkdownPreview
renderMarkdown
:
(
text
,
success
)
->
renderMarkdown
:
(
text
,
success
)
->
return
unless
window
.
markdown_preview_path
return
unless
window
.
markdown_preview_path
return
success
(
@
ajaxCache
[
text
])
if
@
ajaxCache
[
text
]
$
.
ajax
$
.
ajax
type
:
'POST'
type
:
'POST'
url
:
window
.
markdown_preview_path
url
:
window
.
markdown_preview_path
data
:
{
text
:
text
}
data
:
{
text
:
text
}
dataType
:
'json'
dataType
:
'json'
success
:
success
success
:
(
response
)
=>
@
ajaxCache
[
text
]
=
response
success
(
response
)
hideReferencedUsers
:
(
form
)
->
hideReferencedUsers
:
(
form
)
->
referencedUsers
=
form
.
find
(
'.referenced-users'
)
referencedUsers
=
form
.
find
(
'.referenced-users'
)
...
@@ -49,6 +54,7 @@ markdownPreview = new MarkdownPreview()
...
@@ -49,6 +54,7 @@ markdownPreview = new MarkdownPreview()
previewButtonSelector
=
'.js-md-preview-button'
previewButtonSelector
=
'.js-md-preview-button'
writeButtonSelector
=
'.js-md-write-button'
writeButtonSelector
=
'.js-md-write-button'
lastTextareaPreviewed
=
null
$
.
fn
.
setupMarkdownPreview
=
->
$
.
fn
.
setupMarkdownPreview
=
->
$form
=
$
(
this
)
$form
=
$
(
this
)
...
@@ -58,10 +64,10 @@ $.fn.setupMarkdownPreview = ->
...
@@ -58,10 +64,10 @@ $.fn.setupMarkdownPreview = ->
form_textarea
.
on
'input'
,
->
markdownPreview
.
hideReferencedUsers
(
$form
)
form_textarea
.
on
'input'
,
->
markdownPreview
.
hideReferencedUsers
(
$form
)
form_textarea
.
on
'blur'
,
->
markdownPreview
.
showPreview
(
$form
)
form_textarea
.
on
'blur'
,
->
markdownPreview
.
showPreview
(
$form
)
$
(
document
).
on
'
click'
,
previewButtonSelector
,
(
e
)
->
$
(
document
).
on
'
markdown-preview:show'
,
(
e
,
$form
)
->
e
.
preventDefault
()
return
unless
$form
$form
=
$
(
this
).
closest
(
'form
'
)
lastTextareaPreviewed
=
$form
.
find
(
'textarea.markdown-area
'
)
# toggle tabs
# toggle tabs
$form
.
find
(
writeButtonSelector
).
parent
().
removeClass
(
'active'
)
$form
.
find
(
writeButtonSelector
).
parent
().
removeClass
(
'active'
)
...
@@ -73,10 +79,10 @@ $(document).on 'click', previewButtonSelector, (e) ->
...
@@ -73,10 +79,10 @@ $(document).on 'click', previewButtonSelector, (e) ->
markdownPreview
.
showPreview
(
$form
)
markdownPreview
.
showPreview
(
$form
)
$
(
document
).
on
'
click'
,
writeButtonSelector
,
(
e
)
->
$
(
document
).
on
'
markdown-preview:hide'
,
(
e
,
$form
)
->
e
.
preventDefault
()
return
unless
$form
$form
=
$
(
this
).
closest
(
'form'
)
lastTextareaPreviewed
=
null
# toggle tabs
# toggle tabs
$form
.
find
(
writeButtonSelector
).
parent
().
addClass
(
'active'
)
$form
.
find
(
writeButtonSelector
).
parent
().
addClass
(
'active'
)
...
@@ -84,4 +90,30 @@ $(document).on 'click', writeButtonSelector, (e) ->
...
@@ -84,4 +90,30 @@ $(document).on 'click', writeButtonSelector, (e) ->
# toggle content
# toggle content
$form
.
find
(
'.md-write-holder'
).
show
()
$form
.
find
(
'.md-write-holder'
).
show
()
$form
.
find
(
'textarea.markdown-area'
).
focus
()
$form
.
find
(
'.md-preview-holder'
).
hide
()
$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
...
@@ -4,11 +4,15 @@ class @Shortcuts
Mousetrap
.
reset
()
Mousetrap
.
reset
()
Mousetrap
.
bind
(
'?'
,
@
selectiveHelp
)
Mousetrap
.
bind
(
'?'
,
@
selectiveHelp
)
Mousetrap
.
bind
(
's'
,
Shortcuts
.
focusSearch
)
Mousetrap
.
bind
(
's'
,
Shortcuts
.
focusSearch
)
Mousetrap
.
bind
([
'ctrl+shift+p'
,
'command+shift+p'
],
@
toggleMarkdownPreview
)
Mousetrap
.
bind
(
't'
,
->
Turbolinks
.
visit
(
findFileURL
))
if
findFileURL
?
Mousetrap
.
bind
(
't'
,
->
Turbolinks
.
visit
(
findFileURL
))
if
findFileURL
?
selectiveHelp
:
(
e
)
=>
selectiveHelp
:
(
e
)
=>
Shortcuts
.
showHelp
(
e
,
@
enabledHelp
)
Shortcuts
.
showHelp
(
e
,
@
enabledHelp
)
toggleMarkdownPreview
:
(
e
)
=>
$
(
document
).
triggerHandler
(
'markdown-preview:toggle'
,
[
e
])
@
showHelp
:
(
e
,
location
)
->
@
showHelp
:
(
e
,
location
)
->
if
$
(
'#modal-shortcuts'
).
length
>
0
if
$
(
'#modal-shortcuts'
).
length
>
0
$
(
'#modal-shortcuts'
).
modal
(
'show'
)
$
(
'#modal-shortcuts'
).
modal
(
'show'
)
...
@@ -35,3 +39,14 @@ $(document).on 'click.more_help', '.js-more-help-button', (e) ->
...
@@ -35,3 +39,14 @@ $(document).on 'click.more_help', '.js-more-help-button', (e) ->
$
(
@
).
remove
()
$
(
@
).
remove
()
$
(
'.hidden-shortcut'
).
show
()
$
(
'.hidden-shortcut'
).
show
()
e
.
preventDefault
()
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 @@
...
@@ -22,6 +22,10 @@
%td
.shortcut
%td
.shortcut
.key
?
.key
?
%td
Show this dialog
%td
Show this dialog
%tr
%td
.shortcut
.key
ctrl shift p
%td
Toggle Markdown preview
%tbody
%tbody
%tr
%tr
%th
%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