js/tinymce/tinymce.jquery.js
function (rng, forward) {
        var self = this, sel, node, evt;

        if (!isValidRange(rng)) {
          return;
        }

        // Is IE specific range
        if (rng.select) {
          self.explicitRange = null;

          try {
            rng.select();
          } catch (ex) {
            // Needed for some odd IE bug #1843306
          }

          return;
        }

        if (!self.tridentSel) {
          sel = self.getSel();

          evt = self.editor.fire('SetSelectionRange', { range: rng, forward: forward });
          rng = evt.range;

          if (sel) {
            self.explicitRange = rng;

            try {
              sel.removeAllRanges();
              sel.addRange(rng);
            } catch (ex) {
              // IE might throw errors here if the editor is within a hidden container and selection is changed
            }

            // Forward is set to false and we have an extend function
            if (forward === false && sel.extend) {
              sel.collapse(rng.endContainer, rng.endOffset);
              sel.extend(rng.startContainer, rng.startOffset);
            }

            // adding range isn't always successful so we need to check range count otherwise an exception can occur
            self.selectedRange = sel.rangeCount > 0 ? sel.getRangeAt(0) : null;
          }

          // WebKit egde case selecting images works better using setBaseAndExtent when the image is floated
          if (!rng.collapsed && rng.startContainer === rng.endContainer && sel.setBaseAndExtent && !Env.ie) {
            if (rng.endOffset - rng.startOffset < 2) {
              if (rng.startContainer.hasChildNodes()) {
                node = rng.startContainer.childNodes[rng.startOffset];
                if (node && node.tagName === 'IMG') {
                  sel.setBaseAndExtent(
                    rng.startContainer,
                    rng.startOffset,
                    rng.endContainer,
                    rng.endOffset
                  );

                  // Since the setBaseAndExtent is fixed in more recent Blink versions we
                  // need to detect if it's doing the wrong thing and falling back to the
                  // crazy incorrect behavior api call since that seems to be the only way
                  // to get it to work on Safari WebKit as of 2017-02-23
                  if (sel.anchorNode !== rng.startContainer || sel.focusNode !== rng.endContainer) {
                    sel.setBaseAndExtent(node, 0, node, 1);
                  }
                }
              }
            }
          }

          self.editor.fire('AfterSetSelectionRange', { range: rng, forward: forward });
        } else {
          // Is W3C Range fake range on IE
          if (rng.cloneRange) {
            try {
              self.tridentSel.addRange(rng);
            } catch (ex) {
              //IE9 throws an error here if called before selection is placed in the editor
            }
          }
        }
      }
function (rng, forward) {
        var self = this, sel, node, evt;

        if (!isValidRange(rng)) {
          return;
        }

        // Is IE specific range
        if (rng.select) {
          self.explicitRange = null;

          try {
            rng.select();
          } catch (ex) {
            // Needed for some odd IE bug #1843306
          }

          return;
        }

        if (!self.tridentSel) {
          sel = self.getSel();

          evt = self.editor.fire('SetSelectionRange', { range: rng, forward: forward });
          rng = evt.range;

          if (sel) {
            self.explicitRange = rng;

            try {
              sel.removeAllRanges();
              sel.addRange(rng);
            } catch (ex) {
              // IE might throw errors here if the editor is within a hidden container and selection is changed
            }

            // Forward is set to false and we have an extend function
            if (forward === false && sel.extend) {
              sel.collapse(rng.endContainer, rng.endOffset);
              sel.extend(rng.startContainer, rng.startOffset);
            }

            // adding range isn't always successful so we need to check range count otherwise an exception can occur
            self.selectedRange = sel.rangeCount > 0 ? sel.getRangeAt(0) : null;
          }

          // WebKit egde case selecting images works better using setBaseAndExtent when the image is floated
          if (!rng.collapsed && rng.startContainer === rng.endContainer && sel.setBaseAndExtent && !Env.ie) {
            if (rng.endOffset - rng.startOffset < 2) {
              if (rng.startContainer.hasChildNodes()) {
                node = rng.startContainer.childNodes[rng.startOffset];
                if (node && node.tagName === 'IMG') {
                  sel.setBaseAndExtent(
                    rng.startContainer,
                    rng.startOffset,
                    rng.endContainer,
                    rng.endOffset
                  );

                  // Since the setBaseAndExtent is fixed in more recent Blink versions we
                  // need to detect if it's doing the wrong thing and falling back to the
                  // crazy incorrect behavior api call since that seems to be the only way
                  // to get it to work on Safari WebKit as of 2017-02-23
                  if (sel.anchorNode !== rng.startContainer || sel.focusNode !== rng.endContainer) {
                    sel.setBaseAndExtent(node, 0, node, 1);
                  }
                }
              }
            }
          }

          self.editor.fire('AfterSetSelectionRange', { range: rng, forward: forward });
        } else {
          // Is W3C Range fake range on IE
          if (rng.cloneRange) {
            try {
              self.tridentSel.addRange(rng);
            } catch (ex) {
              //IE9 throws an error here if called before selection is placed in the editor
            }
          }
        }
      }
