diff options
author | Johann Hubert Sonntagbauer <johann.sonntagbauer@gmail.com> | 2018-11-20 09:57:00 +0300 |
---|---|---|
committer | Kushal Pandya <kushalspandya@gmail.com> | 2018-11-20 09:57:00 +0300 |
commit | 65de10ec6dd23543d7dc1d2a469b3b3991e33bfb (patch) | |
tree | ca2afd72c28e17e30214f9091a2b35c47bac9a9f /spec/javascripts/lib | |
parent | d4a5c8e2b8302c503a71fa392cab37290eee06df (diff) |
Refine cursor positioning in Markdown Editor for wrap tags.
Diffstat (limited to 'spec/javascripts/lib')
-rw-r--r-- | spec/javascripts/lib/utils/text_markdown_spec.js | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/spec/javascripts/lib/utils/text_markdown_spec.js b/spec/javascripts/lib/utils/text_markdown_spec.js index b9e805628f8..f71d27eb4e4 100644 --- a/spec/javascripts/lib/utils/text_markdown_spec.js +++ b/spec/javascripts/lib/utils/text_markdown_spec.js @@ -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', () => { |