Commit 060d5d36 authored by Paul Slaughter's avatar Paul Slaughter

Merge branch '353245-with-markdown_continue_lists-any-enter-adds-new-list-item' into 'master'

Resolve "With :markdown_continue_lists ANY "Enter" adds new list item"

See merge request gitlab-org/gitlab!81060
parents c2a69598 6ab40cdb
......@@ -367,6 +367,8 @@ function handleContinueList(e, textArea) {
export function keypressNoteText(e) {
const textArea = this;
if ($(textArea).atwho?.('isSelecting')) return;
handleContinueList(e, textArea);
handleSurroundSelectedText(e, textArea);
}
......
......@@ -420,6 +420,14 @@ RSpec.describe 'GFM autocomplete', :js do
end
end
end
context 'when typing enter for autocomplete in a markdown list' do
it 'does not create a new list item' do
fill_in 'Comment', with: "- @#{user.username}\n"
expect(find_field('Comment').value).to eq "- @#{user.username}\n"
end
end
end
private
......
import $ from 'jquery';
import { insertMarkdownText, keypressNoteText } from '~/lib/utils/text_markdown';
import '~/lib/utils/jquery_at_who';
describe('init markdown', () => {
let textArea;
......@@ -223,6 +225,24 @@ describe('init markdown', () => {
expect(textArea.selectionEnd).toBe(text.length);
});
// test that when we're in the middle of autocomplete, we don't
// add a new list item
it.each`
text | expected | atwho_selecting
${'- item @'} | ${'- item @'} | ${true}
${'- item @'} | ${'- item @\n- '} | ${false}
`('behaves correctly during autocomplete', ({ text, expected, atwho_selecting }) => {
jest.spyOn($.fn, 'atwho').mockReturnValue(atwho_selecting);
textArea.value = text;
textArea.setSelectionRange(text.length, text.length);
textArea.addEventListener('keydown', keypressNoteText);
textArea.dispatchEvent(enterEvent);
expect(textArea.value).toEqual(expected);
});
it('does nothing if feature flag disabled', () => {
gon.features = { markdownContinueLists: false };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment