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

This commit is contained in:
Rolf Schmidt 2021-09-02 08:55:30 +02:00 committed by Thorsten Eckel
parent fa4577d463
commit 60c9c45c96
2 changed files with 23 additions and 12 deletions

View file

@ -391,14 +391,10 @@
start = 0 start = 0
} }
// for chrome, remove also leading space, add it later - otherwice space will be tropped // for chrome, check if space is before trigger if so, add it later - otherwise space will be dropped
if (start) { var addSpacer = false
clone.setStart(range.startContainer, start-1) if ( $(range.startContainer.parentNode).html().includes(' ' + string) ) {
clone.setEnd(range.startContainer, start) addSpacer = true
var spacerChar = clone.toString()
if (spacerChar === ' ') {
start = start - 1
}
} }
//this.log('CUT FOR', string, "-"+clone.toString()+"-", start, range.startOffset) //this.log('CUT FOR', string, "-"+clone.toString()+"-", start, range.startOffset)
clone.setStart(range.startContainer, start) clone.setStart(range.startContainer, start)
@ -406,10 +402,8 @@
clone.deleteContents() clone.deleteContents()
// for chrome, insert space again // for chrome, insert space again
if (start) { if (addSpacer) {
if (spacerChar === ' ') { range.pasteHtml(' ')
this.paste(' ')
}
} }
} }

View file

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