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
772bf771
Commit
772bf771
authored
Jul 16, 2020
by
Paul Slaughter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Merge branch 'bw-surround-text-wth-char' into 'master'"
This reverts merge request !25748
parent
1ad2429e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
5 additions
and
68 deletions
+5
-68
app/assets/javascripts/lib/utils/text_markdown.js
app/assets/javascripts/lib/utils/text_markdown.js
+0
-34
changelogs/unreleased/bw-surround-text-wth-char.yml
changelogs/unreleased/bw-surround-text-wth-char.yml
+0
-5
spec/frontend/lib/utils/text_markdown_spec.js
spec/frontend/lib/utils/text_markdown_spec.js
+5
-29
No files found.
app/assets/javascripts/lib/utils/text_markdown.js
View file @
772bf771
...
...
@@ -303,40 +303,7 @@ function updateText({ textArea, tag, cursorOffset, blockTag, wrap, select, tagCo
});
}
/* eslint-disable @gitlab/require-i18n-strings */
export
function
keypressNoteText
(
e
)
{
if
(
this
.
selectionStart
===
this
.
selectionEnd
)
{
return
;
}
const
keys
=
{
'
*
'
:
'
**{text}**
'
,
// wraps with bold character
_
:
'
_{text}_
'
,
// wraps with italic character
'
`
'
:
'
`{text}`
'
,
// wraps with inline character
"
'
"
:
"
'{text}'
"
,
// single quotes
'
"
'
:
'
"{text}"
'
,
// double quotes
'
[
'
:
'
[{text}]
'
,
// brackets
'
{
'
:
'
{{text}}
'
,
// braces
'
(
'
:
'
({text})
'
,
// parentheses
'
<
'
:
'
<{text}>
'
,
// angle brackets
};
const
tag
=
keys
[
e
.
key
];
if
(
tag
)
{
updateText
({
tag
,
textArea
:
this
,
blockTag
:
''
,
wrap
:
true
,
select
:
''
,
tagContent
:
''
,
});
e
.
preventDefault
();
}
}
/* eslint-enable @gitlab/require-i18n-strings */
export
function
addMarkdownListeners
(
form
)
{
$
(
'
.markdown-area
'
).
on
(
'
keydown
'
,
keypressNoteText
);
return
$
(
'
.js-md
'
,
form
)
.
off
(
'
click
'
)
.
on
(
'
click
'
,
function
()
{
...
...
@@ -373,6 +340,5 @@ export function addEditorMarkdownListeners(editor) {
}
export
function
removeMarkdownListeners
(
form
)
{
$
(
'
.markdown-area
'
).
off
(
'
keydown
'
);
return
$
(
'
.js-md
'
,
form
).
off
(
'
click
'
);
}
changelogs/unreleased/bw-surround-text-wth-char.yml
deleted
100644 → 0
View file @
1ad2429e
---
title
:
Surround selected text in markdown fields on certain key presses
merge_request
:
25748
author
:
type
:
added
spec/frontend/lib/utils/text_markdown_spec.js
View file @
772bf771
import
{
insertMarkdownText
,
keypressNoteText
}
from
'
~/lib/utils/text_markdown
'
;
import
{
insertMarkdownText
}
from
'
~/lib/utils/text_markdown
'
;
describe
(
'
init markdown
'
,
()
=>
{
let
textArea
;
...
...
@@ -115,15 +115,14 @@ describe('init markdown', () => {
describe
(
'
with selection
'
,
()
=>
{
const
text
=
'
initial selected value
'
;
const
selected
=
'
selected
'
;
let
selectedIndex
;
beforeEach
(()
=>
{
textArea
.
value
=
text
;
selectedIndex
=
text
.
indexOf
(
selected
);
const
selectedIndex
=
text
.
indexOf
(
selected
);
textArea
.
setSelectionRange
(
selectedIndex
,
selectedIndex
+
selected
.
length
);
});
it
(
'
applies the tag to the selected value
'
,
()
=>
{
const
selectedIndex
=
text
.
indexOf
(
selected
);
const
tag
=
'
*
'
;
insertMarkdownText
({
...
...
@@ -154,29 +153,6 @@ describe('init markdown', () => {
expect
(
textArea
.
value
).
toEqual
(
text
.
replace
(
selected
,
`[
${
selected
}
](url)`
));
});
it
.
each
`
key | expected
${
'
[
'
}
|
${
`[
${
selected
}
]`
}
${
'
*
'
}
|
${
`**
${
selected
}
**`
}
${
"
'
"
}
|
${
`'
${
selected
}
'`
}
${
'
_
'
}
|
${
`_
${
selected
}
_`
}
${
'
`
'
}
|
${
`\`
${
selected
}
\``
}
${
'
"
'
}
|
${
`"
${
selected
}
"`
}
${
'
{
'
}
|
${
`{
${
selected
}
}`
}
${
'
(
'
}
|
${
`(
${
selected
}
)`
}
${
'
<
'
}
|
${
`<
${
selected
}
>`
}
`
(
'
generates $expected when $key is pressed
'
,
({
key
,
expected
})
=>
{
const
event
=
new
KeyboardEvent
(
'
keydown
'
,
{
key
});
textArea
.
addEventListener
(
'
keydown
'
,
keypressNoteText
);
textArea
.
dispatchEvent
(
event
);
expect
(
textArea
.
value
).
toEqual
(
text
.
replace
(
selected
,
expected
));
// cursor placement should be after selection + 2 tag lengths
expect
(
textArea
.
selectionStart
).
toBe
(
selectedIndex
+
expected
.
length
);
});
describe
(
'
and text to be selected
'
,
()
=>
{
const
tag
=
'
[{text}](url)
'
;
const
select
=
'
url
'
;
...
...
@@ -202,7 +178,7 @@ describe('init markdown', () => {
it
(
'
selects the right text when multiple tags are present
'
,
()
=>
{
const
initialValue
=
`
${
tag
}
${
tag
}
${
selected
}
`
;
textArea
.
value
=
initialValue
;
selectedIndex
=
initialValue
.
indexOf
(
selected
);
const
selectedIndex
=
initialValue
.
indexOf
(
selected
);
textArea
.
setSelectionRange
(
selectedIndex
,
selectedIndex
+
selected
.
length
);
insertMarkdownText
({
textArea
,
...
...
@@ -228,7 +204,7 @@ describe('init markdown', () => {
const
initialValue
=
`text
${
expectedUrl
}
text`
;
textArea
.
value
=
initialValue
;
selectedIndex
=
initialValue
.
indexOf
(
expectedUrl
);
const
selectedIndex
=
initialValue
.
indexOf
(
expectedUrl
);
textArea
.
setSelectionRange
(
selectedIndex
,
selectedIndex
+
expectedUrl
.
length
);
insertMarkdownText
({
...
...
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