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

feat: Allows height to be not explicit height, e.g. 'inherit' or '100%' #196

Merged
merged 1 commit into from
Jun 9, 2024
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
15 changes: 9 additions & 6 deletions src/diff-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ CodeMirrorDiffView.prototype.unbind = function() {
this.el.removeChild(this.el.lastChild);
}
if (this._origEl) {
this.el.style = this._origEl.style;
this.el.className = this._origEl.className;
}
this._unbound = true;
Expand Down Expand Up @@ -257,16 +256,17 @@ CodeMirrorDiffView.prototype.resize = function() {

CodeMirrorDiffView.prototype.bind = function(container) {
this.trace('api#bind', container);
this._origEl = {
style: container.style,
className: container.className
};
const el = dom.getMergelyContainer({ clazz: container.className });
const computedStyle = window.getComputedStyle(container);
if (!computedStyle.height || computedStyle.height === '0px') {
if (!el.style.height
&& (!computedStyle.height || computedStyle.height === '0px')
) {
throw new Error(
`The element "${container.id}" requires an explicit height`);
}
this._origEl = {
className: container.className
};
this.id = `${container.id}`;
this.lhsId = `${container.id}-lhs`;
this.rhsId = `${container.id}-rhs`;
Expand Down Expand Up @@ -753,6 +753,9 @@ CodeMirrorDiffView.prototype._set_top_offset = function (side) {
// this is the distance from the top of the screen to the top of the
// content of the first codemirror editor
const topnode = this._queryElement('.CodeMirror-measure');
if (!topnode.offsetParent) {
return false;
}
const top_offset = topnode.offsetParent.offsetTop + 4;

// restore editor's scroll position
Expand Down
4 changes: 3 additions & 1 deletion src/mergely.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ class Mergely {
}

const computedStyle = window.getComputedStyle(element);
if (!computedStyle.height || computedStyle.height === '0px') {
if (!element.style.height
&& (!computedStyle.height || computedStyle.height === '0px')
) {
throw new Error(
`The element "${selector}" requires an explicit height`);
}
Expand Down
4 changes: 4 additions & 0 deletions webpack.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ module.exports = (mode) => {
...webpackDevConfig.output,
path: path.join(__dirname, 'lib'),
filename: './[name].js',
library: {
name: 'mergely',
type: 'umd',
}
},
optimization: {
minimize: true,
Expand Down
Loading