Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync with origin #6

Merged
merged 7 commits into from
Mar 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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