Commit 6ab40cdb authored by Brett Walker's avatar Brett Walker Committed by Paul Slaughter

Autocomplete should not create extra list items

When selecting an item in an autocomplete by typing
“Enter”, if you’re in a markdown list item, another
list item should not be created
parent 0e9d641a
......@@ -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