From 9c940827ec811ce572384f184cbb9d18289fe7fd Mon Sep 17 00:00:00 2001 From: Dmitry Levkovskiy Date: Fri, 26 Mar 2021 11:34:41 +0300 Subject: [PATCH] Sync with origin (#6) * Merge pull request #3223 from luin/ignore-nested-quill-mutations Ignore mutations happens in nested Quill instance (cherry picked from commit 8ce3ee33f757c29ab6d07998a9f1a5d52c9eb4b2) * Merge pull request #3272 from luin/firefox-bullet Header/paragraph doesn't reset list numbering in Firefox (cherry picked from commit eeb976e5e7e955e75940653375f7dffea7e478ea) * allow list completion on lists and headers (cherry picked from commit a6911aa4b85b29749e5f9788293e11c5cec31d3f) * fix arrow keying past list item - in chrome it take two left arrows to go to prev list item - in firefox ctrl+left does not work (cherry picked from commit 9d16aa5377157286c9db2d769b27ea12f32f3a74) * fix breaking list items Without this a string with no space on a line will cause the break to occur after the bullet but with it a string with spaces may not break at the space. The latter is much more common and also the choice Paper makes (cherry picked from commit 232b6f46e977bf3c4b13c4398fbd0c0b99c6dad4) * Merge branch 'fix-cut-format' * Merge pull request #3293 from quilljs/firefox-checkbox Fix checkbox not checkable on Firefox (cherry picked from commit 1f0530a01108c533fe2af07587001f530921983a) Co-authored-by: Jason Chen --- assets/core.styl | 12 +++++++++++- blots/scroll.js | 4 ++++ modules/clipboard.js | 3 ++- modules/keyboard.js | 34 ++++++++++++++++++---------------- test/unit/modules/clipboard.js | 27 +++++++++++++++++++++++++++ 5 files changed, 62 insertions(+), 18 deletions(-) diff --git a/assets/core.styl b/assets/core.styl index e562f97e92..d2781ab0c7 100644 --- a/assets/core.styl +++ b/assets/core.styl @@ -57,7 +57,10 @@ resets(arr) margin: 0 padding: 0 p, h1, h2, h3, h4, h5, h6 - counter-reset: resets(0..MAX_INDENT) + @supports (counter-set: none) + counter-set: resets(0..MAX_INDENT) + @supports not (counter-set: none) + counter-reset: resets(0..MAX_INDENT) table border-collapse: collapse td @@ -69,6 +72,7 @@ resets(arr) list-style-type: none padding-left: LIST_STYLE_OUTER_WIDTH position: relative + > .ql-ui:before display: inline-block margin-left: -1*LIST_STYLE_OUTER_WIDTH @@ -77,6 +81,12 @@ resets(arr) white-space: nowrap width: LIST_STYLE_WIDTH + @supports (display: contents) + li[data-list=bullet], + li[data-list=ordered] + > .ql-ui + display: contents + li[data-list=checked], li[data-list=unchecked] > .ql-ui diff --git a/blots/scroll.js b/blots/scroll.js index dfaa8b278b..4d6ff5cb43 100644 --- a/blots/scroll.js +++ b/blots/scroll.js @@ -164,6 +164,10 @@ class Scroll extends ScrollBlot { if (!Array.isArray(mutations)) { mutations = this.observer.takeRecords(); } + mutations = mutations.filter(({ target }) => { + const blot = this.find(target, true); + return blot && blot.scroll === this; + }); if (mutations.length > 0) { this.emitter.emit(Emitter.events.SCROLL_BEFORE_UPDATE, source, mutations); } diff --git a/modules/clipboard.js b/modules/clipboard.js index d10349a4bd..a7b2f9da26 100644 --- a/modules/clipboard.js +++ b/modules/clipboard.js @@ -19,6 +19,7 @@ import { ColorStyle } from '../formats/color'; import { DirectionAttribute, DirectionStyle } from '../formats/direction'; import { FontStyle } from '../formats/font'; import { SizeStyle } from '../formats/size'; +import { deleteRange } from './keyboard'; const debug = logger('quill:clipboard'); @@ -162,7 +163,7 @@ class Clipboard extends Module { e.clipboardData.setData('text/html', html); if (isCut) { this.raiseCallback('onCut', e); - this.quill.deleteText(range, Quill.sources.USER); + deleteRange({ range, quill: this.quill }); } } diff --git a/modules/keyboard.js b/modules/keyboard.js index c94b13a90e..1de3fdd98e 100644 --- a/modules/keyboard.js +++ b/modules/keyboard.js @@ -328,19 +328,8 @@ class Keyboard extends Module { } handleDeleteRange(range, context) { - const lines = this.quill.getLines(range); - let formats = {}; - if (lines.length > 1) { - const firstFormats = lines[0].formats(); - const lastFormats = lines[lines.length - 1].formats(); - formats = AttributeMap.diff(lastFormats, firstFormats) || {}; - } - this.quill.deleteText(range, Quill.sources.USER); - if (Object.keys(formats).length > 0) { - this.raiseOnKeydownCallback(context.event); - this.quill.formatLine(range.index, 1, formats, Quill.sources.USER); - } - this.quill.setSelection(range.index, Quill.sources.SILENT); + this.raiseOnKeydownCallback(context.event); + deleteRange({ range, quill: this.quill }); this.quill.focus(); } @@ -569,10 +558,8 @@ Keyboard.DEFAULTS = { shiftKey: null, collapsed: true, format: { - list: false, 'code-block': false, blockquote: false, - header: false, table: false, }, prefix: /^\s*?(\d+\.|-|\*|\[ ?\]|\[x\])$/, @@ -798,6 +785,21 @@ function normalize(binding) { return binding; } +function deleteRange({ quill, range }) { + const lines = quill.getLines(range); + let formats = {}; + if (lines.length > 1) { + const firstFormats = lines[0].formats(); + const lastFormats = lines[lines.length - 1].formats(); + formats = AttributeMap.diff(lastFormats, firstFormats) || {}; + } + quill.deleteText(range, Quill.sources.USER); + if (Object.keys(formats).length > 0) { + quill.formatLine(range.index, 1, formats, Quill.sources.USER); + } + quill.setSelection(range.index, Quill.sources.SILENT); +} + function tableSide(table, row, cell, offset) { if (row.prev == null && row.next == null) { if (cell.prev == null && cell.next == null) { @@ -814,4 +816,4 @@ function tableSide(table, row, cell, offset) { return null; } -export { Keyboard as default, SHORTKEY, normalize }; +export { Keyboard as default, SHORTKEY, normalize, deleteRange }; diff --git a/test/unit/modules/clipboard.js b/test/unit/modules/clipboard.js index 8c1583d417..a2c338d46c 100644 --- a/test/unit/modules/clipboard.js +++ b/test/unit/modules/clipboard.js @@ -58,6 +58,33 @@ describe('Clipboard', function() { }); }); + describe('cut', () => { + beforeEach(function() { + this.clipboardData = {}; + this.clipboardEvent = { + clipboardData: { + setData: (type, data) => { + this.clipboardData[type] = data; + }, + }, + preventDefault: () => {}, + }; + }); + + it('keeps formats of first line', function(done) { + this.quill.clipboard.onCaptureCopy(this.clipboardEvent, true); + setTimeout(() => { + expect(this.quill.root).toEqualHTML('

0178

'); + expect(this.quill.getSelection()).toEqual(new Range(2)); + expect(this.clipboardData['text/plain']).toEqual('23\n56'); + expect(this.clipboardData['text/html']).toEqual( + '

23

56

', + ); + done(); + }, 2); + }); + }); + it('dangerouslyPasteHTML(html)', function() { this.quill.clipboard.dangerouslyPasteHTML('abcd'); expect(this.quill.root).toEqualHTML(