Find Text using JN for notepad++

Davey
2013-06-05
2013-06-12
  • Davey
    Davey
    2013-06-05

    Hello.
    Can anyone help me with a seemingly simple Javascript...
    (I am not new to scripting... but to Javascript I am new)

    I would like to find text in a document
    and set the selection on that text - and scroll the document to that position.

    I cant seem to figure out how to accomplish this.

    If anyone can help, it will be greatly appreciated!

    Thanks,
    Davey

     
  • Davey
    Davey
    2013-06-10

    Hi
    Maybe if I am more specific someone might know how to help me.
    I already used JN plugin to make a few short scripts which I assigned a shortcut key to.
    I am looking to make another one as such:
    I have many functions in my file... hard to find them.
    When i am in function A, and it calls to function B,
    I would like to select the name of function B, and run a search on "FUNC $(Function name)"
    I.e., I would like the script to take the selected word, add 'FUNC ' before it
    and search that.

    Is this possible in any way?
    I would appreciate any ones help greatly.
    Thanks!

    Davey

     
  • Eugen Kremer
    Eugen Kremer
    2013-06-11

    Hi Davey,

    I think you need something like this:
    var selection = firstView.selection;
    var text = firstView.text;

    var re = new RegExp("FUNC\s+"+selection,"g");
    var charPos = text.search(re);

    if (charPos >= 0){
    // set cursor position to found func
    firstView.pos = charPos;
    // remove selection
    firstView.byteAnchor = firstView.bytePos;
    // scroll to the position
    firstView.lines.current = firstView.lines.current;// returns current line from cursor, and scrolls to the line if we set it
    }

     
  • Davey
    Davey
    2013-06-12

    Thanks Eugen
    That code worked pefect for me.
    This saves me a lot of time!
    Thanks again!!

    P.S.
    1 correction I had to make
    in the following line:
    var re = new RegExp("FUNC\s+"+selection,"g");
    we needed 2 slashes before the s, in order to escape it as such:
    var re = new RegExp("FUNC\s+"+selection,"g");

     
    Last edit: Davey 2013-06-12