mIRC Home    About    Download    Register    News    Help

Print Thread
#175812 29/04/07 12:10 AM
Joined: Jul 2006
Posts: 4,145
W
Wims Offline OP
Hoopy frood
OP Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
I would like to see this return the position of the cursor in an edit multi-lines because i've tried to make it with alias but i failed...

i know that dcx can do it.

Also, i think a switch for /did which not scroll the scrollbar ( for -adior and if have one )


Last edited by Wims; 29/04/07 01:34 AM.

#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Quote:
I would like to see this return the position of the cursor in an edit multi-lines because i've tried to make it with alias but i failed...
This is already possible in editboxes in general with $did(name,id).selstart/selend. Apparently it only works in editboxes and not in an editable comboboxes.

Regarding multi-line editboxes, $did().selstart/end there return the positions counting from the very beginning of the text (line 1), so if you editbox contained this for example:

abc
def
g|hi

$did().selstart/end would return 11 (including enter = crlf = 2 chars)

You can translate that to a line-based position with something like this:
Code:
alias linesel {
  var %s1 = $did($1,$2).selstart, %e1 = $did($1,$2).selend, %sel = $did($1,$2,1).sel
  did -c $1-2 %sel
  var %s2 = %s1 - $did($1,$2).selstart, %e2 = $calc(%e1 + %s2 - %s1)
  did -c $1-2 %sel $calc(%s2 +1) $calc(%e2 +1)
  return %s2 %e2
}
$linesel(name,id) returns "X Y" where X = line-based .selstart and Y = line-based .selend.

As the code implies, you can get the number of the line that contains the cursor with $did(name,id,1).sel

Edit: btw it won't work quite correctly if a multi-line segment of the editbox text is selected. In that case, two numbers aren't even enough to provide all necessary information, so a little more complex script would be required (you should be able to modify the current one).

Edit 2: thought of a better method

Last edited by qwerty; 29/04/07 10:53 AM.

/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Jul 2006
Posts: 4,145
W
Wims Offline OP
Hoopy frood
OP Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
Don't care about text actually selected so thx, but why you put %s2 and %e2, i just want, the line ( i knew for ($did(dname,id).sel ) and the pos in the line and why do you move the cursor position with /did -c ?


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
If no text is selected, both .selstart and .selend return the same number, which is effectively the cursor position. If text is selected, the cursor could be either at .selstart or at .selend (there is no simple/elegant way to know which one in this case).

You should check whether the two numbers returned by $linesel() are equal. If they are, problem solved; if not, it's up to you to decide which number to use as the cursor position.

The first /did -c is used to temporarily move the cursor to the beginning of the line. Comparing .selstart (and .selend) before and after that /did -c allows you to retrieve the position of the cursor within the line, which is what you want. The second /did -c simply restores the original .selstart/end.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Jul 2006
Posts: 4,145
W
Wims Offline OP
Hoopy frood
OP Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
ok i will see but if this can be added in mirc it better wink

Hum it seems that $did(dname,id).sel not return the number of lines selected, a bug ?


Last edited by Wims; 29/04/07 04:15 PM.

#mircscripting @ irc.swiftirc.net == the best mIRC help channel

Link Copied to Clipboard