Commit a713a29a authored by Phil Hughes's avatar Phil Hughes

Fixed first newline not working

parent fecebc79
......@@ -44,8 +44,15 @@
}
};
gl.text.insertText = function(textArea, text, tag, blockTag, selected, wrap) {
var insertText, inserted, selectedSplit, startChar, removedLastNewLine;
var insertText, inserted, selectedSplit, startChar, removedLastNewLine, removedFirstNewLine;
removedLastNewLine = false;
removedFirstNewLine = false;
// Remove the first newline
if (selected.indexOf('\n') === 0) {
removedFirstNewLine = true;
selected = selected.replace(/\n+/, '');
}
// Remove the last newline
if (textArea.selectionEnd - textArea.selectionStart > selected.replace(/\n$/, '').length) {
......@@ -72,6 +79,10 @@
insertText = "" + startChar + tag + selected + (wrap ? tag : ' ');
}
if (removedFirstNewLine) {
insertText = '\n' + insertText;
}
if (removedLastNewLine) {
insertText += '\n';
}
......
require 'rails_helper'
feature 'Issue markdown toolbar', feature: true, js: true do
let(:project) { create(:project, :public) }
let(:issue) { create(:issue, project: project) }
let(:user) { create(:user) }
before do
login_as(user)
visit namespace_project_issue_path(project.namespace, project, issue)
end
it "doesn't include first new line when adding bold" do
find('#note_note').native.send_keys('test')
find('#note_note').native.send_key(:enter)
find('#note_note').native.send_keys('bold')
page.evaluate_script('document.getElementById("note_note").setSelectionRange(4, 9)')
first('.toolbar-btn').click
expect(find('#note_note')[:value]).to eq("test\n**bold**\n")
end
it "doesn't include first new line when adding underline" do
find('#note_note').native.send_keys('test')
find('#note_note').native.send_key(:enter)
find('#note_note').native.send_keys('underline')
page.evaluate_script('document.getElementById("note_note").setSelectionRange(4, 50)')
find('.toolbar-btn:nth-child(2)').click
expect(find('#note_note')[:value]).to eq("test\n*underline*\n")
end
end
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