Permalink
Browse files

[panel addon] Implement a 'stable' option

Issue #4485
  • Loading branch information...
1 parent 3a83dcc commit 6928fec6695f468f17b5031e48192ad2f7d505f1 @marijnh marijnh committed Jan 4, 2017
Showing with 18 additions and 6 deletions.
  1. +9 −0 addon/display/panel.js
  2. +2 −2 demo/panel.html
  3. +7 −4 doc/manual.html
@@ -38,6 +38,9 @@
var height = (options && options.height) || node.offsetHeight;
this._setSize(null, info.heightLeft -= height);
info.panels++;
+ if (options.stable && isAtTop(this, node))
+ this.scrollTo(null, this.getScrollInfo().top + height)
+
return new Panel(this, node, options, height);
});
@@ -109,4 +112,10 @@
cm.setSize = cm._setSize;
cm.setSize();
}
+
+ function isAtTop(cm, dom) {
+ for (let sibling = dom.nextSibling; sibling; sibling = sibling.nextSibling)
+ if (sibling == cm.getWrapperElement()) return true
+ return false
+ }
});
View
@@ -115,7 +115,7 @@
}
function addPanel(where) {
var node = makePanel(where);
- panels[node.id] = editor.addPanel(node, {position: where});
+ panels[node.id] = editor.addPanel(node, {position: where, stable: true});
}
addPanel("top");
@@ -126,7 +126,7 @@
var panel = panels["panel-" + id];
var node = makePanel("");
- panels[node.id] = editor.addPanel(node, {replace: panel, position: "after-top"});
+ panels[node.id] = editor.addPanel(node, {replace: panel, position: "after-top", stable: true});
return false;
}
</script>
View
@@ -2910,7 +2910,7 @@ <h2 id="addons">Addons</h2>
changed.<br/>
The method accepts the following options:
<dl>
- <dt><code><strong>position</strong> : string</code></dt>
+ <dt><code><strong>position</strong>: string</code></dt>
<dd>Controls the position of the newly added panel. The
following values are recognized:
<dl>
@@ -2924,12 +2924,15 @@ <h2 id="addons">Addons</h2>
<dd>Adds the panel at the top of the bottom panels.</dd>
</dl>
</dd>
- <dt><code><strong>before</strong> : Panel</code></dt>
+ <dt><code><strong>before</strong>: Panel</code></dt>
<dd>The new panel will be added before the given panel.</dd>
- <dt><code><strong>after</strong> : Panel</code></dt>
+ <dt><code><strong>after</strong>: Panel</code></dt>
<dd>The new panel will be added after the given panel.</dd>
- <dt><code><strong>replace</strong> : Panel</code></dt>
+ <dt><code><strong>replace</strong>: Panel</code></dt>
<dd>The new panel will replace the given panel.</dd>
+ <dt><code><strong>stable</strong>: bool</code></dt>
+ <dd>Whether to scroll the editor to keep the text's vertical
+ position stable, when adding a panel above it. Defaults to false.</dd>
</dl>
When using the <code>after</code>, <code>before</code> or <code>replace</code> options,
if the panel doesn't exists or has been removed,

0 comments on commit 6928fec

Please sign in to comment.