Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
7abdc24c
Commit
7abdc24c
authored
Feb 22, 2017
by
Jan Christophersen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only add a newline in Markdown Editor if the current line is not empty
parent
3b3f0fab
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
78 additions
and
4 deletions
+78
-4
app/assets/javascripts/lib/utils/text_utility.js
app/assets/javascripts/lib/utils/text_utility.js
+14
-4
changelogs/unreleased/27978-improve-task-list-ux.yml
changelogs/unreleased/27978-improve-task-list-ux.yml
+4
-0
spec/javascripts/lib/utils/text_utility_spec.js.es6
spec/javascripts/lib/utils/text_utility_spec.js.es6
+60
-0
No files found.
app/assets/javascripts/lib/utils/text_utility.js
View file @
7abdc24c
...
...
@@ -65,9 +65,10 @@ require('vendor/latinise');
}
};
gl
.
text
.
insertText
=
function
(
textArea
,
text
,
tag
,
blockTag
,
selected
,
wrap
)
{
var
insertText
,
inserted
,
selectedSplit
,
startChar
,
removedLastNewLine
,
removedFirstNewLine
;
var
insertText
,
inserted
,
selectedSplit
,
startChar
,
removedLastNewLine
,
removedFirstNewLine
,
currentLineEmpty
,
lastNewLine
;
removedLastNewLine
=
false
;
removedFirstNewLine
=
false
;
currentLineEmpty
=
false
;
// Remove the first newline
if
(
selected
.
indexOf
(
'
\n
'
)
===
0
)
{
...
...
@@ -82,7 +83,17 @@ require('vendor/latinise');
}
selectedSplit
=
selected
.
split
(
'
\n
'
);
startChar
=
!
wrap
&&
textArea
.
selectionStart
>
0
?
'
\n
'
:
''
;
if
(
!
wrap
)
{
lastNewLine
=
textArea
.
value
.
substr
(
0
,
textArea
.
selectionStart
).
lastIndexOf
(
'
\n
'
);
// Check whether the current line is empty or consists only of spaces(=handle as empty)
if
(
/^
\s
*$/
.
test
(
textArea
.
value
.
substring
(
lastNewLine
,
textArea
.
selectionStart
)))
{
currentLineEmpty
=
true
;
}
}
startChar
=
!
wrap
&&
!
currentLineEmpty
&&
textArea
.
selectionStart
>
0
?
'
\n
'
:
''
;
if
(
selectedSplit
.
length
>
1
&&
(
!
wrap
||
(
blockTag
!=
null
)))
{
if
(
blockTag
!=
null
)
{
...
...
@@ -142,9 +153,8 @@ require('vendor/latinise');
}
};
gl
.
text
.
updateText
=
function
(
textArea
,
tag
,
blockTag
,
wrap
)
{
var
$textArea
,
oldVal
,
selected
,
text
;
var
$textArea
,
selected
,
text
;
$textArea
=
$
(
textArea
);
oldVal
=
$textArea
.
val
();
textArea
=
$textArea
.
get
(
0
);
text
=
$textArea
.
val
();
selected
=
this
.
selectedText
(
text
,
textArea
);
...
...
changelogs/unreleased/27978-improve-task-list-ux.yml
0 → 100644
View file @
7abdc24c
---
title
:
Only add a newline in the Markdown Editor if the current line is not empty
merge_request
:
9455
author
:
Jan Christophersen
spec/javascripts/lib/utils/text_utility_spec.js.es6
View file @
7abdc24c
...
...
@@ -46,5 +46,65 @@ require('~/lib/utils/text_utility');
expect(gl.text.highCountTrim(45)).toBe(45);
});
});
describe('gl.text.insertText', () => {
let textArea;
beforeAll(() => {
textArea = document.createElement('textarea');
document.querySelector('body').appendChild(textArea);
});
afterAll(() => {
textArea.parentNode.removeChild(textArea);
});
describe('without selection', () => {
it('inserts the tag on an empty line', () => {
const initialValue = '';
textArea.value = initialValue;
textArea.selectionStart = 0;
textArea.selectionEnd = 0;
gl.text.insertText(textArea, textArea.value, '*', null, '', false);
expect(textArea.value).toEqual(`${initialValue}* `);
});
it('inserts the tag on a new line if the current one is not empty', () => {
const initialValue = 'some text';
textArea.value = initialValue;
textArea.setSelectionRange(initialValue.length, initialValue.length);
gl.text.insertText(textArea, textArea.value, '*', null, '', false);
expect(textArea.value).toEqual(`${initialValue}\n* `);
});
it('inserts the tag on the same line if the current line only contains spaces', () => {
const initialValue = ' ';
textArea.value = initialValue;
textArea.setSelectionRange(initialValue.length, initialValue.length);
gl.text.insertText(textArea, textArea.value, '*', null, '', false);
expect(textArea.value).toEqual(`${initialValue}* `);
});
it('inserts the tag on the same line if the current line only contains tabs', () => {
const initialValue = '\t\t\t';
textArea.value = initialValue;
textArea.setSelectionRange(initialValue.length, initialValue.length);
gl.text.insertText(textArea, textArea.value, '*', null, '', false);
expect(textArea.value).toEqual(`${initialValue}* `);
});
});
});
});
})();
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