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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
65de10ec
Commit
65de10ec
authored
Nov 20, 2018
by
Johann Hubert Sonntagbauer
Committed by
Kushal Pandya
Nov 20, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refine cursor positioning in Markdown Editor for wrap tags.
parent
d4a5c8e2
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
9 deletions
+38
-9
app/assets/javascripts/lib/utils/text_markdown.js
app/assets/javascripts/lib/utils/text_markdown.js
+3
-8
changelogs/unreleased/54015-Markdown-Editor-improve-Cursor-placement.yml
...leased/54015-Markdown-Editor-improve-Cursor-placement.yml
+5
-0
spec/javascripts/lib/utils/text_markdown_spec.js
spec/javascripts/lib/utils/text_markdown_spec.js
+30
-1
No files found.
app/assets/javascripts/lib/utils/text_markdown.js
View file @
65de10ec
...
...
@@ -39,7 +39,7 @@ function blockTagText(text, textArea, blockTag, selected) {
}
}
function
moveCursor
({
textArea
,
tag
,
wrapped
,
removedLastNewLine
,
select
})
{
function
moveCursor
({
textArea
,
tag
,
positionBetweenTags
,
removedLastNewLine
,
select
})
{
var
pos
;
if
(
!
textArea
.
setSelectionRange
)
{
return
;
...
...
@@ -51,7 +51,7 @@ function moveCursor({ textArea, tag, wrapped, removedLastNewLine, select }) {
return
textArea
.
setSelectionRange
(
startPosition
,
endPosition
);
}
if
(
textArea
.
selectionStart
===
textArea
.
selectionEnd
)
{
if
(
wrapped
)
{
if
(
positionBetweenTags
)
{
pos
=
textArea
.
selectionStart
-
tag
.
length
;
}
else
{
pos
=
textArea
.
selectionStart
;
...
...
@@ -67,7 +67,6 @@ function moveCursor({ textArea, tag, wrapped, removedLastNewLine, select }) {
export
function
insertMarkdownText
({
textArea
,
text
,
tag
,
blockTag
,
selected
,
wrap
,
select
})
{
var
textToInsert
,
inserted
,
selectedSplit
,
startChar
,
removedLastNewLine
,
...
...
@@ -155,7 +154,7 @@ export function insertMarkdownText({ textArea, text, tag, blockTag, selected, wr
return
moveCursor
({
textArea
,
tag
:
tag
.
replace
(
textPlaceholder
,
selected
),
wrap
,
positionBetweenTags
:
wrap
&&
selected
.
length
===
0
,
removedLastNewLine
,
select
,
});
...
...
@@ -171,10 +170,6 @@ function updateText({ textArea, tag, blockTag, wrap, select }) {
return
insertMarkdownText
({
textArea
,
text
,
tag
,
blockTag
,
selected
,
wrap
,
select
});
}
function
replaceRange
(
s
,
start
,
end
,
substitute
)
{
return
s
.
substring
(
0
,
start
)
+
substitute
+
s
.
substring
(
end
);
}
export
function
addMarkdownListeners
(
form
)
{
return
$
(
'
.js-md
'
,
form
)
.
off
(
'
click
'
)
...
...
changelogs/unreleased/54015-Markdown-Editor-improve-Cursor-placement.yml
0 → 100644
View file @
65de10ec
---
title
:
Refine cursor positioning in Markdown Editor for wrap tags
merge_request
:
23085
author
:
Johann Hubert Sonntagbauer
type
:
changed
spec/javascripts/lib/utils/text_markdown_spec.js
View file @
65de10ec
...
...
@@ -86,6 +86,29 @@ describe('init markdown', () => {
expect
(
textArea
.
value
).
toEqual
(
`
${
initialValue
}
* `
);
});
it
(
'
places the cursor inside the tags
'
,
()
=>
{
const
start
=
'
lorem
'
;
const
end
=
'
ipsum
'
;
const
tag
=
'
*
'
;
textArea
.
value
=
`
${
start
}${
end
}
`
;
textArea
.
setSelectionRange
(
start
.
length
,
start
.
length
);
insertMarkdownText
({
textArea
,
text
:
textArea
.
value
,
tag
,
blockTag
:
null
,
selected
:
''
,
wrap
:
true
,
});
expect
(
textArea
.
value
).
toEqual
(
`
${
start
}
**
${
end
}
`
);
// cursor placement should be between tags
expect
(
textArea
.
selectionStart
).
toBe
(
start
.
length
+
tag
.
length
);
});
});
describe
(
'
with selection
'
,
()
=>
{
...
...
@@ -98,16 +121,22 @@ describe('init markdown', () => {
});
it
(
'
applies the tag to the selected value
'
,
()
=>
{
const
selectedIndex
=
text
.
indexOf
(
selected
);
const
tag
=
'
*
'
;
insertMarkdownText
({
textArea
,
text
:
textArea
.
value
,
tag
:
'
*
'
,
tag
,
blockTag
:
null
,
selected
,
wrap
:
true
,
});
expect
(
textArea
.
value
).
toEqual
(
text
.
replace
(
selected
,
`*
${
selected
}
*`
));
// cursor placement should be after selection + 2 tag lengths
expect
(
textArea
.
selectionStart
).
toBe
(
selectedIndex
+
selected
.
length
+
2
*
tag
.
length
);
});
it
(
'
replaces the placeholder in the tag
'
,
()
=>
{
...
...
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