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(