Skip to content

Commit

Permalink
patch(#95): fixes cursor focus on init (#133)
Browse files Browse the repository at this point in the history
Co-authored-by: Jamie Peabody <[email protected]>
  • Loading branch information
wickedest and Jamie Peabody authored Oct 15, 2020
1 parent ddeb16e commit bd659ad
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mergely",
"version": "4.1.0",
"version": "4.1.1",
"description": "A javascript UI for diff/merge",
"directories": {
"doc": "doc",
Expand Down
24 changes: 16 additions & 8 deletions src/mergely.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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'];
Expand All @@ -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) {
Expand Down Expand Up @@ -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]);
}
Expand Down
3 changes: 1 addition & 2 deletions webpack.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit bd659ad

Please sign in to comment.