Skip to content

Commit

Permalink
get rid of visual matching
Browse files Browse the repository at this point in the history
  • Loading branch information
jhchen committed Aug 6, 2017
1 parent 9539ae7 commit 3897c98
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 28 deletions.
14 changes: 0 additions & 14 deletions docs/docs/modules/clipboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,3 @@ var quill = new Quill('#editor', {
}
});
```

### matchVisual

Quill by default does not have padding or margin for each line, whereas some websites or sources where a paste will come from will. By default Quill will try to match this spacing visually by adding an extra line to compensate for the missing margin/padding. This option disables this behavior.

```javascript
var quill = new Quill('#editor', {
modules: {
clipboard: {
matchVisual: false
}
}
});
```
16 changes: 2 additions & 14 deletions modules/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const CLIPBOARD_CONFIG = [
['br', matchBreak],
[Node.ELEMENT_NODE, matchNewline],
[Node.ELEMENT_NODE, matchBlot],
[Node.ELEMENT_NODE, matchSpacing],
[Node.ELEMENT_NODE, matchAttributor],
[Node.ELEMENT_NODE, matchStyles],
['li', matchIndent],
Expand Down Expand Up @@ -62,7 +61,6 @@ class Clipboard extends Module {
this.container.setAttribute('tabindex', -1);
this.matchers = [];
CLIPBOARD_CONFIG.concat(this.options.matchers).forEach(([selector, matcher]) => {
if (!options.matchVisual && matcher === matchSpacing) return;
this.addMatcher(selector, matcher);
});
}
Expand Down Expand Up @@ -137,7 +135,7 @@ class Clipboard extends Module {
}
Clipboard.DEFAULTS = {
matchers: [],
matchVisual: true
matchVisual: false
};


Expand Down Expand Up @@ -286,16 +284,6 @@ function matchNewline(node, delta) {
return delta;
}

function matchSpacing(node, delta) {
if (isLine(node) && node.nextElementSibling != null && !deltaEndsWith(delta, '\n\n')) {
let nodeHeight = node.offsetHeight + parseFloat(computeStyle(node).marginTop) + parseFloat(computeStyle(node).marginBottom);
if (node.nextElementSibling.offsetTop > node.offsetTop + nodeHeight*1.5) {
delta.insert('\n');
}
}
return delta;
}

function matchStyles(node, delta) {
let formats = {};
let style = node.style || {};
Expand Down Expand Up @@ -345,4 +333,4 @@ function matchText(node, delta) {
}


export { Clipboard as default, matchAttributor, matchBlot, matchNewline, matchSpacing, matchText };
export { Clipboard as default, matchAttributor, matchBlot, matchNewline, matchText };

0 comments on commit 3897c98

Please sign in to comment.