Follow up bf41a7ac81f160992e6d556fb38648f359a8c2e6 - Fixes #3717 - Spaces in front of mentions can cause partly content removal.

This commit is contained in:
Rolf Schmidt 2021-09-09 14:16:10 +02:00 committed by Thorsten Eckel
parent c5659600f3
commit b3bfe71ab8
2 changed files with 26 additions and 11 deletions

View file

@ -368,7 +368,16 @@
nnode.innerHTML = string
}
else {
document.execCommand('insertHTML', false, string)
var sel = rangy.getSelection();
if (!sel.rangeCount) return
var range = sel.getRangeAt(0);
range.collapse(false);
$('<div>').append(string).contents().each(function() {
range.insertNode($(this).get(0));
range.collapseAfter($(this).get(0));
})
sel.setSingleRange(range);
}
}
@ -391,20 +400,10 @@
start = 0
}
// for chrome, check if space is before trigger if so, add it later - otherwise space will be dropped
var addSpacer = false
if ( $(range.startContainer.parentNode).html().includes(' ' + string) ) {
addSpacer = true
}
//this.log('CUT FOR', string, "-"+clone.toString()+"-", start, range.startOffset)
clone.setStart(range.startContainer, start)
clone.setEnd(range.startContainer, range.startOffset)
clone.deleteContents()
// for chrome, insert space again
if (addSpacer) {
range.pasteHtml('&nbsp;')
}
}
Plugin.prototype.onMouseEnter = function(event) {

View file

@ -106,6 +106,22 @@ RSpec.shared_examples 'text modules' do |path:|
end
end
it 'does not delete line breaks of text with mentions (issue #3717)' do
visit path
within(:active_content) do
find('select[name="group_id"]').select('Users')
find(:richtext).send_keys('@@FFFF1')
find(:richtext).send_keys(:enter)
find(:richtext).send_keys(' Testing Testy')
find(:richtext).send_keys(:enter)
find(:richtext).send_keys(:enter)
find(:richtext).send_keys(:backspace)
find(:richtext).send_keys('@@FFFF1')
find(:richtext).send_keys(:enter)
expect(find(:richtext).text).to include("FFFF1 GGGG1 Testing Testy\nFFFF1 GGGG1")
end
end
it 'supports group-dependent text modules' do
# give user access to all groups including those created