Skip to content

Commit

Permalink
add support for ancestor scrolling container
Browse files Browse the repository at this point in the history
closes slab#1082
  • Loading branch information
jhchen committed Dec 13, 2016
1 parent 942c5bf commit 2f4435a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion core/quill.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ Quill.DEFAULTS = {
modules: {},
placeholder: '',
readOnly: false,
scrollingContainer: null,
strict: true,
theme: 'default'
};
Expand Down Expand Up @@ -367,7 +368,7 @@ function expandConfig(container, userConfig) {
};
}
userConfig = extend(true, {}, Quill.DEFAULTS, { modules: moduleConfig }, themeConfig, userConfig);
['bounds', 'container'].forEach(function(key) {
['bounds', 'container', 'scrollingContainer'].forEach(function(key) {
if (typeof userConfig[key] === 'string') {
userConfig[key] = document.querySelector(userConfig[key]);
}
Expand Down
6 changes: 6 additions & 0 deletions docs/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ Default: `false`

Whether to instantiate the editor to read-only mode.

#### scrollingContainer

Default: `null`

Specifies which container has the scrollbars (i.e. `overflow-y: auto`), if changed with CSS from the default `ql-editor`. Necessary to fix scroll jumping bugs when Quill is set to [auto grow](/playground/#autogrow) its height, and another ancestor container is responsible from the scrolling.

#### strict

Default: `true`
Expand Down
2 changes: 2 additions & 0 deletions docs/playground.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
slug: kXRjQJ
- title: Snow Toolbar Tooltips
slug: ozYEro
- title: Autogrow Height
slug: dOqrVm
- title: Quill Playground
slug: KzZqZx
---
Expand Down
5 changes: 3 additions & 2 deletions modules/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class Clipboard extends Module {
this.container.setAttribute('contenteditable', true);
this.container.setAttribute('tabindex', -1);
this.matchers = [];
this.scrollingContainer = quill.options.scrollingContainer || document.body;
CLIPBOARD_CONFIG.concat(this.options.matchers).forEach((pair) => {
this.addMatcher(...pair);
});
Expand Down Expand Up @@ -95,15 +96,15 @@ class Clipboard extends Module {
if (e.defaultPrevented || !this.quill.isEnabled()) return;
let range = this.quill.getSelection();
let delta = new Delta().retain(range.index).delete(range.length);
let bodyTop = document.body.scrollTop;
let scrollTop = this.scrollingContainer.scrollTop;
this.container.focus();
setTimeout(() => {
this.quill.selection.update(Quill.sources.SILENT);
delta = delta.concat(this.convert());
this.quill.updateContents(delta, Quill.sources.USER);
// range.length contributes to delta.length()
this.quill.setSelection(delta.length() - range.length, Quill.sources.SILENT);
document.body.scrollTop = bodyTop;
this.scrollingContainer.scrollTop = scrollTop;
this.quill.selection.scrollIntoView();
}, 1);
}
Expand Down

0 comments on commit 2f4435a

Please sign in to comment.