Made markdown buttons work on all markdown textareas
Selecting multiple rows & a list correctly creates the selected text into a list
This commit is contained in:
parent
d5b331b76b
commit
4140c4622f
|
@ -34,6 +34,8 @@ class @GLForm
|
|||
# form and textarea event listeners
|
||||
@addEventListeners()
|
||||
|
||||
gl.text.init(@form)
|
||||
|
||||
# hide discard button
|
||||
@form.find('.js-note-discard').hide()
|
||||
|
||||
|
@ -42,6 +44,7 @@ class @GLForm
|
|||
clearEventListeners: ->
|
||||
@textarea.off 'focus'
|
||||
@textarea.off 'blur'
|
||||
gl.text.removeListeners(@form)
|
||||
|
||||
addEventListeners: ->
|
||||
@textarea.on 'focus', ->
|
||||
|
|
|
@ -11,7 +11,17 @@
|
|||
text.substring(textarea.selectionStart, textarea.selectionEnd)
|
||||
|
||||
gl.text.insertText = (textArea, text, tag, selected, wrap) ->
|
||||
selectedSplit = selected.split('\n')
|
||||
startChar = if not wrap and textArea.selectionStart > 0 then '\n' else ''
|
||||
|
||||
if selectedSplit.length > 1 and not wrap
|
||||
insertText = selectedSplit.map((val) ->
|
||||
if val.indexOf(tag) is 0
|
||||
"#{val.replace(tag, '')}"
|
||||
else
|
||||
"#{tag}#{val}"
|
||||
).join('\n')
|
||||
else
|
||||
insertText = "#{startChar}#{tag}#{selected}#{if wrap then tag else ' '}"
|
||||
|
||||
if document.queryCommandSupported('insertText')
|
||||
|
@ -51,9 +61,11 @@
|
|||
|
||||
@insertText(textArea, text, tag, selected, wrap)
|
||||
|
||||
gl.text.addListeners = ->
|
||||
gl.text.init = (form) ->
|
||||
self = @
|
||||
$('.js-md').on 'click', ->
|
||||
$('.js-md', form)
|
||||
.off 'click'
|
||||
.on 'click', ->
|
||||
$this = $(@)
|
||||
self.updateText(
|
||||
$this.closest('.md-area').find('textarea'),
|
||||
|
@ -61,7 +73,7 @@
|
|||
not $this.data('md-prepend')
|
||||
)
|
||||
|
||||
gl.text.removeListeners = ->
|
||||
$('.js-md').off()
|
||||
gl.text.removeListeners = (form) ->
|
||||
$('.js-md', form).off()
|
||||
|
||||
) window
|
||||
|
|
|
@ -5,9 +5,3 @@
|
|||
|
||||
#notes
|
||||
= render 'projects/notes/notes_with_form'
|
||||
|
||||
:javascript
|
||||
$(function(){
|
||||
gl.text.removeListeners();
|
||||
gl.text.addListeners();
|
||||
})
|
|
@ -6,9 +6,3 @@
|
|||
= link_to 'Reopen merge request', merge_request_path(@merge_request, merge_request: {state_event: :reopen }), method: :put, class: "btn btn-nr btn-comment btn-grouped btn-reopen reopen-mr-link js-note-target-reopen", title: "Reopen merge request", data: {original_text: "Reopen merge request", alternative_text: "Comment & reopen merge request"}
|
||||
|
||||
#notes= render "projects/notes/notes_with_form"
|
||||
|
||||
:javascript
|
||||
$(function(){
|
||||
gl.text.removeListeners();
|
||||
gl.text.addListeners();
|
||||
})
|
Loading…
Reference in New Issue