[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Sc-devel] getting line in textView/Document



Hi to all,

In need to get a line from a multiline textview and a Document I wrote this little methods.
Sorry if maybe the same thing can already been done.
In negative case, I find them useful.
Code surely can be cleaned up.
As far as I tested they work fine.


// easier to grab the line where the cursor is placed
// av 8/12/07
 
+ JSCTextView {

getLine { 
var lineSize = 0, index = 0, actualLine ;
var lineArr = this.string.split($\n) ;
var incrementArr = lineArr.collect({|l| lineSize = lineSize+l.size+1}) ;
while ({ incrementArr[index] <= this.selectionStart },
{ index = index + 1 }) ;
^actualLine = lineArr[index] ;
}

}



+ SCTextView {

getLine { 
var lineSize = 0, index = 0, actualLine ;
var lineArr = this.string.split($\n) ;
var incrementArr = lineArr.collect({|l| lineSize = lineSize+l.size+1}) ;
while ({ incrementArr[index] <= this.selectionStart },
{ index = index + 1 }) ;
^actualLine = lineArr[index] ;
}


+ Document {

getLine { 
var lineSize = 0, index = 0, actualLine ;
var lineArr = this.string.split($\n) ;
var incrementArr = lineArr.collect({|l| lineSize = lineSize+l.size+1}) ;
while ({ incrementArr[index] <= this.selectionStart },
{ index = index + 1 }) ;
^actualLine = lineArr[index] ;
}

}

--------------------------------------------------
Andrea Valle
--------------------------------------------------
CIRMA - DAMS
Università degli Studi di Torino
--------------------------------------------------


I did this interview where I just mentioned that I read Foucault. Who doesn't in university, right? I was in this strip club giving this guy a lap dance and all he wanted to do was to discuss Foucault with me. Well, I can stand naked and do my little dance, or I can discuss Foucault, but not at the same time; too much information.
(Annabel Chong)