diff --git a/CHANGES.md b/CHANGES.md index 8d76bc6..4d2659d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,8 @@ # Changes +## 4.1.1: +* patch: fixes issue #95 + ## 4.1.0: * minor: emits 'updated' event after every change. * patch: fixes `scrollTo` that no longer functioned after a codemirror update. diff --git a/package.json b/package.json index c0f4683..e07e865 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mergely", - "version": "4.1.0", + "version": "4.1.1", "description": "A javascript UI for diff/merge", "directories": { "doc": "doc", diff --git a/src/mergely.js b/src/mergely.js index e25d399..a971b76 100644 --- a/src/mergely.js +++ b/src/mergely.js @@ -435,7 +435,7 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, { } if (this.resized) this.resized(); }, - _debug: '', //scroll,draw,calc,diff,markup,change + _debug: '', //scroll,draw,calc,diff,markup,change,init resized: function() { } }, options); @@ -845,23 +845,29 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, { var setv; if (this.settings.lhs) { self.trace('init', 'setting lhs value'); - setv = this.editor[this.id + '-lhs'].getDoc().setValue; - this.settings.lhs(setv.bind(this.editor[this.id + '-lhs'].getDoc())); + this.settings.lhs(function setValue(value) { + this._initializing = true; + this.editor[this.id + '-lhs'].getDoc().setValue(value); + }.bind(this)); } if (this.settings.rhs) { self.trace('init', 'setting rhs value'); - setv = this.editor[this.id + '-rhs'].getDoc().setValue; - this.settings.rhs(setv.bind(this.editor[this.id + '-rhs'].getDoc())); + this.settings.rhs(function setValue(value) { + this._initializing = true; + this.editor[this.id + '-rhs'].getDoc().setValue(value); + }.bind(this)); } this.element.one('updated', () => { + this._initializing = false; if (self.settings.loaded) { self.settings.loaded(); } }); this.trace('init', 'bound'); + this.editor[this.id + '-lhs'].focus(); }, - _scroll_to_change : function(change) { + _scroll_to_change: function(change) { if (!change) return; var self = this; var led = self.editor[self.id+'-lhs']; @@ -872,6 +878,7 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, { if (change["lhs-line-to"] >= 0) { led.scrollIntoView({line: change["lhs-line-to"]}); } + led.focus(); }, _scrolling: function(editor_name) { @@ -1032,8 +1039,9 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, { this.trace('change', 'diff time', Timer.stop()); this.changes = Mgly.DiffParser(d.normal_form()); this.trace('change', 'parse time', Timer.stop()); - if (this._current_diff === undefined && this.changes.length) { - // go to first difference on start-up + if (this._current_diff === undefined && this.changes.length && this._initializing) { + // go to first difference on start-up where values are provided in + // settings. this._current_diff = 0; this._scroll_to_change(this.changes[0]); } diff --git a/webpack.dev.js b/webpack.dev.js index d2ad442..bde8f06 100644 --- a/webpack.dev.js +++ b/webpack.dev.js @@ -39,8 +39,7 @@ module.exports = { plugins: [ new HtmlWebpackPlugin({ - template: 'examples/app.html', - filename: 'mergely.html' + template: path.join(__dirname, 'examples', 'app.html') }), new webpack.ProvidePlugin({ $: 'jquery',