Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #30294
    Patrick C
    Participant

    Issue
    Select one character (selection size 1).
    Find the same character within the selection.

    Effect
    ✔ Works when using the find dialogue.
    ✘ Fails when using document.selection.Find(…, eeFindNext | eeFindReplaceSelOnly);

    Example
    example

    Increasing the selection’s size to 2 or more works in both cases.

    Code for testing:
    Example code requiring manually selecting d
    Longer example code automatically selecting d

    #30295
    Patrick C
    Participant

    I spent a bit more time on this and it seems that Find in the Selection Only has some additional quirks.

    1) EmEditor doesn’t update the search range when selecting a new one.
    2) EmEditor collapses the selection when it contains only one character (found or not).

    In the following examples the macro code is:

    nFound = document.selection.Find("d", eeFindNext | eeFindReplaceSelOnly);
    status = "nFound = " + nFound;

    Macro find in selection code

    And the find dialogue settings are:
    Find dialogue settings

    Example 1: EmEditor search range.
    In the following example EmEditor incorrectly uses the previous search range when searching in a new search range.
    1) Restart EmEditor
    2) Select the left abcd.
    Left abcd selected
    3) Find d in the selection (dialogue or macro). → Selects the left d ✔
    Found and selected the left d :)
    4) Select the right abcd.
    Right abcd selected
    5) Find d in the selection (dialogue or macro). → Selects the left d 🤔
    Found and selected the d on the left instead of the one on the right
    → EmEditor used the previous search range rather than the current one.

    Example 2: EmEditor one character selection collapse.
    1) Restart EmEditor
    2) Select one character, e.g. d
    Selected d
    3) Find d in the selection → the selection collapses 🤔 (inconsistent with point 5 below).
    Find collapsed the selection
    4) Restart EmEditor
    5) Select two characters, e.g. cd
    Selected cd
    6) Find d in the selection → the selection does not collapse (my preferred behaviour).
    Find selected d
    Btw: When selecting cd and searching for cd, the selection also doesn’t collapse, which is the expected (and in my case preferred) behaviour.

    #30296
    Yutaka Emura
    Keymaster

    The dialog box includes a Count Matches option. To achieve the same result in your macro, make sure to include the eeFindCount flag.
    Using the macro below will give you the same outcome:

    
    nFound = document.selection.Find("d", eeFindNext | eeFindReplaceSelOnly | eeFindCount);
    
    #30303
    Patrick C
    Participant

    Ah 😀 💡, thanks for pointing this out! And sorry, I should have noticed myself.
    This basically means that finding in a one character selection fails with both the search dialogue and the macro:
    Find in a one character fails with both the search dialogue and the EE macro function.

    #30304
    Yutaka Emura
    Keymaster

    This basically means that finding in a one character selection fails with both the search dialogue and the macro:

    That’s because the selection exactly matches the search string. In this case, the command tries to find the next occurrence, but since there isn’t one, the search fails.

    #30305
    Patrick C
    Participant

    Now I get it, and the behaviour is consistent.
    When, for example, selecting «cde» and searching for «cde» in the selection, the search also fails.
    Thank you for clarifying 😃.
    I’ve just purchased an annual subscription. While I’ve been on a lifetime licence since 2015, I thought it was time to say thank you for 10 years of support.

    #30306
    Yutaka Emura
    Keymaster

    We appreciate your support!

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.