diff --git a/examples/ajax.html b/examples/ajax.html index dbc1c89..16926f1 100644 --- a/examples/ajax.html +++ b/examples/ajax.html @@ -13,40 +13,116 @@ This example demonstrates how to set left and right editors using ajax. - + - + - + + + + + +
Drop files here
ignore witespaces
+
+ + + +
  save   save
diff --git a/lib/codemirror.css b/lib/codemirror.css index 8de0b19..a831faa 100644 --- a/lib/codemirror.css +++ b/lib/codemirror.css @@ -3,7 +3,7 @@ .CodeMirror { /* Set height, width, borders, and global font properties here */ font-family: monospace; - height: 300px; + height: 400px; } .CodeMirror-scroll { /* Set scrolling behaviour here */ diff --git a/lib/mergely.js b/lib/mergely.js index a2bc3cb..dc6161a 100644 --- a/lib/mergely.js +++ b/lib/mergely.js @@ -725,7 +725,7 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, { self.settings.current_diff++; self.settings.current_diff = Math.min(self.settings.current_diff, changes.length-1); - scroll_to_change(changes[self.settings.current_diff]); + self._scroll_to_change(changes[self.settings.current_diff]); self._changed(self.id + '-lhs', self.id + '-rhs'); break; @@ -737,7 +737,7 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, { self.settings.current_diff--; self.settings.current_diff = Math.max(self.settings.current_diff, 0); - scroll_to_change(changes[self.settings.current_diff]); + self._scroll_to_change(changes[self.settings.current_diff]); self._changed(self.id + '-lhs', self.id + '-rhs'); break; @@ -773,11 +773,14 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, { return changes; } - function scroll_to_change(change) { + }, + + _scroll_to_change : function(change) { + var self = this; var led = self.editor[self.id+'-lhs']; var red = self.editor[self.id+'-rhs']; - var yref = led.getScrollerElement().offsetHeight * 1/2; // center between 0 and 1/2 + var yref = led.getScrollerElement().offsetHeight * 1/2; // center between >0 and 1/2 // using directly CodeMirror breaks canvas alignment // var ly = led.charCoords({line: Math.max(change["lhs-line-from"],0), ch: 0}, "local").top; @@ -790,7 +793,6 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, { red.scrollTo(null, Math.max(change["rhs-y-start"]-yref, 0)); // right pane should simply follows - } }, _scrolling: function(editor_name) { @@ -949,6 +951,12 @@ 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!==0) { + // go to first differnece on start-up + this.current_diff = 0; + this._scroll_to_change(this.changes[0]); + } + this.trace('change', 'scroll_to_change time', timer.stop()); this._calculate_offsets(editor_name1, editor_name2, this.changes); this.trace('change', 'offsets time', timer.stop()); this._markup_changes(editor_name1, editor_name2, this.changes);