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

fix(#209): Fixes issue with options not being preserved when individually set. #211

Merged
merged 1 commit into from
Oct 11, 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
1 change: 0 additions & 1 deletion src/diff-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,6 @@ CodeMirrorDiffView.prototype.bind = function(container) {
ev.preventDefault();
return;
}
const ed = this.editor[side];
// See if the user clicked the line number of a difference:
let found = false;
for (let i = 0; i < this.changes.length; ++i) {
Expand Down
6 changes: 2 additions & 4 deletions src/mergely.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,11 @@ class Mergely {
const colors = dom.getColors(this.el);
this._options = {
...defaultOptions,//lgpl
...this._initOptions,
...(this._options || this._initOptions),
...options//lgpl-separate-notice
};
this._viewOptions = {
...defaultOptions,
...this._initOptions,
...options,
...this._options,
_colors: colors
};
}
Expand Down
3 changes: 0 additions & 3 deletions test/markup.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,6 @@ describe('markup', () => {
name: 'Changes with non-letter chars',
lhs: '~# 00 == ! (dog) \n',
rhs: '~? 11 ++ ] (fox) .\n',
only: true,
check: (editor) => {
expect(editor.querySelectorAll(LHS_CHANGE_START_AND_END + '.cid-0')).to.have.length(1);
expect(editor.querySelectorAll(LHS_INLINE_TEXT + '.cid-0')).to.have.length(6);
Expand All @@ -355,8 +354,6 @@ describe('markup', () => {
for (const value of rhs_changes.values()) {
rhs_values.push(value.innerText);
}
console.log(lhs_values);
console.log(rhs_values);
expect(lhs_values).to.deep.equal(['#', '00', '==', '!', 'd', 'g']);
expect(rhs_values).to.deep.equal(['?', '11', '++', ']', 'f', 'x', '.']);
}
Expand Down
90 changes: 53 additions & 37 deletions test/mergely.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,17 @@ describe('mergely', function () {
try {
const { children } = editor.el.children[0];
const items = Array.from(children).map(a => a.className);
expect(items[0] == 'mergely-margin');
expect(items[1] == 'mergely-column');
// NOTE: if running karma debug, these tests can fail because
// the debugger grabs the focus and the CodeMirror instance
// loses `CodeMirror-focused`
expect(items).to.deep.equal([
'mergely-margin',
'mergely-column',
'CodeMirror cm-s-default CodeMirror-focused',
'mergely-canvas',
'mergely-column',
'CodeMirror cm-s-default',
'mergely-margin',
'mergely-splash'
]);
expect(items[2].indexOf('CodeMirror cm-s-default' == 0));
expect(items[3] == 'mergely-margin');
expect(items[4] == 'mergely-column');
expect(items[5] == 'CodeMirror cm-s-default');
expect(items[6] == 'mergely-column');
expect(items[7] == 'mergely-splash');
expect(editor.get('lhs')).to.equal('');
expect(editor.get('rhs')).to.equal('');
done();
Expand All @@ -99,15 +97,17 @@ describe('mergely', function () {
// NOTE: if running karma debug, these tests can fail because
// the debugger grabs the focus and the CodeMirror instance
// loses `CodeMirror-focused`
expect(items).to.deep.equal([
'mergely-margin',
'mergely-column',
'CodeMirror cm-s-default CodeMirror-focused',
'mergely-canvas',
'mergely-column',
'CodeMirror cm-s-default',
'mergely-margin'
]);
expect(items[0] == 'mergely-margin');
expect(items[1] == 'mergely-column');
// NOTE: if running karma debug, these tests can fail because
// the debugger grabs the focus and the CodeMirror instance
// loses `CodeMirror-focused`
expect(items[2].indexOf('CodeMirror cm-s-default' == 0));
expect(items[3] == 'mergely-margin');
expect(items[4] == 'mergely-column');
expect(items[5] == 'CodeMirror cm-s-default');
expect(items[6] == 'mergely-column');
expect(items[7] == 'mergely-splash');
expect(editor.get('lhs')).to.equal('left-hand side text');
expect(editor.get('rhs')).to.equal('right-hand side text');
done();
Expand All @@ -129,18 +129,17 @@ describe('mergely', function () {
try {
const { children } = editor.el.children[0];
const items = Array.from(children).map(a => a.className);
expect(items[0] == 'mergely-margin');
expect(items[1] == 'mergely-column');
// NOTE: if running karma debug, these tests can fail because
// the debugger grabs the focus and the CodeMirror instance
// loses `CodeMirror-focused`
expect(items).to.deep.equal([
'mergely-margin',
'mergely-column',
'CodeMirror cm-s-default CodeMirror-focused',
'mergely-canvas',
'mergely-column',
'CodeMirror cm-s-default',
'mergely-margin'
]);
expect(items[2].indexOf('CodeMirror cm-s-default' == 0));
expect(items[3] == 'mergely-margin');
expect(items[4] == 'mergely-column');
expect(items[5] == 'CodeMirror cm-s-default');
expect(items[6] == 'mergely-column');
expect(items[7] == 'mergely-splash');
expect(editor.get('lhs')).to.equal('left-hand side text');
expect(editor.get('rhs')).to.equal('right-hand side text');
done();
Expand All @@ -161,18 +160,17 @@ describe('mergely', function () {
try {
const { children } = editor.el.children[0];
const items = Array.from(children).map(a => a.className);
expect(items[0] == 'mergely-margin');
expect(items[1] == 'mergely-column');
// NOTE: if running karma debug, these tests can fail because
// the debugger grabs the focus and the CodeMirror instance
// loses `CodeMirror-focused`
expect(items).to.deep.equal([
'mergely-margin',
'mergely-column',
'CodeMirror cm-s-default CodeMirror-focused',
'mergely-canvas',
'mergely-column',
'CodeMirror cm-s-default',
'mergely-margin'
]);
expect(items[2].indexOf('CodeMirror cm-s-default' == 0));
expect(items[3] == 'mergely-margin');
expect(items[4] == 'mergely-column');
expect(items[5] == 'CodeMirror cm-s-default');
expect(items[6] == 'mergely-column');
expect(items[7] == 'mergely-splash');
expect(children[0].style.visibility).to.equal('hidden');
expect(children[6].style.visibility).to.equal('hidden');
done();
Expand Down Expand Up @@ -503,6 +501,24 @@ describe('mergely', function () {
});
});

it('should preserve changed option', function (done) {
const editor = init({
change_timeout: 0,
license: 'lgpl-separate-notice',
lhs: 'left-hand side text',
rhs: 'right-hand side text'
});
editor.once('updated', () => {
editor.options({ sidebar: false });
expect(editor.options().wrap_lines).to.equal(false, 'wrap_lines');
expect(editor.options().sidebar).to.equal(false, 'sidebar');
editor.options({ wrap_lines: false });
expect(editor.options().wrap_lines).to.equal(false, 'wrap_lines-2');
expect(editor.options().sidebar).to.equal(false, 'sidebar-2');
done();
});
});

it('should ignore white-space', function (done) {
const editor = init({
height: 100,
Expand Down
Loading