int electricScroll = (doElectricScroll ? this.electricScroll : 0);
int electricScroll;  if(doElectricScroll && visibleLines > this.electricScroll * 2) electricScroll = this.electricScroll; else electricScroll = 0;
	public void scrollToCaret(boolean doElectricScroll)	{		int caretLine = getCaretLine();		int offset = getCaretPosition() - getLineStartOffset(caretLine);		int virtualCaretLine = buffer.physicalToVirtual(caretLine);		// visibleLines == 0 before the component is realized		// we can't do any proper scrolling then, so we have		// this hack...		if(visibleLines == 0)		{			setFirstLine(caretLine - electricScroll);			return;		}		int electricScroll = (doElectricScroll ? this.electricScroll : 0);		boolean changed = false;		int _firstLine = firstLine + electricScroll;		int _lastLine = firstLine + visibleLines - electricScroll;		if(virtualCaretLine > _firstLine && virtualCaretLine < _lastLine)		{			// vertical scroll position is correct already		}		else if(_firstLine - virtualCaretLine > visibleLines			|| virtualCaretLine - _lastLine > visibleLines)		{			int virtualMarkLine = buffer.physicalToVirtual(getMarkLine());			// center {markLine,caretLine} on screen			firstLine = virtualMarkLine - (visibleLines				- virtualCaretLine + virtualMarkLine) / 2; 			firstLine = Math.max(virtualCaretLine - visibleLines				+ electricScroll + 1,firstLine); 			firstLine = Math.min(virtualCaretLine /* + visibleLines */				- electricScroll,firstLine);			changed = true;		}		else if(virtualCaretLine < _firstLine)		{			firstLine = Math.max(0,virtualCaretLine - electricScroll);			changed = true;		}		else if(virtualCaretLine >= _lastLine)		{			firstLine = (virtualCaretLine - visibleLines)				+ electricScroll + 1;			if(firstLine >= getVirtualLineCount() - visibleLines)				firstLine = getVirtualLineCount() - visibleLines;			changed = true;		}		int x = offsetToX(caretLine,offset);		int width = painter.getFontMetrics().charWidth('w');		if(x < 0)		{			horizontalOffset = Math.min(0,horizontalOffset				- x + width + 5);			changed = true;		}		else if(x >= painter.getWidth() - width - 5)		{			horizontalOffset = horizontalOffset +				(painter.getWidth() - x) - width - 5;			changed = true;		}		if(changed)		{			if(firstLine < 0)				firstLine = 0;			physFirstLine = buffer.virtualToPhysical(firstLine);			updateScrollBars();			painter.repaint();			gutter.repaint();			view.synchroScrollVertical(this,firstLine);			view.synchroScrollHorizontal(this,horizontalOffset);		}	}