Search in target is sometimes failing



  • @Peter-Goddard

    yes, it could be that this is not the issue, but a new npp start also means that your data is not the same as before,
    but you certainly have more information to evaluate this than I do,
    I am fishing here more or less in the dark.
    Can you describe in pseudocode what you are doing, maybe this could be helpful to find the issue.



  • @Ekopalypse

    Sure. This plugin just places a “\n” infront every case of “<” in the selected area.

    function(){

    Set the target search area to the area that has been selected.

    Look for the first case of “<” in the targeted area.

    While a, “<” can be found, get the placement of, “<”, insert a “\n” at that spot. Set the beginning of the target search area just ahead of where “<” is now found and increase the end of the target search area by 1. Search again for the next “<” in the target search area

    }



  • @Peter-Goddard

    From your explanation this doesn’t work.
    You need to advance the start by 2, correct?
    Assuming the following, 0123… are positions made visible.

    0123456789
    ab<def<h
    

    position of < is 2 correct?
    Insert c at that position results in

    0123456789
    abc<def<h
    

    and if you set the start now to position+1 (=3) it will re-find the same <

    Sure this is what you do?
    My pseudocode would look like this

    target = selected text
    target_end = last position of selected text
    position = search in target for '<'
    while position > -1:
        insert char '\n' at position 
        reset target_start to position+2 and target_end to target_end+1
        position = search in target for '<'
    


  • @Ekopalypse

    Sorry, I am increasing the start by 2, I just didn’t clarify that. I meant that when I said, “Set the beginning of the target search area just ahead of where “<” is now found”. My mistake. I know my code works because when I select the text,

    <<<<

    it results in

    <
    <
    <
    <

    Sorry for the confusion



  • @Ekopalypse Of course, my code works, until it breaks liked we talked about before



  • @Peter-Goddard

    ok, then I would say it is time to debug/print some info about
    target_start, target_end and position found.
    Make a debug build, use OutputDebugStringW and tools like DebugView
    to capture the output. Of course only, if you can’t run within Visual Studio.



  • Actually, it doesn’t have to be a debug build, a release build should do it as well.



  • @Ekopalypse

    Okay, I’m trying that now. I am using visual studios and I have added in my code a OutputDebugStringW, now where would I find the values that it outputs when I use my plugin in notepad?



  • @Peter-Goddard

    Did you start npp from within Visual Studio or did you attach (from Debug menu) npp to visual studio? If so, those should appear in
    View->Output window.



  • @Ekopalypse

    I think I have made a very obvious mistake. I forgot to specify my search flag as you mentioned in my other post. After switching it to Regexp, it seems to be working. I feel like that was very obvious and you have taken a lot of your time to help me, so thank you again for all your help.

    If anything else happens, I’ll post again. Thanks.


Log in to reply