Skip to content

Commit

Permalink
misc refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Jul 29, 2011
1 parent ba1a972 commit dfcb55e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
16 changes: 8 additions & 8 deletions build/texty.js
Expand Up @@ -869,7 +869,7 @@ Text.prototype.size = function(n){
* @api private
*/

Text.prototype.drawSelection = function(ctx, x, y, height, text){
Text.prototype.drawSelection = function(ctx, x, y, size, text){
var selection = this.selection()
, from = selection.from
, to = selection.to
Expand All @@ -878,7 +878,7 @@ Text.prototype.drawSelection = function(ctx, x, y, height, text){
, last = before[beforeLen - 1]
, selected = text.slice(from, to).split('\n')
, selectionLen = selected.length
, px = height / 2
, px = size / 2
, ox = x
, oy = y
, width
Expand All @@ -887,24 +887,24 @@ Text.prototype.drawSelection = function(ctx, x, y, height, text){
ctx.fillStyle = this._selectionBackgroundColor;

// first
y += (beforeLen - 1) * height;
y += (beforeLen - 1) * size;
width = ctx.measureText(selected[0]).width;
last = ctx.measureText(last).width;
ctx.fillRect(x + last, y - px, width, height);
ctx.fillRect(x + last, y - px, width, size);

// mid
for (var i = 1, len = selectionLen - 1; i < len; ++i) {
y += height;
y += size;
width = ctx.measureText(selected[i]).width;
ctx.fillRect(x, y - px, width, height);
ctx.fillRect(x, y - px, width, size);
}

// last
if (selectionLen < 2) return;
y += height;
y += size;
last = selected[selectionLen - 1];
width = ctx.measureText(last).width;
ctx.fillRect(x, y - px, width, height);
ctx.fillRect(x, y - px, width, size);
};

/**
Expand Down

0 comments on commit dfcb55e

Please sign in to comment.