Fixed canvas width issue
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
/**
|
||||
* Copyright (c) 2012 by Jamie Peabody, http://www.mergely.com
|
||||
* All rights reserved.
|
||||
* Version: 2.5 2012-07-31
|
||||
*/
|
||||
/* required */
|
||||
.mergely-column textarea { width: 80px; height: 200px; }
|
||||
.mergely-column { float: left; }
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
/**
|
||||
* Copyright (c) 2012 by Jamie Peabody, http://www.mergely.com
|
||||
* All rights reserved.
|
||||
* Version: 2.5 2012-07-31
|
||||
*/
|
||||
Mgly = {};
|
||||
|
||||
Object.size = function(obj) {
|
||||
@@ -533,7 +538,7 @@ $.extend(Mgly.mergely.prototype,
|
||||
|
||||
// create the textarea and canvas elements
|
||||
$(this.element).append($('<div class="mergely-margin" style="height: ' + height + '"><canvas id="' + this.id + '-lhs-margin" width="8" height="' + height + '"></canvas></div>'));
|
||||
$(this.element).append($('<div style="width:' + width + '; height:' + height + '" id="' + this.id + '-editor-lhs" class="mergely-column"><textarea style="" id="' + this.id + '-lhs"></textarea></div>'));
|
||||
$(this.element).append($('<div style="width:' + width + '; height:' + height + '" id="' + this.id + '-editor-lhs" class="mergely-column"><textarea style="" id="' + this.id + '-lhs"></textarea></div>'));
|
||||
$(this.element).append($('<div class="mergely-canvas" style="height: ' + height + '"><canvas id="' + this.id + '-lhs-' + this.id + '-rhs-canvas" style="width:28px" width="28px" height="' + height + '"></canvas></div>'));
|
||||
$(this.element).append($('<div style="width:' + width + '; height:' + height + '" id="' + this.id + '-editor-rhs" class="mergely-column"><textarea style="" id="' + this.id + '-rhs"></textarea></div>'));
|
||||
$(this.element).append($('<div class="mergely-margin" style="height: ' + height + '"><canvas id="' + this.id + '-rhs-margin" width="8" height="' + height + '"></canvas></div>'));
|
||||
@@ -671,19 +676,43 @@ $.extend(Mgly.mergely.prototype,
|
||||
_calculate_offsets: function (editor_name1, editor_name2, changes) {
|
||||
if (this.draw_top_offset == null) {
|
||||
var topnode = this.element.find('.CodeMirror-gutter-text pre').first();
|
||||
var top_offset = topnode.offset().top;
|
||||
if (!top_offset) {
|
||||
// try again
|
||||
return;
|
||||
}
|
||||
this.em_height = topnode.get(0).offsetHeight;
|
||||
// this is the distance from the top of the screen
|
||||
this.draw_top_offset = 6.5 - top_offset;
|
||||
this.draw_top_offset = 6.5 - top_offset;
|
||||
if (!this.em_height) {
|
||||
var test = $('<div class="CodeMirror-gutter-text"><pre> </pre></div>');
|
||||
this.em_height = parseInt(test.css('line-height')) - 2;
|
||||
console.warn('Failed to calculate offsets, trying brute-force:', this.em_height);
|
||||
}
|
||||
if (!this.em_height) {
|
||||
console.warn('Failed to calculate offsets, using 18 by default');
|
||||
this.em_height = 18;
|
||||
}
|
||||
this.draw_lhs_min = 0.5;
|
||||
var c = $('#' + editor_name1 + '-' + editor_name2 + '-canvas');
|
||||
if (!c.width()) {
|
||||
console.error('canvas width is 0');
|
||||
return;
|
||||
}
|
||||
this.draw_rhs_max = $('#' + editor_name1 + '-' + editor_name2 + '-canvas').width() - 0.5; //24.5;
|
||||
|
||||
this.draw_lhs_width = 5;
|
||||
this.draw_rhs_width = 5;
|
||||
}
|
||||
this.draw_rhs_width = 5;
|
||||
this.trace('calc', 'change offsets calculated', {top_offset: top_offset, lhs_min: this.draw_lhs_min, rhs_max: this.draw_rhs_max, lhs_width: this.draw_lhs_width, rhs_width: this.draw_rhs_width});
|
||||
}
|
||||
for (var i in changes) {
|
||||
var change = changes[i];
|
||||
/*
|
||||
FIXME
|
||||
var lhslc = this.editor[editor_name1].lineCount();
|
||||
if (change['lhs-line-to'] + 1 >= lhslc) {
|
||||
console.warn('here');
|
||||
}
|
||||
*/
|
||||
change['lhs-y-start'] = this.draw_top_offset + this.editor[editor_name1].charCoords({line: change['lhs-line-from'], ch:0}).y;
|
||||
change['lhs-y-end'] = this.draw_top_offset + this.editor[editor_name1].charCoords({line: change['lhs-line-to']+1, ch:0}).y;
|
||||
@@ -694,7 +723,7 @@ $.extend(Mgly.mergely.prototype,
|
||||
}
|
||||
else if (change['op'] == 'a') {
|
||||
change['lhs-y-start'] = change['lhs-y-end'];
|
||||
}
|
||||
}
|
||||
//this.trace('calc', 'change offsets calculated', i, change);
|
||||
}
|
||||
},
|
||||
@@ -1125,7 +1154,7 @@ $.extend(Mgly.mergely.prototype,
|
||||
},
|
||||
trace: function(name) {
|
||||
if(this.settings._debug.indexOf(name) >= 0) {
|
||||
arguments[0] = name+':';
|
||||
arguments[0] = name+':';
|
||||
console.log(this, [].slice.apply(arguments));
|
||||
}
|
||||
}
|
||||
|
||||
7
lib/mergely.min.js
vendored
7
lib/mergely.min.js
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user