Merge pull request #18 from taigaio/wysiwyg-smart-enter-handling

Fix bux 923: Wysiwyg smart enter handling
stable
Andrey Antukh 2014-09-11 14:44:32 +02:00
commit 1f59c0c6d9
1 changed files with 23 additions and 0 deletions

View File

@ -68,6 +68,29 @@ tgMarkitupDirective = ($rootscope, $rs) ->
markdownSettings =
nameSpace: 'markdown'
onShiftEnter: {keepDefault:false, openWith:'\n\n'}
onEnter:
keepDefault: false
replaceWith: (data) ->
lastLine = data.textarea.value[0..(data.caretPosition - 1)].split("\n").pop()
match = lastLine.match /^(\s*- ).*/
return "\n#{match[1]}" if match
match = lastLine.match /^(\s*\* ).*/
return "\n#{match[1]}" if match
match = lastLine.match /^(\s*1\. ).*/
return "\n#{match[1]}" if match
return "\n"
afterInsert: (data) ->
# Calculate the scroll position
totalLines = data.textarea.value.split("\n").length
line = data.textarea.value[0..(data.caretPosition - 1)].split("\n").length
scrollRelation = line / totalLines
$el.scrollTop((scrollRelation * $el[0].scrollHeight) - ($el.height() / 2))
markupSet: [
{
name: $i18next.t('wiki-editor.heading-1')