mIRC Homepage
Posted By: Wims $did(dialog,id).caretpos - 29/04/07 12:10 AM
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 )

Posted By: qwerty Re: $did(dialog,id).caretpos - 29/04/07 02:07 AM
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
Posted By: Wims Re: $did(dialog,id).caretpos - 29/04/07 02:20 PM
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 ?
Posted By: qwerty Re: $did(dialog,id).caretpos - 29/04/07 02:43 PM
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.
Posted By: Wims Re: $did(dialog,id).caretpos - 29/04/07 03:55 PM
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 ?

© mIRC Discussion Forums