4 Replies Latest reply on Apr 20, 2016 11:30 AM by K.Daube

    Have object - want that user sees selection

    K.Daube Level 1

      Dear experts,

      I'm down in the object store and have found a marker. I want that the user sees in the document, what I have found.

      The problem is: how to come from an object to a TextSelection and TextLocation? All I have found goes the other way round.

       

      currentMarker = GetFirstMarker (doc, "#calc"); // this does its job
      doc.TextSelecton = currentMarker;              // no error, no effect 
      doc.ScrollToText(...);                         // requires TextLocation

       

      I have studied more than one diagram of the DOM but still don't see through the fog.

      Klaus

        • 1. Re: Have object - want that user sees selection
          Klaus Göbel Level 3

          Hi Klaus,

          that should work:

           

          var tloc = currentMarker.TextLoc;
          
          var tlocStart = new TextLoc(currentMarker.TextLoc.beg.obj,currentMarker.TextLoc.beg.offset);
          tlocEnd.offset = tlocEnd.offset + 1; // if you want to select the marker
          var tlocEnd = new TextLoc(currentMarker.TextLoc.end.obj,currentMarker.TextLoc.end.offset);      // beg and end  have the same value, but this is to show the complete way
          
          var myTextRange = new TextRange (tlocStart, tlocEnd);   // define a TextRange
          
          doc.TextSelection = myTextRange;  // if you want to select the marker
          
          doc.ScrollToText(myTextRange);                         // requires a TextRange. NOT a location
          
          

           

          In your code line 3 you have to use a TextRange.

           

          This TextRange you get from your Marker's TextLoc (marker.TextLoc)

          • 2. Re: Have object - want that user sees selection
            K.Daube Level 1

            Thanks Klaus,

            Not relevant: line 1 is dangling in the air - tloc not used any further.

            More delicate: currentMarker.TextLoc.beg.obj creates "undefined is not an object".

            but currentMarker.beg.obj creates the same error, as I tried in the following code to have more steps to walk through:

            function DisplayMarker (oDoc, currentMarker) {
              var tloc = currentMarker.TextLoc;  
              // beg and end  have the same value, but this is to show the complete way 
              var begObj    = currentMarker.TextLoc.beg.obj;
              var begOffset = currentMarker.TextLoc.beg.offset;
              var tlocStart = new TextLoc(begObj, begOffset);  
              var tlocEnd =   new TextLoc(currentMarker.TextLoc.end.obj, currentMarker.TextLoc.end.offset);   
              tlocEnd.offset = tlocEnd.offset + 1;            // if you want to select the marker  
                
              var myTextRange = new TextRange (tlocStart, tlocEnd);   // define a TextRange  
              oDoc.TextSelection = myTextRange;               // if you want to select the marker  
              oDoc.ScrollToText(myTextRange);                 // requires a TextRange. NOT a location  
             }

             

            Still confused, but on a higher level ...

            Klaus

            • 3. Re: Have object - want that user sees selection
              Klaus Göbel Level 3

              Hi Klaus,

               

              I have to say sorry. I was lacking in concentration.

               

              Here the right solution. (I hope, this time with better concentration)

               

              This is the way:

              you get the textlocation.

              you create a textrange.

              you select the text.

               

               

              var tloc1 = currentMarker.TextLoc;
              
              var tloc2 = currentMarker.TextLoc;
              tloc2.offset = tloc2.offset+1;
                         
              var myTextRange  = new TextRange(tloc1,tloc2);
                        
              doc.TextSelection = myTextRange ;
                        
              doc.ScrollToText (myTextRange );
              
              • 4. Re: Have object - want that user sees selection
                K.Daube Level 1

                Yes, Klaus, your concentration was excellent!

                function DisplayMarker (oDoc, currentMarker) {
                  var tloc1 = currentMarker.TextLoc;  
                  var tloc2 = currentMarker.TextLoc;  
                  tloc2.offset = tloc2.offset+1;                 // offset2 = offset1 is given by TextLoc 
                  var myTextRange  = new TextRange(tloc1,tloc2); // define a TextRange    
                  oDoc.TextSelection = myTextRange;              // if you want to select the marker  
                  oDoc.ScrollToText(myTextRange);                // requires a TextRange. NOT a location  
                 }
                


                The marker becomes selected in line 7, before the function is left:

                SelectedMarker.png