Firefox Range Bug

Today I came across an odd Firefox javascript bug. While trying to manipulate a range object, I ran into a wall that was preventing me from changing it a second time. On my page, I have a script that runs when a user selects text. I then delete the contents and replace it with the same text with a span tag around it. I noticed however, that if I brought up the range object again, it said it had no content. My syntax was simple:

range.deleteContents();
range.insertNode(newContents);

newContents was simply a span element with some text that I had created using the document.createElement method.

This code works exactly as expected in chrome. If I look into the range object, I  correctly have the new contents. In firefox however, the range object was missing all of its delicious contenty goodness. After doing a bit of re-working, I came up with the following solution:

range.deleteContents();
range.insertNode(newContents);
 
range = document.createRange();
range.selectNode(newContents);

The additional 2 lines make it work and it still functions properly in Chrome. Now when I bring up the range object, it has the new content for me to mess around with again.

Using firefox 10.0.2

That Holiday Rush

Going to be working on some last minute Processing.js tickets today and a summary post of 4 months in the open source world so far. Look for more on those later today. I might even add some content to this post, who knows!

Frustrations in C minor

Having been a coder for 12 years, I experienced something very new  today. Often times, I have found myself working in code that I have never seen before. This usually happens when starting a new job, or even a new task at a job. When I started working on the firefox code the other day, I found something completely unanticipated. I couldn’t read the code. Now, saying that is a bit strong. Obviously, any programmer worth their weight in salt can read almost any new language or source code. But the paradigms I faced in the mozilla code were beyond completely foreign to me. It got pretty bad at one point where I questioned my own ability to code in cpp (something I have felt comfortable doing for a long time). It’s nice to know though, that my peers who are working on this with me and even my superiors have this issue at some point. Still, I dont like that feeling.