Skip to content

Commit

Permalink
Sync with origin (#6)
Browse files Browse the repository at this point in the history
* Merge pull request slab#3223 from luin/ignore-nested-quill-mutations

Ignore mutations happens in nested Quill instance

(cherry picked from commit 8ce3ee3)

* Merge pull request slab#3272 from luin/firefox-bullet

Header/paragraph doesn't reset list numbering in Firefox

(cherry picked from commit eeb976e)

* allow list completion on lists and headers

(cherry picked from commit a6911aa)

* 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 9d16aa5)

* 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 232b6f4)

* Merge branch 'fix-cut-format'

* Merge pull request slab#3293 from quilljs/firefox-checkbox

Fix checkbox not checkable on Firefox

(cherry picked from commit 1f0530a)

Co-authored-by: Jason Chen <[email protected]>
  • Loading branch information
DokaRus and jhchen authored Mar 26, 2021
1 parent 66e6aad commit 9c94082
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 18 deletions.
12 changes: 11 additions & 1 deletion assets/core.styl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions blots/scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion modules/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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 });
}
}

Expand Down
34 changes: 18 additions & 16 deletions modules/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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\])$/,
Expand Down Expand Up @@ -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) {
Expand All @@ -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 };
27 changes: 27 additions & 0 deletions test/unit/modules/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<h1>01<em>7</em>8</h1>');
expect(this.quill.getSelection()).toEqual(new Range(2));
expect(this.clipboardData['text/plain']).toEqual('23\n56');
expect(this.clipboardData['text/html']).toEqual(
'<h1>23</h1><p>5<em>6</em></p>',
);
done();
}, 2);
});
});

it('dangerouslyPasteHTML(html)', function() {
this.quill.clipboard.dangerouslyPasteHTML('<i>ab</i><b>cd</b>');
expect(this.quill.root).toEqualHTML(
Expand Down

0 comments on commit 9c94082

Please sign in to comment.