Script - UI

David M
2016-07-18
2016-08-15
  • David M

    David M - 2016-07-18

    Hi,
    How can I move cursor from an ui script?
    example: i want to move cursor left.
    from manual:

    %SCRIPT
    var ui = createUI("example.ui");
    ui.test_b.clicked.connect(function(){
            cursor.movePosition(1, cursorEnums.Left); //this doesn't work
            alert("x");})
    registerAsBackgroundScript("abc");
    ui.show();
    

    If I want to get current column or line, cursor.lineNumber() this doesn't work either, but editor.cursor.lineNumber() works.

    (using TeXstudio 2.11.0 (hg 6062:c58c915d7759) - portable on win 7)

    Thanks!
    - David M.

     
    Last edit: David M 2016-07-18
  • Tim Hoffmann

    Tim Hoffmann - 2016-07-18

    The cursor object is created once on generation of the script. It may not be valid later if you make the script persistent, e.g. when your function is executed. In this case, you should create a copy of the current cursor. This is a virtual cursor, you can move it around, select and inspect the text without changing the cursor displayed on screen. To change the cursor on the screen make the virtual cursor, the cursor of the editor (editor.setCursor).

    %SCRIPT
    var ui = createUI("example.ui");
    ui.test_b.clicked.connect(function(){
            c = editor.cursor
            c.movePosition(1, cursorEnums.Left)
            edtior.setCursor(c)
            alert("x");})
    registerAsBackgroundScript("abc");
    ui.show();
    
     
  • David M

    David M - 2016-07-21

    I got another problem, with same function c.movePosition(1, cursorEnums.Left).
    If I set offset -> 10 for example and in document I have this text:

    abcd efgh
    
    ijkl mnop
    ...
    

    current cursor is between "j" and "k". c.movePosition(10, cursorEnums.Left) won't move cursor between "c" and "d" but on starting of empty line.

    How can I disable that behaviour, or there is alternate move function that move correct?

    Thanks again!

                -David M.
    
     
  • Tim Hoffmann

    Tim Hoffmann - 2016-07-21

    this is a bug:
    fixed: hg 6135 (aa5af0e17889)

     
  • David M

    David M - 2016-08-05

    There is any function to check if a script is running in background?
    something like isActive = scriptIsActive("abc"); will return true if there is any script started with registerAsBackgroundScript("abc");

    Thanks!

                -David M.
    
     
  • Tim Hoffmann

    Tim Hoffmann - 2016-08-15

    No, this information is not available.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks