if (length != 0) {
try {
if (e instanceof SlaveDocumentEvent) {
SlaveDocumentEvent slave= (SlaveDocumentEvent) e;
DocumentEvent master= slave.getMasterEvent();
if (master != null)
preservedText= master.getDocument().get(master.getOffset(), master.getLength());
} else {
preservedText= e.getDocument().get(e.getOffset(), e.getLength());
}