Commit ac4952c5 authored by RawKStar77's avatar RawKStar77

Handle edge case in scope.insertMath() rather than applyInlineMarkup()

parent 7eb036d5
...@@ -65,10 +65,7 @@ markdown = ['$filter', '$sanitize', '$sce', '$timeout', ($filter, $sanitize, $sc ...@@ -65,10 +65,7 @@ markdown = ['$filter', '$sanitize', '$sce', '$timeout', ($filter, $sanitize, $sc
# 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 - markupL.length) slice1 = text.before.slice(text.before.length - markupL.length)
slice2 = text.after.slice(0, markupR.length) slice2 = text.after.slice(0, markupR.length)
# Edge case: scope.insertMath() is called for inline and block markup, to avoid a case if (slice1 == markupL and slice2 == markupR)
# in which pressing the math button to remove block math markup adds inline math inside of
# block math $$\(LaTex or MathML\)$$ we check for $$ here.
if (slice1 == markupL and slice2 == markupR) or (slice1 == '$$' and slice2 == '$$')
# Remove markup # Remove markup
newtext = ( newtext = (
text.before.slice(0, (text.before.length - markupL.length)) + text.before.slice(0, (text.before.length - markupL.length)) +
...@@ -93,7 +90,11 @@ markdown = ['$filter', '$sanitize', '$sce', '$timeout', ($filter, $sanitize, $sc ...@@ -93,7 +90,11 @@ markdown = ['$filter', '$sanitize', '$sce', '$timeout', ($filter, $sanitize, $sc
scope.insertMath = -> scope.insertMath = ->
text = userSelection() text = userSelection()
index = text.before.length index = text.before.length
if index == 0 or input.value[index - 1] == '\n' if (
index == 0 or
input.value[index - 1] == '\n' or
(input.value[index - 1] == '$' and input.value[index - 2] == '$')
)
applyInlineMarkup('$$', 'LaTeX or MathML') applyInlineMarkup('$$', 'LaTeX or MathML')
else else
applyInlineMarkup('\\(', 'LaTeX or MathML', '\\)') applyInlineMarkup('\\(', 'LaTeX or MathML', '\\)')
......
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