Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
1e1a1dfd
Commit
1e1a1dfd
authored
Sep 16, 2014
by
RawKStar77
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add checks to see if markup has already been inserted
parent
4dd51e34
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
13 deletions
+54
-13
markdown.coffee
h/static/scripts/directives/markdown.coffee
+48
-13
annotations.scss
h/static/styles/annotations.scss
+6
-0
No files found.
h/static/scripts/directives/markdown.coffee
View file @
1e1a1dfd
...
...
@@ -38,11 +38,24 @@ markdown = ['$filter', '$timeout', ($filter, $timeout) ->
if
text
.
selection
==
""
newtext
=
text
.
before
+
markup
+
innertext
+
markup
+
text
.
after
input
[
0
].
value
=
newtext
input
[
0
].
selectionStart
=
(
text
.
before
+
markup
).
length
input
[
0
].
selectionEnd
=
(
text
.
before
+
innertext
+
markup
).
length
else
# Check to see if markup has already been applied before to the selection.
slice1
=
text
.
before
.
slice
((
text
.
before
.
length
-
markup
.
length
))
slice2
=
text
.
after
.
slice
(
0
,
markup
.
length
)
if
slice1
==
markup
and
slice2
==
markup
# Remove markup
newtext
=
text
.
before
.
slice
(
0
,
(
text
.
before
.
length
-
markup
.
length
))
+
text
.
selection
+
text
.
after
.
slice
(
markup
.
length
)
input
[
0
].
value
=
newtext
input
[
0
].
selectionStart
=
text
.
before
.
length
-
markup
.
length
input
[
0
].
selectionEnd
=
(
text
.
before
+
text
.
selection
).
length
-
markup
.
length
else
# Apply markup
newtext
=
text
.
before
+
markup
+
text
.
selection
+
markup
+
text
.
after
input
[
0
].
value
=
newtext
input
[
0
].
selectionStart
=
(
text
.
before
+
markup
).
length
input
[
0
].
selectionEnd
=
(
text
.
before
+
innertext
+
markup
).
length
input
[
0
].
selectionEnd
=
(
text
.
before
+
text
.
selection
+
markup
).
length
scope
.
insertItalic
=
->
# Shares the same logic as insertBold() but with different markup.
...
...
@@ -60,6 +73,9 @@ markdown = ['$filter', '$timeout', ($filter, $timeout) ->
input
[
0
].
selectionStart
=
text
.
before
.
length
+
1
input
[
0
].
selectionEnd
=
text
.
before
.
length
+
10
else
# Check to see if markup has already been applied to avoid double presses.
if
text
.
selection
==
"Link Text"
or
text
.
selection
==
"https://example.com"
return
newtext
=
text
.
before
+
'['
+
text
.
selection
+
'](https://example.com)'
+
text
.
after
input
[
0
].
value
=
newtext
input
[
0
].
selectionStart
=
(
text
.
before
+
text
.
selection
).
length
+
3
...
...
@@ -73,6 +89,9 @@ markdown = ['$filter', '$timeout', ($filter, $timeout) ->
input
[
0
].
selectionStart
=
text
.
before
.
length
+
21
input
[
0
].
selectionEnd
=
text
.
before
.
length
+
42
else
# Check to see if markup has already been applied to avoid double presses.
if
text
.
selection
==
"https://yourimage.jpg"
return
newtext
=
text
.
before
+
'!['
+
text
.
selection
+
'](https://yourimage.jpg)'
+
text
.
after
input
[
0
].
value
=
newtext
input
[
0
].
selectionStart
=
(
text
.
before
+
text
.
selection
).
length
+
4
...
...
@@ -80,7 +99,6 @@ markdown = ['$filter', '$timeout', ($filter, $timeout) ->
scope
.
insertList
=
(
markup
=
"* "
)
->
text
=
scope
.
returnSelection
()
# If the character preceeding the curser is a newline just insert a "* ".
if
text
.
selection
!=
""
newstring
=
""
index
=
text
.
before
.
length
...
...
@@ -110,7 +128,6 @@ markdown = ['$filter', '$timeout', ($filter, $timeout) ->
if
not
newlinedetected
# Edge case: The selection does not include any new lines and does not start at 0.
# We need to find the newline before the currently selected text and add markup there.
# console.log input[0].value.substring(0, (text.before + text.selection).length)
i
=
0
indexoflastnewline
=
undefined
newstring
=
""
...
...
@@ -140,14 +157,32 @@ markdown = ['$filter', '$timeout', ($filter, $timeout) ->
input
[
0
].
selectionEnd
=
(
text
.
before
+
markup
).
length
else
# No selection, cursor is not on new line. Go to the previous newline and insert markup there.
# # Check to see if markup has already been inserted.
if
text
.
before
.
slice
(
text
.
before
.
length
-
markup
.
length
)
==
markup
newtext
=
text
.
before
.
substring
(
0
,
(
index
))
+
"
\n
"
+
text
.
before
.
substring
(
index
+
1
+
markup
.
length
)
+
text
.
after
i
=
0
for
char
in
text
.
before
if
char
==
"
\n
"
and
i
!=
0
index
=
i
i
+=
1
if
!
index
# If the line of text happens to fall on the first line and index is not set.
if
!
index
# If the line of text happens to fall on the first line and index is not set.
# Check to see if markup has already been inserted and undo it.
if
text
.
before
.
slice
(
0
,
markup
.
length
)
==
markup
newtext
=
text
.
before
.
substring
(
markup
.
length
)
+
text
.
after
input
[
0
].
value
=
newtext
input
[
0
].
selectionStart
=
text
.
before
.
length
-
markup
.
length
input
[
0
].
selectionEnd
=
text
.
before
.
length
-
markup
.
length
else
newtext
=
markup
+
text
.
before
.
substring
(
0
)
+
text
.
after
input
[
0
].
value
=
newtext
input
[
0
].
selectionStart
=
(
text
.
before
+
markup
).
length
input
[
0
].
selectionEnd
=
(
text
.
before
+
markup
).
length
# Check to see if markup has already been inserted and undo it.
else
if
text
.
before
.
slice
((
index
+
1
),
(
index
+
1
+
markup
.
length
))
==
markup
newtext
=
text
.
before
.
substring
(
0
,
(
index
))
+
"
\n
"
+
text
.
before
.
substring
(
index
+
1
+
markup
.
length
)
+
text
.
after
input
[
0
].
value
=
newtext
input
[
0
].
selectionStart
=
text
.
before
.
length
-
markup
.
length
input
[
0
].
selectionEnd
=
text
.
before
.
length
-
markup
.
length
else
newtext
=
text
.
before
.
substring
(
0
,
(
index
))
+
"
\n
"
+
markup
+
text
.
before
.
substring
(
index
+
1
)
+
text
.
after
input
[
0
].
value
=
newtext
...
...
h/static/styles/annotations.scss
View file @
1e1a1dfd
...
...
@@ -63,6 +63,12 @@
width
:
100%
;
margin-bottom
:
-1px
;
padding
:
.7em
.7em
.7em
.5em
;
user-select
:
none
;
-webkit-touch-callout
:
none
;
-webkit-user-select
:
none
;
-khtml-user-select
:
none
;
-moz-user-select
:
none
;
-ms-user-select
:
none
;
&
.disable
{
i
{
...
...
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