Просмотр исходного кода

Fixes #3094, fixes #2334 - When quoting, no breakout from div container possible.

Dominik Klein 3 лет назад
Родитель
Сommit
e338309791

+ 16 - 5
app/assets/javascripts/app/lib/base/jquery.contenteditable.js

@@ -114,11 +114,22 @@
       sel = window.getSelection()
       if (sel) {
         node = $(sel.anchorNode)
-        if (node && node.parent() && node.parent().is('blockquote')) {
-          e.preventDefault()
-          document.execCommand('Insertparagraph')
-          document.execCommand('Outdent')
-          return
+
+        if (node.closest('blockquote').length > 0) {
+
+          // Special handling when the line is not wrapped inside of a html element.
+          if (!node.is('div') && node.parent().is('blockquote') && node.text()) {
+            e.preventDefault()
+            document.execCommand('formatBlock', false, 'div')
+            document.execCommand('insertParagraph')
+            return
+          }
+          if (!e.shiftKey && node && (node.is('blockquote') || (node.parent() && node.parent().is('blockquote')) || !node.text())) {
+            e.preventDefault()
+            document.execCommand('insertParagraph')
+            document.execCommand('outdent')
+            return
+          }
         }
       }
 

+ 25 - 0
spec/system/ticket/update/full_quote_header_spec.rb

@@ -178,6 +178,31 @@ RSpec.describe 'Ticket > Update > Full Quote Header', current_user_id: -> { curr
       end
     end
 
+    context 'when full quote header setting is enabled' do
+      let(:full_quote_header_setting) { true }
+
+      it 'can breakout with enter from quote block' do
+        within(:active_content) do
+          highlight_and_click_reply
+
+          within(:richtext) do
+            blockquote_empty_line = first('blockquote br:nth-child(2)', visible: :all)
+            page.driver.browser.action.move_to_location(blockquote_empty_line.native.location.x, blockquote_empty_line.native.location.y).click.perform
+          end
+
+          # Special handling for firefox, because the cursor is at the wrong location after the move to with click.
+          if Capybara.current_driver == :zammad_firefox
+            find(:richtext).send_keys(:down)
+          end
+
+          find(:richtext).send_keys(:enter)
+
+          within(:richtext) do
+            expect(page).to have_css('blockquote', count: 2)
+          end
+        end
+      end
+    end
   end
 
   def click_forward