Commit 410e24a3 authored by RawKStar77's avatar RawKStar77

Rename returnSelection() to userSelection(), remove unneeded parentheses, fix spelling error

parent eb0c163c
...@@ -15,7 +15,7 @@ markdown = ['$filter', '$timeout', '$window', ($filter, $timeout, $window) -> ...@@ -15,7 +15,7 @@ markdown = ['$filter', '$timeout', '$window', ($filter, $timeout, $window) ->
output = elem.find('div')[1] output = elem.find('div')[1]
textarea = input[0] textarea = input[0]
returnSelection = -> userSelection = ->
ourIframeSelection = $window.getSelection().toString() ourIframeSelection = $window.getSelection().toString()
if textarea.selectionStart != undefined if textarea.selectionStart != undefined
startPos = textarea.selectionStart startPos = textarea.selectionStart
...@@ -33,18 +33,19 @@ markdown = ['$filter', '$timeout', '$window', ($filter, $timeout, $window) -> ...@@ -33,18 +33,19 @@ markdown = ['$filter', '$timeout', '$window', ($filter, $timeout, $window) ->
start: startPos start: startPos
end: endPos end: endPos
} }
input.focus()
return selection return selection
insertMarkup = (value, selectionStart, selectionEnd) -> insertMarkup = (value, selectionStart, selectionEnd) ->
# New value is set for the textarea # New value is set for the textarea
textarea.value = value textarea.value = value
# A new selection is set, or the cursur is positioned inside the textarea. # A new selection is set, or the cursor is positioned inside the textarea.
textarea.selectionStart = selectionStart textarea.selectionStart = selectionStart
textarea.selectionEnd = selectionEnd textarea.selectionEnd = selectionEnd
# Focus the textarea
textarea.focus()
applyInlineMarkup = (markup, innertext)-> applyInlineMarkup = (markup, innertext)->
text = returnSelection() text = userSelection()
if text.selection == "" if text.selection == ""
newtext = text.before + markup + innertext + markup + text.after newtext = text.before + markup + innertext + markup + text.after
start = (text.before + markup).length start = (text.before + markup).length
...@@ -52,7 +53,7 @@ markdown = ['$filter', '$timeout', '$window', ($filter, $timeout, $window) -> ...@@ -52,7 +53,7 @@ markdown = ['$filter', '$timeout', '$window', ($filter, $timeout, $window) ->
insertMarkup(newtext, start, end) insertMarkup(newtext, start, end)
else else
# Check to see if markup has already been applied before to the selection. # Check to see if markup has already been applied before to the selection.
slice1 = text.before.slice((text.before.length - markup.length)) slice1 = text.before.slice(text.before.length - markup.length)
slice2 = text.after.slice(0, markup.length) slice2 = text.after.slice(0, markup.length)
if slice1 == markup and slice2 == markup if slice1 == markup and slice2 == markup
# Remove markup # Remove markup
...@@ -77,7 +78,7 @@ markdown = ['$filter', '$timeout', '$window', ($filter, $timeout, $window) -> ...@@ -77,7 +78,7 @@ markdown = ['$filter', '$timeout', '$window', ($filter, $timeout, $window) ->
applyInlineMarkup("$$", "LaTex") applyInlineMarkup("$$", "LaTex")
scope.insertLink = -> scope.insertLink = ->
text = returnSelection() text = userSelection()
if text.selection == "" if text.selection == ""
newtext = text.before + "[Link Text](https://example.com)" + text.after newtext = text.before + "[Link Text](https://example.com)" + text.after
start = text.before.length + 1 start = text.before.length + 1
...@@ -93,7 +94,7 @@ markdown = ['$filter', '$timeout', '$window', ($filter, $timeout, $window) -> ...@@ -93,7 +94,7 @@ markdown = ['$filter', '$timeout', '$window', ($filter, $timeout, $window) ->
insertMarkup(newtext, start, end) insertMarkup(newtext, start, end)
scope.insertIMG = -> scope.insertIMG = ->
text = returnSelection() text = userSelection()
if text.selection == "" if text.selection == ""
newtext = text.before + "![Image Description](https://yourimage.jpg)" + text.after newtext = text.before + "![Image Description](https://yourimage.jpg)" + text.after
start = text.before.length + 21 start = text.before.length + 21
...@@ -109,7 +110,7 @@ markdown = ['$filter', '$timeout', '$window', ($filter, $timeout, $window) -> ...@@ -109,7 +110,7 @@ markdown = ['$filter', '$timeout', '$window', ($filter, $timeout, $window) ->
insertMarkup(newtext, start, end) insertMarkup(newtext, start, end)
scope.applyBlockMarkup = (markup) -> scope.applyBlockMarkup = (markup) ->
text = returnSelection() text = userSelection()
if text.selection != "" if text.selection != ""
newstring = "" newstring = ""
index = text.before.length index = text.before.length
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment