code: function computeSelAfterChange(doc, change, hint) {
      if (hint && typeof hint == "object") // Assumed to be {anchor, head} object
        return {anchor: clipPostChange(doc, change, hint.anchor),
                head: clipPostChange(doc, change, hint.head)};
  
      if (hint == "start") return {anchor: change.from, head: change.from};
  
      var end = changeEnd(change);
      if (hint == "around") return {anchor: change.from, head: end};
      if (hint == "end") return {anchor: end, head: end};
  
      // hint is null, leave the selection alone as much as possible
      var adjustPos = function(pos) {
        if (posLess(pos, change.from)) return pos;
        if (!posLess(change.to, pos)) return end;
  
        var line = pos.line + change.text.length - (change.to.line - change.from.line) - 1, ch = pos.ch;
        if (pos.line == change.to.line) ch += end.ch - change.to.ch;
        return Pos(line, ch);
      };
      return {anchor: adjustPos(doc.sel.anchor), head: adjustPos(doc.sel.head)};
    }
docs: Hint can be null|"end"|"start"|"around"|{anchor,head}