BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
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
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
297e6e29
Commit
297e6e29
authored
Jan 05, 2017
by
Fatih Acet
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'markdown-button-newline-bug-fix' into 'master'
Fixed new line being included in bold/italic in GFM form Closes #25456 See merge request !8086
parents
32b1ceb0
a713a29a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
3 deletions
+70
-3
text_utility.js
app/assets/javascripts/lib/utils/text_utility.js
+33
-3
markdown_toolbar_spec.rb
spec/features/issues/markdown_toolbar_spec.rb
+37
-0
No files found.
app/assets/javascripts/lib/utils/text_utility.js
View file @
297e6e29
...
...
@@ -44,9 +44,25 @@
}
};
gl
.
text
.
insertText
=
function
(
textArea
,
text
,
tag
,
blockTag
,
selected
,
wrap
)
{
var
insertText
,
inserted
,
selectedSplit
,
startChar
;
var
insertText
,
inserted
,
selectedSplit
,
startChar
,
removedLastNewLine
,
removedFirstNewLine
;
removedLastNewLine
=
false
;
removedFirstNewLine
=
false
;
// Remove the first newline
if
(
selected
.
indexOf
(
'
\
n'
)
===
0
)
{
removedFirstNewLine
=
true
;
selected
=
selected
.
replace
(
/
\n
+/
,
''
);
}
// Remove the last newline
if
(
textArea
.
selectionEnd
-
textArea
.
selectionStart
>
selected
.
replace
(
/
\n
$/
,
''
).
length
)
{
removedLastNewLine
=
true
;
selected
=
selected
.
replace
(
/
\n
$/
,
''
);
}
selectedSplit
=
selected
.
split
(
'
\
n'
);
startChar
=
!
wrap
&&
textArea
.
selectionStart
>
0
?
'
\
n'
:
''
;
if
(
selectedSplit
.
length
>
1
&&
(
!
wrap
||
(
blockTag
!=
null
)))
{
if
(
blockTag
!=
null
)
{
insertText
=
this
.
blockTagText
(
text
,
textArea
,
blockTag
,
selected
);
...
...
@@ -62,6 +78,15 @@
}
else
{
insertText
=
""
+
startChar
+
tag
+
selected
+
(
wrap
?
tag
:
' '
);
}
if
(
removedFirstNewLine
)
{
insertText
=
'
\
n'
+
insertText
;
}
if
(
removedLastNewLine
)
{
insertText
+=
'
\
n'
;
}
if
(
document
.
queryCommandSupported
(
'insertText'
))
{
inserted
=
document
.
execCommand
(
'insertText'
,
false
,
insertText
);
}
...
...
@@ -74,9 +99,9 @@
document
.
execCommand
(
"ms-endUndoUnit"
);
}
catch
(
error
)
{}
}
return
this
.
moveCursor
(
textArea
,
tag
,
wrap
);
return
this
.
moveCursor
(
textArea
,
tag
,
wrap
,
removedLastNewLine
);
};
gl
.
text
.
moveCursor
=
function
(
textArea
,
tag
,
wrapped
)
{
gl
.
text
.
moveCursor
=
function
(
textArea
,
tag
,
wrapped
,
removedLastNewLine
)
{
var
pos
;
if
(
!
textArea
.
setSelectionRange
)
{
return
;
...
...
@@ -87,6 +112,11 @@
}
else
{
pos
=
textArea
.
selectionStart
;
}
if
(
removedLastNewLine
)
{
pos
-=
1
;
}
return
textArea
.
setSelectionRange
(
pos
,
pos
);
}
};
...
...
spec/features/issues/markdown_toolbar_spec.rb
0 → 100644
View file @
297e6e29
require
'rails_helper'
feature
'Issue markdown toolbar'
,
feature:
true
,
js:
true
do
let
(
:project
)
{
create
(
:project
,
:public
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:user
)
{
create
(
:user
)
}
before
do
login_as
(
user
)
visit
namespace_project_issue_path
(
project
.
namespace
,
project
,
issue
)
end
it
"doesn't include first new line when adding bold"
do
find
(
'#note_note'
).
native
.
send_keys
(
'test'
)
find
(
'#note_note'
).
native
.
send_key
(
:enter
)
find
(
'#note_note'
).
native
.
send_keys
(
'bold'
)
page
.
evaluate_script
(
'document.getElementById("note_note").setSelectionRange(4, 9)'
)
first
(
'.toolbar-btn'
).
click
expect
(
find
(
'#note_note'
)[
:value
]).
to
eq
(
"test
\n
**bold**
\n
"
)
end
it
"doesn't include first new line when adding underline"
do
find
(
'#note_note'
).
native
.
send_keys
(
'test'
)
find
(
'#note_note'
).
native
.
send_key
(
:enter
)
find
(
'#note_note'
).
native
.
send_keys
(
'underline'
)
page
.
evaluate_script
(
'document.getElementById("note_note").setSelectionRange(4, 50)'
)
find
(
'.toolbar-btn:nth-child(2)'
).
click
expect
(
find
(
'#note_note'
)[
:value
]).
to
eq
(
"test
\n
*underline*
\n
"
)
end
end
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