You have a sorted listwindow. If you are you use /rline in a sorted list, you can easily change the sort order.
In order to work around that, check to see if you have any currently selected lines. If you do, you want to save the actual text of each line selected in a tokenized variable or in a hash table. (In actual practice, you won't check, you'll just $addtok to a variable.
[color:#840017]
var %slines, %i = 1
while $line(@window, $sline(@window, %i).ln) != $null {
%slines = $addtok(%slines, $ifmatch, 255)
inc %i
}
[/color]
If there are no selected lines, it won't even enter the loop. Next, you do whatever code you need to do to rline or dline or whatever you want to do.
[color:#840017]
rline @window 2 New text goes here
; or
dline @window 5
[/color]
Then you just reselect each of the lines by looping through the tokens into $fline.
[color:#840017]
var %i = 1
while $gettok(%slines, %i, 255) {
sline -a @window $fline(@window, $ifmatch, 1)
inc %i
}
[/color]
At this point, your originally selected lines should be back reselected (if there were any). If your lines have very long text and you have a lot of lines selected, you might need to switch to using a temp hash table, storing the values of the selected lines in there, then reversing the process and destroying the hash table when you're done reselecting.
Is this what you had in mind or did I completely miss the point of your post?