if(Debug.SCROLL_TO_DEBUG) Log.log(Log.DEBUG,this,"scrollTo(), lineCount=" + getLineCount());   int extraEndVirt; int lineLength = buffer.getLineLength(line); if(offset > lineLength) { extraEndVirt = charWidth * (offset - lineLength); offset = lineLength; } else extraEndVirt = 0;  int _electricScroll = doElectricScroll && visibleLines - 1 > electricScroll * 2 ? electricScroll : 0;   if(visibleLines <= 1) { if(Debug.SCROLL_TO_DEBUG) Log.log(Log.DEBUG,this,"visibleLines <= 0"); setFirstPhysicalLine(line,_electricScroll); return; }   int screenLine = chunkCache.getScreenLineOfOffset(line,offset); int visibleLines = getVisibleLines(); if(screenLine == -1) { if(Debug.SCROLL_TO_DEBUG) Log.log(Log.DEBUG,this,"screenLine == -1"); ChunkCache.LineInfo[] infos = chunkCache .getLineInfosForPhysicalLine(line); int subregion = ChunkCache.getSubregionOfOffset( offset,infos); int prevLine = displayManager.getPrevVisibleLine(getFirstPhysicalLine()); int nextLine = displayManager.getNextVisibleLine(getLastPhysicalLine()); if(line == getFirstPhysicalLine()) { if(Debug.SCROLL_TO_DEBUG) Log.log(Log.DEBUG,this,line + " == " + getFirstPhysicalLine()); setFirstPhysicalLine(line,subregion - _electricScroll); } else if(line == prevLine) { if(Debug.SCROLL_TO_DEBUG) Log.log(Log.DEBUG,this,line + " == " + prevLine); setFirstPhysicalLine(prevLine,subregion - _electricScroll); } else if(line == getLastPhysicalLine()) { if(Debug.SCROLL_TO_DEBUG) Log.log(Log.DEBUG,this,line + " == " + getLastPhysicalLine()); setFirstPhysicalLine(line, subregion + _electricScroll - visibleLines + (lastLinePartial ? 2 : 1)); } else if(line == nextLine) { if(Debug.SCROLL_TO_DEBUG) Log.log(Log.DEBUG,this,line + " == " + nextLine); setFirstPhysicalLine(nextLine, subregion + electricScroll - visibleLines + (lastLinePartial ? 2 : 1)); } else { if(Debug.SCROLL_TO_DEBUG) { Log.log(Log.DEBUG,this,"neither"); Log.log(Log.DEBUG,this,"Last physical line is " + getLastPhysicalLine()); } setFirstPhysicalLine(line,subregion - visibleLines / 2); if(Debug.SCROLL_TO_DEBUG) { Log.log(Log.DEBUG,this,"Last physical line is " + getLastPhysicalLine()); } } } else if(screenLine < _electricScroll) { if(Debug.SCROLL_TO_DEBUG) Log.log(Log.DEBUG,this,"electric up"); setFirstLine(getFirstLine() - _electricScroll + screenLine); } else if(screenLine > visibleLines - _electricScroll - (lastLinePartial ? 2 : 1)) { if(Debug.SCROLL_TO_DEBUG) Log.log(Log.DEBUG,this,"electric down"); setFirstLine(getFirstLine() + _electricScroll - visibleLines + screenLine + (lastLinePartial ? 2 : 1)); }   if(!displayManager.isLineVisible(line)) return;  Point point = offsetToXY(line,offset,offsetXY); if(point == null)   {  Log.log(Log.ERROR,this,"BUG: screenLine=" + screenLine + ",visibleLines=" + visibleLines + ",physicalLine=" + line + ",offset=" + offset + ",firstPhysicalLine=" + getFirstPhysicalLine() + ",lastPhysicalLine=" + getLastPhysicalLine());  } point.x += extraEndVirt;  if(point.x < 0) { setHorizontalOffset(horizontalOffset - point.x + charWidth + 5); } else if(point.x >= painter.getWidth() - charWidth - 5) { setHorizontalOffset(horizontalOffset + (painter.getWidth() - point.x) - charWidth - 5); }
int line = buffer.getLineOfOffset(offset); scrollTo(line,offset - buffer.getLineStartOffset(line), doElectricScroll);
	public void scrollTo(int line, int offset, boolean doElectricScroll)	{		if(Debug.SCROLL_TO_DEBUG)			Log.log(Log.DEBUG,this,"scrollTo(), lineCount="				+ getLineCount());		//{{{ Get ready		int extraEndVirt;		int lineLength = buffer.getLineLength(line);		if(offset > lineLength)		{			extraEndVirt = charWidth * (offset - lineLength);			offset = lineLength;		}		else			extraEndVirt = 0;		int _electricScroll = doElectricScroll			&& visibleLines - 1 > electricScroll * 2			? electricScroll : 0;		//}}}		if(visibleLines <= 1)		{			if(Debug.SCROLL_TO_DEBUG)				Log.log(Log.DEBUG,this,"visibleLines <= 0");			setFirstPhysicalLine(line,_electricScroll);			return;		}		//{{{ Scroll vertically		int screenLine = chunkCache.getScreenLineOfOffset(line,offset);		int visibleLines = getVisibleLines();		if(screenLine == -1)		{			if(Debug.SCROLL_TO_DEBUG)				Log.log(Log.DEBUG,this,"screenLine == -1");			ChunkCache.LineInfo[] infos = chunkCache				.getLineInfosForPhysicalLine(line);			int subregion = ChunkCache.getSubregionOfOffset(				offset,infos);			int prevLine = displayManager.getPrevVisibleLine(getFirstPhysicalLine());			int nextLine = displayManager.getNextVisibleLine(getLastPhysicalLine());			if(line == getFirstPhysicalLine())			{				if(Debug.SCROLL_TO_DEBUG)					Log.log(Log.DEBUG,this,line + " == " + getFirstPhysicalLine());				setFirstPhysicalLine(line,subregion					- _electricScroll);			}			else if(line == prevLine)			{				if(Debug.SCROLL_TO_DEBUG)					Log.log(Log.DEBUG,this,line + " == " + prevLine);				setFirstPhysicalLine(prevLine,subregion					- _electricScroll);			}			else if(line == getLastPhysicalLine())			{				if(Debug.SCROLL_TO_DEBUG)					Log.log(Log.DEBUG,this,line + " == " + getLastPhysicalLine());				setFirstPhysicalLine(line,					subregion + _electricScroll					- visibleLines					+ (lastLinePartial ? 2 : 1));			}			else if(line == nextLine)			{				if(Debug.SCROLL_TO_DEBUG)					Log.log(Log.DEBUG,this,line + " == " + nextLine);				setFirstPhysicalLine(nextLine,					subregion + electricScroll					- visibleLines					+ (lastLinePartial ? 2 : 1));			}			else			{				if(Debug.SCROLL_TO_DEBUG)				{					Log.log(Log.DEBUG,this,"neither");					Log.log(Log.DEBUG,this,"Last physical line is " + getLastPhysicalLine());				}				setFirstPhysicalLine(line,subregion					- visibleLines / 2);				if(Debug.SCROLL_TO_DEBUG)				{					Log.log(Log.DEBUG,this,"Last physical line is " + getLastPhysicalLine());				}			}		}		else if(screenLine < _electricScroll)		{			if(Debug.SCROLL_TO_DEBUG)				Log.log(Log.DEBUG,this,"electric up");			setFirstLine(getFirstLine() - _electricScroll + screenLine);		}		else if(screenLine > visibleLines - _electricScroll			- (lastLinePartial ? 2 : 1))		{			if(Debug.SCROLL_TO_DEBUG)				Log.log(Log.DEBUG,this,"electric down");			setFirstLine(getFirstLine() + _electricScroll - visibleLines + screenLine + (lastLinePartial ? 2 : 1));		} //}}}		//{{{ Scroll horizontally		if(!displayManager.isLineVisible(line))			return;		Point point = offsetToXY(line,offset,offsetXY);		if(point == null)		// FIXME - we need to reset the state of this window so that it has the right		// dimensions again.		{			Log.log(Log.ERROR,this,"BUG: screenLine=" + screenLine				+ ",visibleLines=" + visibleLines				+ ",physicalLine=" + line				+ ",offset=" + offset				+ ",firstPhysicalLine=" + getFirstPhysicalLine()				+ ",lastPhysicalLine=" + getLastPhysicalLine());		}		point.x += extraEndVirt;		if(point.x < 0)		{			setHorizontalOffset(horizontalOffset				- point.x + charWidth + 5);		}		else if(point.x >= painter.getWidth() - charWidth - 5)		{			setHorizontalOffset(horizontalOffset +				(painter.getWidth() - point.x)				- charWidth - 5);		} //}}}	} //}}}