Fixed first newline not working
This commit is contained in:
parent
fecebc7991
commit
a713a29aad
2 changed files with 49 additions and 1 deletions
|
@ -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';
|
||||
}
|
||||
|
|
37
spec/features/issues/markdown_toolbar_spec.rb
Normal file
37
spec/features/issues/markdown_toolbar_spec.rb
Normal file
|
@ -0,0 +1,37 @@
|
|||
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
|
Loading…
Reference in a new issue