In your find function:
my $result = $t->FindNext(-forwards, -exact, -nocase, "the"); # /^\
You have the argument '-forwards'. The possible options are documented as '-forward' and '-reverse'.

Note that Tk/Text.pm actually uses the following code:

eval { if ($direction eq '-forward') { $w->markSet('insert', 'sel.last'); $w->markSet('current', 'sel.last'); } else { $w->markSet('insert', 'sel.first'); $w->markSet('current', 'sel.first'); } };
So effectively anything not '-forward' is treated as '-reverse'.

Update - I should have looked further.

After the bit of code I copied above, FindNext calls the Text's search method with $direction as the first parameter. The search method is documented as using '-forwards' or '-backwards'. The C source at tkText.c agrees: the TextSearchCmd function does not mention '-reverse'.

The relevant C is:

arg = argv[i]; ... length = strlen(arg); ... c = arg[1]; if ((c == 'b') && (strncmp(argv[i], "-backwards", length) == 0)) { backwards = 1; ... } else if ((c == 'f') && (strncmp(argv[i], "-forwards", length) == 0)) + { backwards = 0;
Because of the use of strncmp with 'length', either '-forward' or '-forwards' will work correctly in the call to search.

Final answer: in FindNext use '-forward', '-backward', or '-backwards'. Do not use '-reverse' as documented, or '-forwards' like search.

When using search, '-forward', '-forwards', '-backward', or '-backwards' are all acceptable.


Update2: bug report forwarded to slaven@rezic.de. Tk::Text bug report

Update 2010-02-02: Patches in the Perl/Tk subversion repo as r13796.


In reply to Re: Why Findnext does not works? by keszler
in thread Why Findnext does not works? by balee

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.