Skip to main content
Klaus Göbel
Braniac
February 13, 2017
Answered

Put focus on insertion point..

  • February 13, 2017
  • 1 reply
  • 7751 views

I'm trying to put the focus on the insertion point after inserting text from a palette without mouseclick.

I just want to continue writing at that point.

Things I've already tested:

- scrollToText

- oDoc.IsInFront = 1

- oDoc.TextSelection = tRange

Has anybody solved this problem?

var w = new Window ("palette","INSERT");

    w.Button = w.add("button",undefined,"Go")

    w.Button.onClick = Insert;

    w.show()

function Insert()

{

var oDoc = app.ActiveDoc

var textLoc = oDoc.TextSelection.beg; 

oDoc.AddText (textLoc, "Test"); 

}

This topic has been closed for replies.
Correct answer yatani

Following Markus' last advice I can place the text:

#target framemaker
var w = new Window ("palette","INSERT"); 
        w.Button = w.add("button",undefined,"Go") 
        w.Button.onClick = Insert; 
        w.show() 

function Insert()  { 
    var oDoc = app.ActiveDoc 
    var textLoc = oDoc.TextSelection.beg;
    w.active = false;   // Markus' suggestion
    oDoc.AddText (textLoc, "Test");   
}

So, does this work in a real-world script also?


You may have already solved it, but using Fcodes() will do the trick.

#target framemaker
var w = new Window ("palette","INSERT");
    w.Button = w.add("button",undefined,"Go")
    w.Button.onClick = Insert;
    w.show()

function Insert() {
    var oDoc = app.ActiveDoc;
    var textLoc = oDoc.TextSelection.beg;
    //A graphic toolbar appears and App focus returns to document.
    Fcodes([FCodes.KBD_TOOLWIN]);
    oDoc.AddText (textLoc, "Test");
}

1 reply

K.Daube
Braniac
February 13, 2017

Klaus,

I have a function DisplayMarker which might give a hint:

function DisplayMarker (oDoc, oCurrentMarker) {
//          Select marker to visualize the location of the current marker
//          (Text Symbols must be on to see it)
var myTextRange, oTextLoc1, oTextLoc2;

  if (oCurrentMarker.ObjectValid()) {
    oTextLoc1 = oCurrentMarker.TextLoc;
    oTextLoc2 = oCurrentMarker.TextLoc;
  } else {
    alert ("DisplayMarker:\nPgm error: oCurrentMarker not defined.", DisplayMarker.name, true);
    return false;
  }
  oTextLoc2.offset = oTextLoc2.offset+1;                  // offset2 = offset1 is given by oTextLoc
  myTextRange  = new TextRange(oTextLoc1,oTextLoc2);      // define a TextRange   
  oDoc.TextSelection = myTextRange;              // if you want to select the marker 
  oDoc.ScrollToText(myTextRange);                // requires a TextRange. NOT a location 
} //--- end DisplayMarker

It works fine.

Klaus Göbel
Braniac
February 13, 2017

Hi Klaus,

thanks a lot for your suggestions.

The problem is, to put the focus on the document, when working with a palette-window.

In my little script above, when you click "Go", the text is inserted at the insertion point.

What I want to do then is, just to write in the document, without clicking with the mouse to the insertion point.

Things I've already tested:

- scrollToText

- oDoc.IsInFront = 1

- oDoc.TextSelection = tRange

I've also tested Shift - F7: no success.

K.Daube
Braniac
February 13, 2017

Now I understand: I also had no success in doing this.

I needed to resort to "documentation change"...

function SetFocusToDoc (oDoc) { //=== Set focus back to document after invoking panel =============

// Comment  Since the panels are per definition 'in front' they can not be influenced to give
//          focus back to the document. The user must click into the document to get it in focus
//          to be able to enter another shortcut. Of course the focus of the panel is left also
//          when reaching for the menu.
//          HENCE THIS FUNCTION IS NOT USED …
// Reference Klaus Göbel at https://forums.adobe.com/thread/2240541
var oTextRange, fcode = [];

  oTextRange = oDoc.TextSelection;
  oDoc.ScrollToText (oTextRange);
  oDoc.IsInFront = 0;                            // method Klaus Göbel -> no effect
  oDoc.IsInFront = 1;
  fcode[0] = FCodes.FOCUS_INPUT_DOC;  // <Definition \x620> new idea - no effect
    Fcodes(fcode);
} //--- end SetFocusToDoc

This seems to be a panel quirk