[MacRuby-devel] Another Cocoa issue

david kramf dakr.012 at gmail.com
Fri Dec 14 03:44:20 PST 2012


Hello,
In the following code I analyze a textView , split it to lines , try to build a Model object from each line , and if  build failed I want to color that line in red. I use setColor:range , but once called this method colors my entire view ( also previous lines ) in red. Can someone tell me what I do wrong?
Thanks, David Kramf

 def textView(textView,doCommandBySelector:sel)
       puts "#{sel.to_s}"
       return false if sel.to_s != "insertNewline:"
       puts " in doCommandBySelector selector is #{sel}"
       @newline = true
       enum = @textView.string.lines(seperaotr=$/)
       @location = 0
       enum.each_with_index do |l,i|
            puts "location is #{@location}"
            words = l.split
            line = Line.new(words[0],words[1])
            @lines[i] = line if @lines[i] != line
            red = NSColor.redColor
            range = NSMakeRange(@location,l.length)
            puts "#{range.location}-#{range.length}"
            @textView.setTextColor(red,range) if line.rule  == nil
            @location = @location + l.length
       end
       false
    end
    

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20121214/43241e91/attachment.html>


More information about the MacRuby-devel mailing list