void adjustSelection(JEditorPane pane,HTMLDocument doc,int startOffset,int oldLength){
  int newLength=doc.getLength();
  if (newLength != oldLength && startOffset < newLength) {
    if (startOffset > 0) {
      String text;
      try {
        text=doc.getText(startOffset - 1,1);
      }
 catch (      BadLocationException ble) {
        text=null;
      }
      if (text != null && text.length() > 0 && text.charAt(0) == '\n') {
        pane.select(startOffset,startOffset);
      }
 else {
        pane.select(startOffset + 1,startOffset + 1);
      }
    }
 else {
      pane.select(1,1);
    }
  }
}

void adjustSelection ( JEditorPane pane , HTMLDocument doc , int startOffset , int oldLength ) { int newLength = doc . getLength ( ) ; if ( newLength != oldLength && startOffset < newLength ) { if ( startOffset > 0 ) { String text ; try { text = doc . getText ( startOffset - 1 , 1 ) ; } catch ( BadLocationException ble ) { text = null ; } if ( text != null && text . length ( ) > 0 && text . charAt ( 0 ) == '\n' ) { pane . select ( startOffset , startOffset ) ; } else { pane . select ( startOffset + 1 , startOffset + 1 ) ; } } else { pane . select ( 1 , 1 ) ; } } }
called after an insertion to adjust the selection .
