From 60c9c45c9692d034f45ae7044429e342e3c82797 Mon Sep 17 00:00:00 2001 From: Rolf Schmidt Date: Thu, 2 Sep 2021 08:55:30 +0200 Subject: [PATCH] Fixes #3717 - Spaces in front of mentions can cause partly content removal. --- .../app/lib/base/jquery.textmodule.js | 18 ++++++------------ spec/system/examples/text_modules_examples.rb | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/app/lib/base/jquery.textmodule.js b/app/assets/javascripts/app/lib/base/jquery.textmodule.js index 04bcc1637..80c937c1f 100644 --- a/app/assets/javascripts/app/lib/base/jquery.textmodule.js +++ b/app/assets/javascripts/app/lib/base/jquery.textmodule.js @@ -391,14 +391,10 @@ start = 0 } - // for chrome, remove also leading space, add it later - otherwice space will be tropped - if (start) { - clone.setStart(range.startContainer, start-1) - clone.setEnd(range.startContainer, start) - var spacerChar = clone.toString() - if (spacerChar === ' ') { - start = start - 1 - } + // 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) @@ -406,10 +402,8 @@ clone.deleteContents() // for chrome, insert space again - if (start) { - if (spacerChar === ' ') { - this.paste(' ') - } + if (addSpacer) { + range.pasteHtml(' ') } } diff --git a/spec/system/examples/text_modules_examples.rb b/spec/system/examples/text_modules_examples.rb index 3b79e89b8..e080122a1 100644 --- a/spec/system/examples/text_modules_examples.rb +++ b/spec/system/examples/text_modules_examples.rb @@ -89,6 +89,23 @@ RSpec.shared_examples 'text modules' do |path:| 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 # give user access to all groups including those created