function ( rng , forward ) { var self = this , sel , node , evt ; if ( ! isValidRange ( rng ) ) { return ; } // Is IE specific range if ( rng . select ) { self . explicitRange = null ; try { rng . select ( ) ; } catch ( ex ) { // Needed for some odd IE bug #1843306 } return ; } if ( ! self . tridentSel ) { sel = self . getSel ( ) ; evt = self . editor . fire ( 'SetSelectionRange' , { range : rng , forward : forward } ) ; rng = evt . range ; if ( sel ) { self . explicitRange = rng ; try { sel . removeAllRanges ( ) ; sel . addRange ( rng ) ; } catch ( ex ) { // IE might throw errors here if the editor is within a hidden container and selection is changed } // Forward is set to false and we have an extend function if ( forward === false && sel . extend ) { sel . collapse ( rng . endContainer , rng . endOffset ) ; sel . extend ( rng . startContainer , rng . startOffset ) ; } // adding range isn't always successful so we need to check range count otherwise an exception can occur self . selectedRange = sel . rangeCount > 0 ? sel . getRangeAt ( 0 ) : null ; } // WebKit egde case selecting images works better using setBaseAndExtent when the image is floated if ( ! rng . collapsed && rng . startContainer === rng . endContainer && sel . setBaseAndExtent && ! Env . ie ) { if ( rng . endOffset - rng . startOffset < 2 ) { if ( rng . startContainer . hasChildNodes ( ) ) { node = rng . startContainer . childNodes [ rng . startOffset ] ; if ( node && node . tagName === 'IMG' ) { sel . setBaseAndExtent ( rng . startContainer , rng . startOffset , rng . endContainer , rng . endOffset ) ; // Since the setBaseAndExtent is fixed in more recent Blink versions we // need to detect if it's doing the wrong thing and falling back to the // crazy incorrect behavior api call since that seems to be the only way // to get it to work on Safari WebKit as of 2017-02-23 if ( sel . anchorNode !== rng . startContainer || sel . focusNode !== rng . endContainer ) { sel . setBaseAndExtent ( node , 0 , node , 1 ) ; } } } } } self . editor . fire ( 'AfterSetSelectionRange' , { range : rng , forward : forward } ) ; } else { // Is W3C Range fake range on IE if ( rng . cloneRange ) { try { self . tridentSel . addRange ( rng ) ; } catch ( ex ) { //IE9 throws an error here if called before selection is placed in the editor } } } }
Changes the selection to the specified DOM range.

@method setRng
@param {Range} rng Range to select.
@param {Boolean} forward Optional boolean if the selection is forwards or backwards.
Changes the selection to the specified DOM range .