Revision: 22366
http://jedit.svn.sourceforge.net/jedit/?rev=22366&view=rev
Author: ezust
Date: 2012-10-13 22:21:34 +0000 (Sat, 13 Oct 2012)
Log Message:
-----------
Merge request 3577121: Fix for 2832769, 2998294, and 3193168
Modified Paths:
--------------
jEdit/branches/5.0.x/doc/CHANGES.txt
jEdit/branches/5.0.x/doc/whatsnew/news.xml
jEdit/branches/5.0.x/org/gjt/sp/jedit/textarea/Anchor.java
jEdit/branches/5.0.x/org/gjt/sp/jedit/textarea/BufferHandler.java
jEdit/branches/5.0.x/org/gjt/sp/jedit/textarea/ChunkCache.java
jEdit/branches/5.0.x/org/gjt/sp/jedit/textarea/DisplayManager.java
jEdit/branches/5.0.x/org/gjt/sp/jedit/textarea/FirstLine.java
jEdit/branches/5.0.x/org/gjt/sp/jedit/textarea/ScreenLineManager.java
jEdit/branches/5.0.x/org/gjt/sp/jedit/textarea/ScrollLineCount.java
jEdit/branches/5.0.x/org/gjt/sp/jedit/textarea/TextArea.java
Property Changed:
----------------
jEdit/branches/5.0.x/
Property changes on: jEdit/branches/5.0.x
___________________________________________________________________
Modified: svn:mergeinfo
- /jEdit/branches/docking_framework:13128-13258
/jEdit/trunk:21791-21792,21800-21801,21816,21880,21917,21933,21965-21966,21974,21981,21998-22000,22055,22077,22085-22086,22088,22108,22169,22192,22230-22231,22264,22273,22276,22364
+ /jEdit/branches/docking_framework:13128-13258
/jEdit/trunk:21791-21792,21800-21801,21816,21880,21917,21933,21965-21966,21974,21981,21998-22000,22055,22077,22085-22086,22088,22108,22169,22192,22230-22231,22264,22273,22276,22361,22363-22364
Modified: jEdit/branches/5.0.x/doc/CHANGES.txt
===================================================================
--- jEdit/branches/5.0.x/doc/CHANGES.txt 2012-10-13 21:55:51 UTC (rev 22365)
+++ jEdit/branches/5.0.x/doc/CHANGES.txt 2012-10-13 22:21:34 UTC (rev 22366)
@@ -4,13 +4,17 @@
{{{ Version 5.0pre2
-Thanks to Jarek Czekalski, Eric Le Lay, Matthieu Casanova, Tom Power, Malathi,
-Vladimir Avondin, and Alan Ezust for contributing to this release.
+Thanks to Jarek Czekalski, Eric Le Lay, Matthieu Casanova, Tom Power, Malathi,
+Thomas Meyer, Vladimir Avondin, and Alan Ezust for contributing to this release.
{{{ Bug fixes
- Fix broken keymap properties (Björn "Vampire" Kautler)
+- Fixed a number of scrollbar bugs related to undo, multiline cut,
+ soft-wrap, and folding.
+ (Patch#3567959, Bugs #2832769, #2998294, and #3193168 - Thomas Meyer)
+
- Fix broken macro Files/Glob_close.bsh (Eric Le Lay)
- File status checking before save (#3562315, Alan Ezust)
@@ -55,7 +59,7 @@
Anson, Matthieu Casanova, Olivier Pisano, Jimmy Chaw, peibl, Robert Schwenn,
Martin Raspe, Max Funk, SPennington, Ingo Tomahogh, Jarek Czekalski, Jojaba,
Stephen Blackheath, Milan Černil, Makarius, Chris Sullins, Peter C. Chapin,
-Thomas Meyer, Tom Power and Donovaly for contributing to this release.
+Tom Power and Donovaly for contributing to this release.
{{{ Bug fixes
@@ -364,7 +368,7 @@
- New FileOpenerService, Offered by FastOpen 2.5, SmartOpen 1.1.
Used by ErrorList 2.0 (#3481157 Alan Ezust)
-- jeditresource:/ URL handler now also checks jEditHome for files so
+- jeditresource:/ URL handler now also checks jEditHome for files so
it can be used to link to core documentation. (#3565139 Alan Ezust)
- Macros folder can now be localized with properties
Modified: jEdit/branches/5.0.x/doc/whatsnew/news.xml
===================================================================
--- jEdit/branches/5.0.x/doc/whatsnew/news.xml 2012-10-13 21:55:51 UTC (rev 22365)
+++ jEdit/branches/5.0.x/doc/whatsnew/news.xml 2012-10-13 22:21:34 UTC (rev 22366)
@@ -21,6 +21,12 @@
<listitem><para> Updated html/css edit modes with HTML5/CSS3 keywords.
</para></listitem>
+ <listitem><para> Scrolling - Many bugs (#2832769, #2998294, #3193168,
+ possibly others), related to soft wrap, multiline delete/cut, undo, and
+ folding, that could cause the text area to be confused about its location,
+ are fixed. This greatly improves the stability of jEdit. Thank you,
+ Thomas Meyer!! </para></listitem>
+
<listitem><para> Localization - jEdit now supports switching
between default locale, French, German, Russian, Czech, and Japanese.
Some translations for those locales are provided, containing
Modified: jEdit/branches/5.0.x/org/gjt/sp/jedit/textarea/Anchor.java
===================================================================
--- jEdit/branches/5.0.x/org/gjt/sp/jedit/textarea/Anchor.java 2012-10-13 21:55:51 UTC (rev 22365)
+++ jEdit/branches/5.0.x/org/gjt/sp/jedit/textarea/Anchor.java 2012-10-13 22:21:34 UTC (rev 22366)
@@ -22,9 +22,6 @@
package org.gjt.sp.jedit.textarea;
-import org.gjt.sp.jedit.Debug;
-import org.gjt.sp.util.Log;
-
/**
* A base point for physical line/screen line conversion.
* @author Slava Pestov
@@ -32,26 +29,47 @@
*/
abstract class Anchor
{
- protected final DisplayManager displayManager;
- protected final TextArea textArea;
- /** The physical line. */
- int physicalLine;
+ private final DisplayManager displayManager;
+ private final TextArea textArea;
+
/**
- * The visible line index. (from the top of the buffer). It can be different from physical line
- * when using soft wrap.
+ * Class ScrollLineCount:
+ * The total number of physical lines in this buffer
+ * (visible and invisible lines)
+ *
+ * Class FirstLine:
+ * The physical line number of this Anchor in the Buffer.
+ * The first visible physical line index
+ * (only visible lines are processed).
*/
- int scrollLine;
+ private int physicalLine;
+
+ /**
+ * Class ScrollLineCount:
+ * The number of visible lines (from the top of the buffer).
+ * It can be different from physical line when using soft wrap.
+ * or when using folding, if the foldings are collapsed
+ *
+ * Class FirstLine:
+ * Physical line number of the scroll line
+ * (only visible lines are processed)
+ */
+ private int scrollLine;
+
/**
* If this is set to true, the changed() method will be called in
* {@link DisplayManager#notifyScreenLineChanges()}
*/
- boolean callChanged;
+ private boolean callChanged;
/**
* If this is set to true, the reset() method will be called in
* {@link DisplayManager#notifyScreenLineChanges()}
*/
- boolean callReset;
+ private boolean callReset;
+ int preContentInsertedScrollLines;
+ int preContentRemovedScrollLines;
+
//{{{ Anchor constructor
protected Anchor(DisplayManager displayManager,
TextArea textArea)
@@ -68,27 +86,42 @@
@Override
public String toString()
{
- return getClass().getName() + '[' + physicalLine + ','
- + scrollLine + ']';
+ return getClass().getName() + '[' + getPhysicalLine() + ',' + getScrollLine() + ']';
} //}}}
+ void movePhysicalLine(int numLines)
+ {
+ if(numLines == 0)
+ return;
+ setPhysicalLine(getPhysicalLine() + numLines);
+ }
+
+ void moveScrollLine(int numLines)
+ {
+ if(numLines == 0)
+ return;
+ setScrollLine(getScrollLine() + numLines);
+ }
+
+ //{{{ preContentInserted() method
+ /**
+ * Some content is inserted.
+ *
+ * @param startLine the start of the insert
+ * @param numLines the number of inserted lines
+ */
+ abstract void preContentInserted(int startLine, int numLines);
+ //}}}
+
//{{{ contentInserted() method
/**
* Some content is inserted.
*
* @param startLine the start of the insert
- * @param numLines the number of insterted lines
+ * @param numLines the number of inserted lines
*/
- void contentInserted(int startLine, int numLines)
- {
- // The Anchor is changed only if the content was inserted before
- if(physicalLine >= startLine)
- {
- if(physicalLine != startLine)
- physicalLine += numLines;
- callChanged = true;
- }
- } //}}}
+ abstract void contentInserted(int startLine, int numLines);
+ //}}}
//{{{ preContentRemoved() method
/**
@@ -98,58 +131,83 @@
* @param offset the offset in the start line
* @param numLines the number of removed lines
*/
- void preContentRemoved(int startLine, int offset, int numLines)
+
+ abstract void preContentRemoved(int startLine, int offset, int numLines);
+ //}}}
+
+ //{{{ preContentRemoved() method
+ /**
+ * Method called before a content is removed from a buffer.
+ *
+ * @param startLine the first line of the removed content
+ * @param offset the offset in the start line
+ * @param numLines the number of removed lines
+ */
+ abstract void contentRemoved(int startLine, int offset, int numLines);
+ //}}}
+
+ int getPhysicalLine()
{
- if(Debug.SCROLL_DEBUG)
- Log.log(Log.DEBUG,this,"preContentRemoved() before:" + this);
- // The removed content starts before the Anchor, we need to pull the anchor up
- if(physicalLine >= startLine)
+ return physicalLine;
+ }
+
+ void setPhysicalLine(int physicalLine)
+ {
+ assert physicalLine >= 0;
+ if(this.physicalLine != physicalLine)
{
- if(physicalLine == startLine)
- callChanged = true;
- else
- {
- int end = Math.min(startLine + numLines, physicalLine);
- //Check the lines from the beginning of the removed content to the end (or the physical
- //line of the Anchor if it is before the end of the removed content
+ setCallChanged(true);
+ this.physicalLine = physicalLine;
+ }
+ }
- //int loopStart = startLine + 1;
+ int getScrollLine()
+ {
+ return scrollLine;
+ }
- //{{{ treatment if the beginning of the deleted content is inside a physical line that has several line counts
- /*if (displayManager.isLineVisible(startLine))
- {
- int screenLineCount = displayManager.screenLineMgr.getScreenLineCount(startLine);
- if (screenLineCount > 1)
- {
- int lineStartOffset = textArea.getLineStartOffset(startLine);
+ void setScrollLine(int scrollLine)
+ {
+ assert scrollLine >= 0;
+ if(this.scrollLine != scrollLine)
+ {
+ setCallChanged(true);
+ this.scrollLine = scrollLine;
+ }
+ }
- int startScreenLine = textArea.getScreenLineOfOffset(lineStartOffset);
- int deleteStartScreenLine = textArea.getScreenLineOfOffset(offset);
- if (startScreenLine != deleteStartScreenLine)
- {
- loopStart = startLine + 2;
- scrollLine -= screenLineCount - deleteStartScreenLine + startScreenLine;
- }
- }
- }*/
- //}}}
+ boolean isCallChanged()
+ {
+ return callChanged;
+ }
- for(int i = startLine + 1; i <= end; i++)
- {
- //XXX
- if(displayManager.isLineVisible(i))
- {
- scrollLine -=
- displayManager
- .screenLineMgr
- .getScreenLineCount(i);
- }
- }
- physicalLine -= end - startLine;
- callChanged = true;
- }
- }
- if(Debug.SCROLL_DEBUG)
- Log.log(Log.DEBUG,this,"preContentRemoved() after:" + this);
- } //}}}
+ void setCallChanged(boolean callChanged)
+ {
+ this.callChanged = callChanged;
+ }
+
+ boolean isCallReset() {
+ return callReset;
+ }
+
+ void setCallReset(boolean callReset)
+ {
+ this.callReset = callReset;
+ }
+
+ DisplayManager getDisplayManager()
+ {
+ return displayManager;
+ }
+
+ TextArea getTextArea()
+ {
+ return textArea;
+ }
+
+ void resetCallState()
+ {
+ callChanged = false;
+ callReset = false;
+ }
}
Modified: jEdit/branches/5.0.x/org/gjt/sp/jedit/textarea/BufferHandler.java
===================================================================
--- jEdit/branches/5.0.x/org/gjt/sp/jedit/textarea/BufferHandler.java 2012-10-13 21:55:51 UTC (rev 22365)
+++ jEdit/branches/5.0.x/org/gjt/sp/jedit/textarea/BufferHandler.java 2012-10-13 22:21:34 UTC (rev 22366)
@@ -108,11 +108,8 @@
if(textArea.getDisplayManager() == displayManager)
{
- if(numLines != 0)
- {
- firstLine.contentInserted(startLine,numLines);
- scrollLineCount.contentInserted(startLine,numLines);
- }
+ firstLine.contentInserted(startLine,numLines);
+ scrollLineCount.contentInserted(startLine,numLines);
if(delayedUpdateEnd >= startLine)
delayedUpdateEnd += numLines;
@@ -152,8 +149,8 @@
}
else
{
- firstLine.callReset = true;
- scrollLineCount.callReset = true;
+ firstLine.setCallReset(true);
+ scrollLineCount.setCallReset(true);
}
} //}}}
@@ -169,9 +166,14 @@
*/
public void preContentInserted(JEditBuffer buffer, int startLine, int offset, int numLines, int length)
{
+ if(buffer.isLoading())
+ return;
+
if(textArea.getDisplayManager() == displayManager)
{
getReadyToBreakFold(startLine);
+ displayManager.firstLine.preContentInserted(startLine, numLines);
+ displayManager.scrollLineCount.preContentInserted(startLine, numLines);
}
} //}}}
@@ -204,7 +206,7 @@
else
{
int lastLine = startLine + numLines;
- if(!displayManager.isLineVisible(startLine)
+ if( !displayManager.isLineVisible(startLine)
|| !displayManager.isLineVisible(lastLine)
|| offset != buffer.getLineStartOffset(startLine)
|| offset + length != buffer.getLineStartOffset(lastLine))
@@ -215,16 +217,13 @@
else
{
// The removal will not touch
- // inside of folds and wll not
+ // inside of folds and will not
// modify any remaining lines.
}
}
- if(numLines != 0)
- {
- firstLine.preContentRemoved(startLine,offset, numLines);
- scrollLineCount.preContentRemoved(startLine, offset, numLines);
- }
+ firstLine.preContentRemoved(startLine,offset, numLines);
+ scrollLineCount.preContentRemoved(startLine, offset, numLines);
if(delayedUpdateEnd >= startLine)
delayedUpdateEnd -= numLines;
@@ -232,8 +231,8 @@
}
else
{
- firstLine.callReset = true;
- scrollLineCount.callReset = true;
+ firstLine.setCallReset(true);
+ scrollLineCount.setCallReset(true);
}
displayManager.screenLineMgr.contentRemoved(startLine,numLines);
@@ -246,30 +245,17 @@
if(displayManager.folds.preContentRemoved(startLine,numLines))
{
displayManager.folds.reset(buffer.getLineCount());
- firstLine.callReset = true;
- scrollLineCount.callReset = true;
+ firstLine.setCallReset(true);
+ scrollLineCount.setCallReset(true);
}
- if(firstLine.physicalLine
- > displayManager.getLastVisibleLine()
- || firstLine.physicalLine
- < displayManager.getFirstVisibleLine())
+ if(firstLine.getPhysicalLine() > displayManager.getLastVisibleLine() ||
+ firstLine.getPhysicalLine() < displayManager.getFirstVisibleLine() )
{
// will be handled later.
// see comments at the end of
// transactionComplete().
}
- // very subtle... if we leave this for
- // ensurePhysicalLineIsVisible(), an
- // extra line will be added to the
- // scroll line count.
- else if(!displayManager.isLineVisible(
- firstLine.physicalLine))
- {
- firstLine.physicalLine =
- displayManager.getNextVisibleLine(
- firstLine.physicalLine);
- }
} //}}}
//{{{ contentRemoved() method
@@ -279,8 +265,14 @@
if(buffer.isLoading())
return;
+ FirstLine firstLine = displayManager.firstLine;
+ ScrollLineCount scrollLineCount = displayManager.scrollLineCount;
+
if(textArea.getDisplayManager() == displayManager)
{
+ firstLine.contentRemoved(startLine,start,numLines);
+ scrollLineCount.contentRemoved(startLine,start,numLines);
+
//{{{ resize selections if necessary
int nSel = textArea.getSelectionCount();
Iterator<Selection> iter = textArea.getSelectionIterator();
@@ -369,19 +361,7 @@
//{{{ doDelayedUpdate() method
private void doDelayedUpdate()
{
- // must update screen line counts before we call
- // notifyScreenLineChanges() since that calls
- // updateScrollBar() which needs valid info
- int line = delayedUpdateStart;
- if(!displayManager.isLineVisible(line))
- line = displayManager.getNextVisibleLine(line);
- while(line != -1 && line <= delayedUpdateEnd)
- {
- displayManager.updateScreenLineCount(line);
- line = displayManager.getNextVisibleLine(line);
- }
-
- // must be before the below call
+ // must be done before the below call
// so that the chunk cache is not
// updated with an invisible first
// line (see above)
Modified: jEdit/branches/5.0.x/org/gjt/sp/jedit/textarea/ChunkCache.java
===================================================================
--- jEdit/branches/5.0.x/org/gjt/sp/jedit/textarea/ChunkCache.java 2012-10-13 21:55:51 UTC (rev 22365)
+++ jEdit/branches/5.0.x/org/gjt/sp/jedit/textarea/ChunkCache.java 2012-10-13 22:21:34 UTC (rev 22366)
@@ -677,10 +677,10 @@
{
if(i == 0)
{
- if(textArea.displayManager.firstLine.skew > 0)
+ if(textArea.displayManager.firstLine.getSkew() > 0)
{
- Log.log(Log.ERROR,this,"BUG: skew=" + textArea.displayManager.firstLine.skew + ",out.size()=" + out.size());
- textArea.displayManager.firstLine.skew = 0;
+ Log.log(Log.ERROR,this,"BUG: skew=" + textArea.displayManager.firstLine.getSkew() + ",out.size()=" + out.size());
+ textArea.displayManager.firstLine.setSkew(0);
needFullRepaint = true;
lastScreenLine = lineInfo.length - 1;
}
@@ -694,7 +694,7 @@
{
if(i == 0)
{
- int skew = textArea.displayManager.firstLine.skew;
+ int skew = textArea.displayManager.firstLine.getSkew();
if(skew >= out.size())
{
// The skew cannot be greater than the chunk count of the line
Modified: jEdit/branches/5.0.x/org/gjt/sp/jedit/textarea/DisplayManager.java
===================================================================
--- jEdit/branches/5.0.x/org/gjt/sp/jedit/textarea/DisplayManager.java 2012-10-13 21:55:51 UTC (rev 22365)
+++ jEdit/branches/5.0.x/org/gjt/sp/jedit/textarea/DisplayManager.java 2012-10-13 22:21:34 UTC (rev 22366)
@@ -120,7 +120,7 @@
//{{{ isLineVisible() method
/**
- * Returns if the specified line is visible.
+ * Returns if the specified physical line is visible.
* @param line A physical line index
* @since jEdit 4.2pre1
*/
@@ -241,7 +241,7 @@
*/
public final int getScrollLineCount()
{
- return scrollLineCount.scrollLine;
+ return scrollLineCount.getScrollLine();
} //}}}
//{{{ collapseFold() method
@@ -499,6 +499,10 @@
} //}}}
//{{{ notifyScreenLineChanges() method
+ /**
+ * FirstLine or ScrollLineCount changed
+ * Update ScrollBar, etc.
+ */
void notifyScreenLineChanges()
{
if(Debug.SCROLL_DEBUG)
@@ -511,21 +515,22 @@
try
{
- if(firstLine.callReset)
+ if(firstLine.isCallReset())
firstLine.reset();
- else if(firstLine.callChanged)
+ else if(firstLine.isCallChanged())
firstLine.changed();
- if(scrollLineCount.callReset)
+ if(scrollLineCount.isCallReset())
{
scrollLineCount.reset();
+ //FIXME: Why here?
firstLine.ensurePhysicalLineIsVisible();
- }
- else if(scrollLineCount.callChanged)
+ } else if(scrollLineCount.isCallChanged())
scrollLineCount.changed();
-
- if(firstLine.callChanged || scrollLineCount.callReset
- || scrollLineCount.callChanged)
+
+ if(firstLine.isCallChanged() ||
+ scrollLineCount.isCallReset() ||
+ scrollLineCount.isCallChanged())
{
textArea.updateScrollBar();
textArea.recalculateLastPhysicalLine();
@@ -533,36 +538,43 @@
}
finally
{
- firstLine.callReset = firstLine.callChanged = false;
- scrollLineCount.callReset = scrollLineCount.callChanged = false;
+ firstLine.resetCallState();
+ scrollLineCount.resetCallState();
}
} //}}}
//{{{ setFirstLine() method
- void setFirstLine(int oldFirstLine, int firstLine)
+ /**
+ * Sets the vertical scroll bar position
+ *
+ * @param currentFirstLine the current scroll bar position
+ * @param newFirstLine The to-be scroll bar position
+ */
+ void setFirstLine(int currentFirstLine, int newFirstLine)
{
int visibleLines = textArea.getVisibleLines();
- if(firstLine >= oldFirstLine + visibleLines)
+ if(newFirstLine >= currentFirstLine + visibleLines)
{
- this.firstLine.scrollDown(firstLine - oldFirstLine);
+ this.firstLine.scrollDown(newFirstLine - currentFirstLine);
textArea.chunkCache.invalidateAll();
}
- else if(firstLine <= oldFirstLine - visibleLines)
+ else if(newFirstLine <= currentFirstLine - visibleLines)
{
- this.firstLine.scrollUp(oldFirstLine - firstLine);
+ this.firstLine.scrollUp(currentFirstLine - newFirstLine);
textArea.chunkCache.invalidateAll();
}
- else if(firstLine > oldFirstLine)
+ else if(newFirstLine > currentFirstLine)
{
- this.firstLine.scrollDown(firstLine - oldFirstLine);
- textArea.chunkCache.scrollDown(firstLine - oldFirstLine);
+ this.firstLine.scrollDown(newFirstLine - currentFirstLine);
+ textArea.chunkCache.scrollDown(newFirstLine - currentFirstLine);
}
- else if(firstLine < oldFirstLine)
+ else if(newFirstLine < currentFirstLine)
{
- this.firstLine.scrollUp(oldFirstLine - firstLine);
- textArea.chunkCache.scrollUp(oldFirstLine - firstLine);
- }
+ this.firstLine.scrollUp(currentFirstLine - newFirstLine);
+ textArea.chunkCache.scrollUp(currentFirstLine - newFirstLine);
+ } else
+ assert true;
notifyScreenLineChanges();
} //}}}
@@ -576,11 +588,11 @@
*/
void setFirstPhysicalLine(int amount, int skew)
{
- int oldFirstLine = textArea.getFirstLine();
+ int currentFirstLine = textArea.getFirstLine();
if(amount == 0)
{
- skew -= this.firstLine.skew;
+ skew -= this.firstLine.getSkew();
// JEditTextArea.scrollTo() needs this to simplify
// its code
@@ -602,20 +614,20 @@
int firstLine = textArea.getFirstLine();
int visibleLines = textArea.getVisibleLines();
- if(firstLine == oldFirstLine)
+ if(firstLine == currentFirstLine)
/* do nothing */;
- else if(firstLine >= oldFirstLine + visibleLines
- || firstLine <= oldFirstLine - visibleLines)
+ else if(firstLine >= currentFirstLine + visibleLines
+ || firstLine <= currentFirstLine - visibleLines)
{
textArea.chunkCache.invalidateAll();
}
- else if(firstLine > oldFirstLine)
+ else if(firstLine > currentFirstLine)
{
- textArea.chunkCache.scrollDown(firstLine - oldFirstLine);
+ textArea.chunkCache.scrollDown(firstLine - currentFirstLine);
}
- else if(firstLine < oldFirstLine)
+ else if(firstLine < currentFirstLine)
{
- textArea.chunkCache.scrollUp(oldFirstLine - firstLine);
+ textArea.chunkCache.scrollUp(currentFirstLine - firstLine);
}
// we have to be careful
@@ -626,8 +638,8 @@
void invalidateScreenLineCounts()
{
screenLineMgr.invalidateScreenLineCounts();
- firstLine.callReset = true;
- scrollLineCount.callReset = true;
+ firstLine.setCallReset(true);
+ scrollLineCount.setCallReset(true);
} //}}}
//{{{ updateScreenLineCount() method
@@ -643,9 +655,9 @@
if(!screenLineMgr.isScreenLineCountValid(line))
{
- int newCount = textArea.chunkCache
- .getLineSubregionCount(line);
+ int newCount = textArea.chunkCache.getLineSubregionCount(line);
+ assert newCount > 0;
setScreenLineCount(line,newCount);
}
} //}}}
@@ -734,8 +746,8 @@
//{{{ resetAnchors() method
private void resetAnchors()
{
- firstLine.callReset = true;
- scrollLineCount.callReset = true;
+ firstLine.setCallReset(true);
+ scrollLineCount.setCallReset(true);
notifyScreenLineChanges();
} //}}}
@@ -747,6 +759,7 @@
} //}}}
//{{{ showLineRange() method
+ // for folding
private void showLineRange(int start, int end)
{
if(Debug.FOLD_VIS_DEBUG)
@@ -762,13 +775,11 @@
{
// important: not screenLineMgr.getScreenLineCount()
int screenLines = getScreenLineCount(i);
- if(firstLine.physicalLine >= i)
+ if(firstLine.getPhysicalLine() >= i)
{
- firstLine.scrollLine += screenLines;
- firstLine.callChanged = true;
+ firstLine.moveScrollLine(screenLines);
}
- scrollLineCount.scrollLine += screenLines;
- scrollLineCount.callChanged = true;
+ scrollLineCount.moveScrollLine(screenLines);
}
}
@@ -785,44 +796,41 @@
+ ',' + end + ')');
}
- int i = start;
- if(!isLineVisible(i))
- i = getNextVisibleLine(i);
- while(i != -1 && i <= end)
+ int physicalLine = start;
+ if(!isLineVisible(physicalLine))
+ physicalLine = getNextVisibleLine(physicalLine);
+
+ int scrollLines = 0;
+ while(physicalLine != -1 && physicalLine <= end)
{
- int screenLines = getScreenLineCount(i);
- if(i < firstLine.physicalLine)
+ int screenLines = getScreenLineCount(physicalLine);
+ if(physicalLine < firstLine.getPhysicalLine())
{
- firstLine.scrollLine -= screenLines;
- firstLine.skew = 0;
- firstLine.callChanged = true;
+ firstLine.setSkew(0);
+ firstLine.moveScrollLine(-screenLines);
}
- scrollLineCount.scrollLine -= screenLines;
- scrollLineCount.callChanged = true;
-
- i = getNextVisibleLine(i);
+ scrollLines -= screenLines;
+ physicalLine = getNextVisibleLine(physicalLine);
}
+ scrollLineCount.moveScrollLine(scrollLines);
/* update fold visibility map. */
folds.hide(start,end);
- if(!isLineVisible(firstLine.physicalLine))
+ if(!isLineVisible(firstLine.getPhysicalLine()))
{
int firstVisible = getFirstVisibleLine();
- if(firstLine.physicalLine < firstVisible)
+ if(firstLine.getPhysicalLine() < firstVisible)
{
- firstLine.physicalLine = firstVisible;
- firstLine.scrollLine = 0;
+ firstLine.setPhysicalLine(firstVisible);
+ firstLine.setScrollLine(0);
}
else
{
- firstLine.physicalLine = getPrevVisibleLine(
- firstLine.physicalLine);
- firstLine.scrollLine -= getScreenLineCount(
- firstLine.physicalLine);
+ firstLine.setPhysicalLine(getPrevVisibleLine(firstLine.getPhysicalLine()));
+ firstLine.moveScrollLine(-getScreenLineCount(firstLine.getPhysicalLine()));
}
- firstLine.callChanged = true;
}
} //}}}
@@ -830,38 +838,15 @@
/**
* Sets the number of screen lines that the specified physical line
* is split into.
- * @param line the line number
- * @param count the line count (1 if no wrap)
+ * @param line the physical line number
+ * @param count the line count (== 1 if no wrap, > 1 if soft wrap)
* @since jEdit 4.2pre1
*/
private void setScreenLineCount(int line, int count)
{
- int oldCount = screenLineMgr.getScreenLineCount(line);
-
- // old one so that the screen line manager sets the
- // validity flag!
-
+ assert count > 0;
screenLineMgr.setScreenLineCount(line,count);
- if(count == oldCount)
- return;
-
- if(!isLineVisible(line))
- return;
-
- if(firstLine.physicalLine >= line)
- {
- if(firstLine.physicalLine == line)
- firstLine.callChanged = true;
- else
- {
- firstLine.scrollLine += count - oldCount;
- firstLine.callChanged = true;
- }
- }
-
- scrollLineCount.scrollLine += count - oldCount;
- scrollLineCount.callChanged = true;
} //}}}
//{{{ _expandFold() method
Modified: jEdit/branches/5.0.x/org/gjt/sp/jedit/textarea/FirstLine.java
===================================================================
--- jEdit/branches/5.0.x/org/gjt/sp/jedit/textarea/FirstLine.java 2012-10-13 21:55:51 UTC (rev 22365)
+++ jEdit/branches/5.0.x/org/gjt/sp/jedit/textarea/FirstLine.java 2012-10-13 22:21:34 UTC (rev 22366)
@@ -33,9 +33,16 @@
*/
class FirstLine extends Anchor
{
- /** The skew is the scroll count from the beginning of the line. Used with soft wrap. */
- int skew;
+ // scrollLine + skew = vertical scroll bar position
+
+ /**
+ * The skew is the scroll count from the beginning of the line.
+ * Used with soft wrap.
+ */
+ private int skew;
+ private int preContentRemovedNumLines;
+
//{{{ FirstLine constructor
FirstLine(DisplayManager displayManager,
TextArea textArea)
@@ -43,59 +50,188 @@
super(displayManager,textArea);
} //}}}
- //{{{ changed() method
@Override
- public void changed()
+ void preContentInserted(int startLine, int numLines)
{
- //{{{ Debug code
+ int scrollLines = 0;
+ int physicalLine = startLine;
+ int currentPhysicalLine = getPhysicalLine();
+
+ int numLinesVisible = 0;
+ for(int i = 0;
+ physicalLine < currentPhysicalLine;
+ i++, physicalLine++)
+ {
+ if(getDisplayManager().isLineVisible(physicalLine))
+ {
+ scrollLines += getDisplayManager().getScreenLineCount(physicalLine);
+ }
+ if(i < numLines)
+ numLinesVisible++;
+ }
+ preContentInsertedScrollLines = scrollLines;
+ }
+
+ //{{{ contentInserted() method
+ /**
+ * Some content is inserted.
+ *
+ * @param startLine the start of the insert
+ * @param numLines the number of inserted lines
+ */
+ void contentInserted(int startLine, int numLines)
+ {
if(Debug.SCROLL_DEBUG)
+ Log.log(Log.DEBUG,this,"contentInserted() before:" + this);
+
+ int currentPhysicalLine = getPhysicalLine();
+ // The Anchor is changed only if the content was inserted before
+ if(startLine == currentPhysicalLine)
+ setCallChanged(true);
+ else if(startLine < currentPhysicalLine)
{
- Log.log(Log.DEBUG,this,"changed() before: "
- + physicalLine + ':' + scrollLine
- + ':' + skew);
- } //}}}
+ int scrollLines = 0;
+ int physicalLine = startLine;
+ int endLine = currentPhysicalLine + numLines;
+ int numLinesVisible = 0;
- ensurePhysicalLineIsVisible();
+ for(int i = 0;physicalLine < endLine; physicalLine++, i++)
+ {
+ if(getDisplayManager().isLineVisible(physicalLine))
+ {
+ scrollLines += getDisplayManager().getScreenLineCount(physicalLine);
+ }
+ if(i < numLines)
+ numLinesVisible++;
+ }
+ movePhysicalLine(numLinesVisible);
+ moveScrollLine(scrollLines - preContentInsertedScrollLines);
+ }
- int screenLines = displayManager
- .getScreenLineCount(physicalLine);
- if(skew >= screenLines)
- skew = screenLines - 1;
+ if(Debug.SCROLL_DEBUG)
+ Log.log(Log.DEBUG,this,"contentInserted() after:" + this);
- //{{{ Debug code
if(Debug.SCROLL_VERIFY)
+ scrollVerify();
+ } //}}}
+
+ @Override
+ void preContentRemoved(int startLine, int offset, int numLines)
+ {
+ int scrollLines = 0;
+ int physicalLine = startLine;
+ int currentPhysicalLine = getPhysicalLine();
+
+ int numLinesVisible = 0;
+ for(int i = 0;
+ physicalLine < currentPhysicalLine;
+ i++, physicalLine++)
{
- System.err.println("SCROLL_VERIFY");
- int verifyScrollLine = 0;
-
- for(int i = 0; i < displayManager.getBuffer()
- .getLineCount(); i++)
+ if(getDisplayManager().isLineVisible(physicalLine))
{
- if(!displayManager.isLineVisible(i))
- continue;
+ scrollLines += getDisplayManager().getScreenLineCount(physicalLine);
+ }
+ if(i < numLines)
+ numLinesVisible++;
+ }
- if(i >= physicalLine)
- break;
+ preContentRemovedScrollLines = scrollLines;
+ preContentRemovedNumLines = numLinesVisible;
+ }
- verifyScrollLine += displayManager
- .getScreenLineCount(i);
- }
+ //{{{ contentRemoved() method
+ /**
+ * Method called before a content is removed from a buffer.
+ *
+ * @param startLine the first line of the removed content
+ * @param offset the offset in the start line
+ * @param numLines the number of removed lines
+ */
+ void contentRemoved(int startLine, int startOffset, int numLines)
+ {
+ if(Debug.SCROLL_DEBUG)
+ Log.log(Log.DEBUG,this,"contentRemoved() before:" + this);
- if(verifyScrollLine != scrollLine)
+ // The removed content starts before the Anchor, we need to pull the anchor up
+ int currentPhysicalLine = getPhysicalLine();
+ if(startLine == currentPhysicalLine)
+ setCallChanged(true);
+ else if(startLine < currentPhysicalLine)
+ {
+ int scrollLines = 0;
+ int physicalLine = startLine;
+ int endLine = currentPhysicalLine - numLines;
+
+ for(;physicalLine < endLine; physicalLine++)
{
- Exception ex = new Exception(scrollLine + ":" + verifyScrollLine);
- Log.log(Log.ERROR,this,ex);
+ if(getDisplayManager().isLineVisible(physicalLine))
+ {
+ scrollLines += getDisplayManager().getScreenLineCount(physicalLine);
+ }
}
+ movePhysicalLine(-preContentRemovedNumLines);
+ moveScrollLine(scrollLines - preContentRemovedScrollLines);
}
+ if(Debug.SCROLL_DEBUG)
+ Log.log(Log.DEBUG,this,"contentRemoved() after:" + this);
+ if(Debug.SCROLL_VERIFY)
+ scrollVerify();
+ } //}}}
+ //{{{ changed() method
+ @Override
+ public void changed()
+ {
+ //{{{ Debug code
if(Debug.SCROLL_DEBUG)
{
+ Log.log(Log.DEBUG,this,"changed() before: "
+ + getPhysicalLine() + ':' + getScrollLine()
+ + ':' + getSkew());
+ } //}}}
+
+ if(Debug.SCROLL_VERIFY)
+ scrollVerify();
+
+ ensurePhysicalLineIsVisible();
+ int currentPhysicalLine = getPhysicalLine();
+ int screenLines = getDisplayManager().getScreenLineCount(currentPhysicalLine);
+
+ if(getSkew() >= screenLines)
+ setSkew(screenLines - 1);
+
+ //{{{ Debug code
+ if(Debug.SCROLL_VERIFY)
+ scrollVerify();
+
+ if(Debug.SCROLL_DEBUG)
+ {
Log.log(Log.DEBUG,this,"changed() after: "
- + physicalLine + ':' + scrollLine
- + ':' + skew);
+ + getPhysicalLine() + ':' + getScrollLine()
+ + ':' + getSkew());
} //}}}
} //}}}
+ private void scrollVerify()
+ {
+ System.err.println("SCROLL_VERIFY");
+ int verifyScrollLine = 0;
+ int currentPhysicalLine = getPhysicalLine();
+
+ for(int i = 0, n = getDisplayManager().getBuffer().getLineCount(); i < n && i < currentPhysicalLine; i++)
+ {
+ if(getDisplayManager().isLineVisible(i))
+ verifyScrollLine += getDisplayManager().getScreenLineCount(i);
+ }
+
+ int scrollLine = getScrollLine();
+ if(verifyScrollLine != scrollLine)
+ {
+ RuntimeException ex = new RuntimeException("ScrollLine is " + scrollLine + " but should be " + verifyScrollLine + " diff = " + (verifyScrollLine - scrollLine));
+ Log.log(Log.ERROR,this,ex);
+ }
+ }
+
//{{{ reset() method
@Override
public void reset()
@@ -103,85 +239,91 @@
if(Debug.SCROLL_DEBUG)
Log.log(Log.DEBUG,this,"reset()");
- int oldPhysicalLine = physicalLine;
- physicalLine = 0;
- scrollLine = 0;
+ int currentPhysicalLine = getPhysicalLine();
- int i = displayManager.getFirstVisibleLine();
+ int physicalLine = getDisplayManager().getFirstVisibleLine();
+ int scrollLine = 0;
- for(;;)
+ while(physicalLine != -1)
{
- if(i >= oldPhysicalLine)
+ if(physicalLine >= currentPhysicalLine)
break;
- scrollLine += displayManager.getScreenLineCount(i);
+ scrollLine += getDisplayManager().getScreenLineCount(physicalLine);
- int nextLine = displayManager.getNextVisibleLine(i);
+ int nextLine = getDisplayManager().getNextVisibleLine(physicalLine);
if(nextLine == -1)
break;
else
- i = nextLine;
+ physicalLine = nextLine;
}
- physicalLine = i;
+ setPhysicalLine(physicalLine);
+ setScrollLine(scrollLine);
- int screenLines = displayManager.getScreenLineCount(physicalLine);
- if(skew >= screenLines)
- skew = screenLines - 1;
+ int screenLines = getDisplayManager().getScreenLineCount(physicalLine);
+ if(getSkew() >= screenLines)
+ setSkew(screenLines - 1);
- textArea.updateScrollBar();
+ getTextArea().updateScrollBar();
} //}}}
//{{{ physDown() method
// scroll down by physical line amount
void physDown(int amount, int screenAmount)
{
+ int currentPhysicalLine = getPhysicalLine();
+ int currentScrollLine = getScrollLine();
+
if(Debug.SCROLL_DEBUG)
{
Log.log(Log.DEBUG,this,"physDown() start: "
- + physicalLine + ':' + scrollLine);
+ + currentPhysicalLine + ':' + currentScrollLine);
}
- skew = 0;
+ setSkew(0);
- if(!displayManager.isLineVisible(physicalLine))
+ if(!getDisplayManager().isLineVisible(currentPhysicalLine))
{
- int lastVisibleLine = displayManager.getLastVisibleLine();
- if(physicalLine > lastVisibleLine)
- physicalLine = lastVisibleLine;
+ int lastVisibleLine = getDisplayManager().getLastVisibleLine();
+ if(currentPhysicalLine > lastVisibleLine)
+ setPhysicalLine(lastVisibleLine);
else
{
- int nextPhysicalLine = displayManager.getNextVisibleLine(physicalLine);
- amount -= nextPhysicalLine - physicalLine;
- scrollLine += displayManager.getScreenLineCount(physicalLine);
- physicalLine = nextPhysicalLine;
+ int nextPhysicalLine = getDisplayManager().getNextVisibleLine(currentPhysicalLine);
+ assert nextPhysicalLine > 0;
+ amount -= nextPhysicalLine - currentPhysicalLine;
+ moveScrollLine(getDisplayManager().getScreenLineCount(currentPhysicalLine));
+ setPhysicalLine(nextPhysicalLine);
}
}
+ currentPhysicalLine = getPhysicalLine();
+ int scrollLines = 0;
for(;;)
{
- int nextPhysicalLine = displayManager.getNextVisibleLine(
- physicalLine);
+ int nextPhysicalLine = getDisplayManager().getNextVisibleLine(currentPhysicalLine);
+
if(nextPhysicalLine == -1)
break;
- else if(nextPhysicalLine > physicalLine + amount)
+ else if(nextPhysicalLine > currentPhysicalLine + amount)
break;
else
{
- scrollLine += displayManager.getScreenLineCount(physicalLine);
- amount -= nextPhysicalLine - physicalLine;
- physicalLine = nextPhysicalLine;
+ scrollLines += getDisplayManager().getScreenLineCount(currentPhysicalLine);
+ amount -= nextPhysicalLine - currentPhysicalLine;
+ currentPhysicalLine = nextPhysicalLine;
}
}
+ setPhysicalLine(currentPhysicalLine);
+ moveScrollLine(scrollLines);
if(Debug.SCROLL_DEBUG)
{
Log.log(Log.DEBUG,this,"physDown() end: "
- + physicalLine + ':' + scrollLine);
+ + getPhysicalLine() + ':' + getScrollLine());
}
- callChanged = true;
-
// JEditTextArea.scrollTo() needs this to simplify
// its code
if(screenAmount < 0)
@@ -197,48 +339,49 @@
if(Debug.SCROLL_DEBUG)
{
Log.log(Log.DEBUG,this,"physUp() start: "
- + physicalLine + ':' + scrollLine);
+ +getPhysicalLine()+ ':' + getScrollLine());
}
- skew = 0;
+ setSkew(0);
- if(!displayManager.isLineVisible(physicalLine))
+ int currentPhysicalLine = getPhysicalLine();
+ if(!getDisplayManager().isLineVisible(currentPhysicalLine))
{
- int firstVisibleLine = displayManager.getFirstVisibleLine();
- if(physicalLine < firstVisibleLine)
- physicalLine = firstVisibleLine;
+ int firstVisibleLine = getDisplayManager().getFirstVisibleLine();
+ if(currentPhysicalLine < firstVisibleLine)
+ setPhysicalLine(firstVisibleLine);
else
{
- int prevPhysicalLine = displayManager.getPrevVisibleLine(physicalLine);
- amount -= physicalLine - prevPhysicalLine;
+ int prevPhysicalLine = getDisplayManager().getPrevVisibleLine(currentPhysicalLine);
+ amount -= currentPhysicalLine - prevPhysicalLine;
}
}
+ currentPhysicalLine = getPhysicalLine();
+ int scrollLines = 0;
for(;;)
{
- int prevPhysicalLine = displayManager.getPrevVisibleLine(
- physicalLine);
+ int prevPhysicalLine = getDisplayManager().getPrevVisibleLine(currentPhysicalLine);
if(prevPhysicalLine == -1)
break;
- else if(prevPhysicalLine < physicalLine - amount)
+ else if(prevPhysicalLine < currentPhysicalLine - amount)
break;
else
{
- amount -= physicalLine - prevPhysicalLine;
- physicalLine = prevPhysicalLine;
- scrollLine -= displayManager.getScreenLineCount(
- prevPhysicalLine);
+ scrollLines -= getDisplayManager().getScreenLineCount(prevPhysicalLine);
+ amount -= currentPhysicalLine - prevPhysicalLine;
+ currentPhysicalLine = prevPhysicalLine;
}
}
+ setPhysicalLine(currentPhysicalLine);
+ moveScrollLine(scrollLines);
if(Debug.SCROLL_DEBUG)
{
Log.log(Log.DEBUG,this,"physUp() end: "
- + physicalLine + ':' + scrollLine);
+ +getPhysicalLine()+ ':' + getScrollLine());
}
- callChanged = true;
-
// JEditTextArea.scrollTo() needs this to simplify
// its code
if(screenAmount < 0)
@@ -256,34 +399,36 @@
ensurePhysicalLineIsVisible();
- amount += skew;
+ amount += getSkew();
- skew = 0;
+ setSkew(0);
+ int physicalLine = getPhysicalLine();
+ int screenLinesSum = 0;
while(amount > 0)
{
- int screenLines = displayManager.getScreenLineCount(physicalLine);
+ int screenLines = getDisplayManager().getScreenLineCount(physicalLine);
if(amount < screenLines)
{
- skew = amount;
+ setSkew(amount);
break;
}
else
{
- int nextLine = displayManager.getNextVisibleLine(physicalLine);
+ int nextLine = getDisplayManager().getNextVisibleLine(physicalLine);
if(nextLine == -1)
break;
- boolean visible = displayManager.isLineVisible(physicalLine);
+ boolean visible = getDisplayManager().isLineVisible(physicalLine);
physicalLine = nextLine;
if(visible)
{
amount -= screenLines;
- scrollLine += screenLines;
+ screenLinesSum += screenLines;
}
}
}
-
- callChanged = true;
+ setPhysicalLine(physicalLine);
+ moveScrollLine(screenLinesSum);
} //}}}
//{{{ scrollUp() method
@@ -295,62 +440,73 @@
ensurePhysicalLineIsVisible();
- if(amount <= skew)
+ if(amount <= getSkew())
{
// the amount is less than the skew, so we stay in the same like, just going
// upper
- skew -= amount;
+ setSkew(getSkew() - amount);
}
else
{
// moving to the first screen line of the current physical line
- amount -= skew;
- skew = 0;
+ amount -= getSkew();
+ setSkew(0);
+ int physicalLine = getPhysicalLine();
+ int screenLinesSum = 0;
while(amount > 0)
{
- int prevLine = displayManager.getPrevVisibleLine(physicalLine);
+ int prevLine = getDisplayManager().getPrevVisibleLine(physicalLine);
if(prevLine == -1)
break;
// moving to the previous visible physical line
physicalLine = prevLine;
- int screenLines = displayManager.getScreenLineCount(physicalLine);
- scrollLine -= screenLines;
+ int screenLines = getDisplayManager().getScreenLineCount(physicalLine);
+ screenLinesSum -= screenLines;
+
if(amount < screenLines)
{
- skew = screenLines - amount;
+ setSkew(screenLines - amount);
break;
}
else
+ {
amount -= screenLines;
+ }
}
+ setPhysicalLine(physicalLine);
+ moveScrollLine(screenLinesSum);
}
if(Debug.SCROLL_DEBUG)
Log.log(Log.DEBUG,this,"scrollUp() after:" + this);
- callChanged = true;
} //}}}
//{{{ ensurePhysicalLineIsVisible() method
void ensurePhysicalLineIsVisible()
{
- if(!displayManager.isLineVisible(physicalLine))
+ int physicalLine = getPhysicalLine();
+ if(!getDisplayManager().isLineVisible(physicalLine))
{
- if(physicalLine > displayManager.getLastVisibleLine())
+ if(physicalLine > getDisplayManager().getLastVisibleLine())
{
- physicalLine = displayManager.getLastVisibleLine();
- scrollLine = displayManager.getScrollLineCount() - 1;
+ setPhysicalLine(getDisplayManager().getLastVisibleLine());
+ setScrollLine(getDisplayManager().getScrollLineCount() - 1);
}
- else if(physicalLine < displayManager.getFirstVisibleLine())
+ else if(physicalLine < getDisplayManager().getFirstVisibleLine())
{
- physicalLine = displayManager.getFirstVisibleLine();
- scrollLine = 0;
+ setPhysicalLine(getDisplayManager().getFirstVisibleLine());
+ setScrollLine(0);
}
else
{
- physicalLine = displayManager.getNextVisibleLine(physicalLine);
- scrollLine += displayManager.getScreenLineCount(physicalLine);
+ int nextLine = getDisplayManager().getNextVisibleLine(physicalLine);
+ assert nextLine > 0;
+ int screenLineCount = 0;
+ screenLineCount = getDisplayManager().getScreenLineCount(nextLine);
+ setPhysicalLine(nextLine);
+ moveScrollLine(screenLineCount);
}
}
} //}}}
@@ -359,6 +515,21 @@
@Override
public String toString()
{
- return "FirstLine["+physicalLine+','+scrollLine+','+skew+']';
+ return "FirstLine["+ getPhysicalLine() + ',' + getScrollLine() + ',' + getSkew() + ']';
} //}}}
+
+ int getSkew()
+ {
+ return skew;
+ }
+
+ void setSkew(int skew)
+ {
+ if(this.skew != skew)
+ {
+ this.skew = skew;
+ //FIXME: Necessary?
+ setCallChanged(true);
+ }
+ }
}
Modified: jEdit/branches/5.0.x/org/gjt/sp/jedit/textarea/ScreenLineManager.java
===================================================================
--- jEdit/branches/5.0.x/org/gjt/sp/jedit/textarea/ScreenLineManager.java 2012-10-13 21:55:51 UTC (rev 22365)
+++ jEdit/branches/5.0.x/org/gjt/sp/jedit/textarea/ScreenLineManager.java 2012-10-13 22:21:34 UTC (rev 22366)
@@ -61,6 +61,7 @@
*/
int getScreenLineCount(int line)
{
+ assert isScreenLineCountValid(line);
return screenLines[line] >> SCREEN_LINES_SHIFT;
} //}}}
@@ -73,6 +74,8 @@
*/
void setScreenLineCount(int line, int count)
{
+ assert count > 0 : "New line count is bogus!";
+
if(count > Short.MAX_VALUE)
{
// limitations...
@@ -81,15 +84,13 @@
if(Debug.SCREEN_LINES_DEBUG)
Log.log(Log.DEBUG,this,new Exception("setScreenLineCount(" + line + ',' + count + ')'));
- screenLines[line] = (short)(count << SCREEN_LINES_SHIFT
- | SCREEN_LINES_VALID_MASK);
+ screenLines[line] = (short)(count << SCREEN_LINES_SHIFT | SCREEN_LINES_VALID_MASK);
} //}}}
//{{{ invalidateScreenLineCounts() method
void invalidateScreenLineCounts()
{
- int lineCount = buffer.getLineCount();
- for(int i = 0; i < lineCount; i++)
+ for(int i = 0, lineCount = buffer.getLineCount(); i < lineCount; i++)
screenLines[i] &= ~SCREEN_LINES_VALID_MASK;
} //}}}
@@ -143,7 +144,8 @@
private static final int SCREEN_LINES_VALID_MASK = 1;
private final JEditBuffer buffer;
- /** This array contains the line count for each physical line. */
+
+ /** This array contains the screen line count for each physical line. */
private short[] screenLines;
//}}}
}
Modified: jEdit/branches/5.0.x/org/gjt/sp/jedit/textarea/ScrollLineCount.java
===================================================================
--- jEdit/branches/5.0.x/org/gjt/sp/jedit/textarea/ScrollLineCount.java 2012-10-13 21:55:51 UTC (rev 22365)
+++ jEdit/branches/5.0.x/org/gjt/sp/jedit/textarea/ScrollLineCount.java 2012-10-13 22:21:34 UTC (rev 22366)
@@ -30,6 +30,7 @@
*/
class ScrollLineCount extends Anchor
{
+
//{{{ ScrollLineCount constructor
ScrollLineCount(DisplayManager displayManager,
TextArea textArea)
@@ -47,17 +48,92 @@
if(Debug.SCROLL_DEBUG)
Log.log(Log.DEBUG,this,"reset()");
- physicalLine = displayManager.getFirstVisibleLine();
int scrollLine = 0;
+ int physicalLine = getDisplayManager().getFirstVisibleLine();
+
while(physicalLine != -1)
{
- scrollLine += displayManager
- .getScreenLineCount(physicalLine);
- physicalLine = displayManager
- .getNextVisibleLine(physicalLine);
+ scrollLine += getDisplayManager().getScreenLineCount(physicalLine);
+ physicalLine = getDisplayManager().getNextVisibleLine(physicalLine);
}
- this.scrollLine = scrollLine;
- physicalLine = displayManager.getBuffer().getLineCount();
+ setPhysicalLine(getDisplayManager().getBuffer().getLineCount());
+ setScrollLine(scrollLine);
} //}}}
+
+ @Override
+ void preContentInserted(int startLine, int numLines)
+ {
+ preContentInsertedScrollLines = 0;
+ int physicalLine = startLine;
+
+ if(!getDisplayManager().isLineVisible(physicalLine))
+ physicalLine = getDisplayManager().getNextVisibleLine(physicalLine);
+
+ preContentInsertedScrollLines = getDisplayManager().getScreenLineCount(physicalLine);
+ }
+
+ @Override
+ void contentInserted(int startLine, int numLines)
+ {
+ int scrollLines = 0;
+ int physicalLine = startLine;
+
+ for(int i = 0, n = numLines; i < n; i++, physicalLine++)
+ {
+ if(getDisplayManager().isLineVisible(physicalLine))
+ scrollLines += getDisplayManager().getScreenLineCount(physicalLine);
+ }
+ // process next visible line
+ if(!getDisplayManager().isLineVisible(physicalLine))
+ physicalLine = getDisplayManager().getNextVisibleLine(physicalLine);
+ if(physicalLine >= 0)
+ scrollLines += getDisplayManager().getScreenLineCount(physicalLine);
+
+ scrollLines -= preContentInsertedScrollLines;
+
+ movePhysicalLine(numLines);
+ moveScrollLine(scrollLines);
+ }
+
+ @Override
+ void preContentRemoved(int startLine, int offset, int numLines)
+ {
+ int scrollLines = 0;
+ int physicalLine = startLine;
+ int numLinesVisible = 0;
+
+ for(int i = 0, n = numLines; i < n; i++, physicalLine++)
+ {
+ if(getDisplayManager().isLineVisible(physicalLine))
+ {
+ scrollLines += getDisplayManager().getScreenLineCount(physicalLine);
+ numLinesVisible++;
+ }
+ }
+ // process next visible line
+ if(!getDisplayManager().isLineVisible(physicalLine))
+ physicalLine = getDisplayManager().getNextVisibleLine(physicalLine);
+ if(physicalLine >= 0)
+ {
+ scrollLines += getDisplayManager().getScreenLineCount(physicalLine);
+ numLinesVisible++;
+ }
+
+ preContentRemovedScrollLines = scrollLines;
+ }
+
+ @Override
+ void contentRemoved(int startLine, int startOffset, int numLines)
+ {
+ int scrollLines = 0;
+ int physicalLine = startLine;
+ if(!getDisplayManager().isLineVisible(physicalLine))
+ physicalLine = getDisplayManager().getNextVisibleLine(physicalLine);
+ scrollLines = getDisplayManager().getScreenLineCount(physicalLine);
+
+ scrollLines -= preContentRemovedScrollLines;
+ movePhysicalLine(-numLines);
+ moveScrollLine(scrollLines);
+ }
}
Modified: jEdit/branches/5.0.x/org/gjt/sp/jedit/textarea/TextArea.java
===================================================================
--- jEdit/branches/5.0.x/org/gjt/sp/jedit/textarea/TextArea.java 2012-10-13 21:55:51 UTC (rev 22365)
+++ jEdit/branches/5.0.x/org/gjt/sp/jedit/textarea/TextArea.java 2012-10-13 22:21:34 UTC (rev 22366)
@@ -387,6 +387,7 @@
{
bufferChanging = true;
+ boolean inCompoundEdit = false;
if(this.buffer != null)
{
// dubious?
@@ -396,13 +397,17 @@
selectNone();
caretLine = caret = caretScreenLine = 0;
match = null;
+
+ // is the current buffer performing a compoundEdit?
+ inCompoundEdit = this.buffer.insideCompoundEdit();
+ if (inCompoundEdit)
+ this.buffer.endCompoundEdit();
}
- boolean inCompoundEdit = false;
- if (this.buffer != null)
- inCompoundEdit = this.buffer.insideCompoundEdit();
- if (inCompoundEdit)
- this.buffer.endCompoundEdit();
+
+ // set new buffer
this.buffer = buffer;
+ // old buffer did perform a compoundEdit,
+ // so open a compoundEdit for new buffer
if (inCompoundEdit)
this.buffer.beginCompoundEdit();
@@ -511,8 +516,7 @@
*/
public final int getFirstLine()
{
- return displayManager.firstLine.scrollLine
- + displayManager.firstLine.skew;
+ return displayManager.firstLine.getScrollLine() + displayManager.firstLine.getSkew();
} //}}}
//{{{ setFirstLine() method
@@ -532,13 +536,13 @@
firstLine = 0;
//}}}
+ int oldFirstLine = getFirstLine();
if(Debug.SCROLL_DEBUG)
{
Log.log(Log.DEBUG,this,"setFirstLine() from "
- + getFirstLine() + " to " + firstLine);
+ + oldFirstLine + " to " + firstLine);
}
- int oldFirstLine = getFirstLine();
if(firstLine == oldFirstLine)
return;
@@ -556,7 +560,7 @@
*/
public final int getFirstPhysicalLine()
{
- return displayManager.firstLine.physicalLine;
+ return displayManager.firstLine.getPhysicalLine();
} //}}}
//{{{ setFirstPhysicalLine() methods
@@ -584,7 +588,7 @@
+ physFirstLine + ',' + skew + ')');
}
- int amount = physFirstLine - displayManager.firstLine.physicalLine;
+ int amount = physFirstLine - displayManager.firstLine.getPhysicalLine();
displayManager.setFirstPhysicalLine(amount,skew);
@@ -822,8 +826,7 @@
Log.log(Log.DEBUG,this,"neither");
Log.log(Log.DEBUG,this,"Last physical line is " + getLastPhysicalLine());
}
- setFirstPhysicalLine(line,subregion
- - (visibleLines >> 1));
+ setFirstPhysicalLine(line,subregion - (visibleLines >> 1));
if(Debug.SCROLL_TO_DEBUG)
{
Log.log(Log.DEBUG,this,"Last physical line is " + getLastPhysicalLine());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|