Sunday, February 21, 2010

Bug 540112

I have been working on my bug for quite some time now, which seems to be, for the majority, trying different things to make it work and reviewing my JavaScript...I am a little out of practice with JavaScript at the moment as I have not done it since second semester in INT222. I missed it, it's a good language...unfortunately nothing I do to make this cursor blink is working...I will need to use an SC.Timer to make it blink but I think I'd have to pass parameters into the timer, as the function that draws the cursor has two parameters: rect, and context. I remember having to make or call a fire method, or something like it, to fire off the function in question but that would also need parameters and you can't send in parameters with the timer's action property.
What I have now is...

The cursor drawing function...

_drawInsertionPoint: function(rect, context) {
var range = this._selectedRange;
var characterRect = this.get('layoutManager').
characterRectForPosition(range.start);

context.save();

context.strokeStyle = this.get('theme').cursorStyle;

context.beginPath();
context.moveTo(characterRect.x + 0.5, characterRect.y);
context.lineTo(characterRect.x + 0.5,
characterRect.y + characterRect.height);
context.closePath();
context.stroke();

context.restore();
},

The timer function...

_cursorBlinkTimer: function() {
this._cursorBlinkTimer = SC.Timer.schedule({
target: this,
action: '_fireDrawInsertionPoint', /*Had _drawInsertionPoint but can't pass in parameters with this */
interval: 250,
repeats: true
});
},

I thought it needed some sort of other method to send in the parameters but that would need to be called using parameters in the action: property above so that couldn't work...

_fireDrawInsertionPoint: function(rect, context) {
if(this.get('isFirstResponder')) {
drawInsertionPoint(rect, context);
}
},

The place that calls the cursor drawing function...

_drawSelection: function(rect, context) {
if (this._rangeIsInsertionPoint(this._selectedRange)) {
this._drawInsertionPoint(rect, context); //Thought this had to be this._cursorBlinkTimer()
} else {
this._drawSelectionHighlight(rect, context);
}
},



So I'm in a bit of a bind and have been looking around for quite some time but am not coming up with much to go on. I even asked Yahoo Answers lol and they said the way it was coded would be tricky. A fellow on irc told me that I should look into property-observing functions of SC...for something like an isCursorVisible property...I've been looking but haven't been coming up with much and that is much different than what I have done so far but anything is acceptable as long as it works and is it good taste. Hmm. Tricky.

No comments:

Post a Comment