@Override
public void caretUpdate (CaretEvent e) {

	int dot = e.getDot();
	int mark = e.getMark();
	int begin = Math.min(dot, mark);
//	int length = Math.abs(dot-mark); 



	//try to find current ASection to edit
	
	currentASection = null;
	
	// if found mark the section with caret
	if((dot==mark) && (aDoc.getASection(begin)!=null)) {
		currentASection = aDoc.getASection(begin);
		dot = currentASection.getStartOffset();
		mark = currentASection.getEndOffset();	
		
		Caret c  = textPane.getCaret();
		textPane.removeCaretListener(this);
		
		
		c.setDot(mark);
		c.moveDot(dot);
		
		textPane.addCaretListener(this);
		commentField.getCaret().removeChangeListener(this);
		
		aspectPanel.setPanelEnabled(false);
		AData data = aDoc.getAData(currentASection);
    	aspectPanel.setPanelEnabled(true);
    	setContols(data);
    	
		commentField.getCaret().addChangeListener(this);
	}
	else
	if (dot!=mark){
		    currentASection = aDoc.getASectionThatStartsAt(begin);
		    if (currentASection!=null){ 
		    	AData data = aDoc.getAData(currentASection);
		    	setContols(data);
		    	dot = currentASection.getStartOffset();
				mark = currentASection.getEndOffset();	
				
				Caret c  = textPane.getCaret();
				textPane.removeCaretListener(this);
				
				c.setDot(mark);
				c.moveDot(dot);
				
				textPane.addCaretListener(this);
				setContols(data);
		    } else aspectPanel.setPanelEnabled(false);
			
			aspectPanel.setPanelEnabled(true);

	} else {aspectPanel.setPanelEnabled(false); }
	


}