Browse Source

TextAreaMouseHandler: This patch by Troy Simpson fixes an issue with selecting text via double-click, then following-up with a gutter selection.

GapTextBufferStrategy: rewrote PlaceGap, fixing a performance issue when deleting text in large documents
DefaultHighlightingStrategy: cache currentLine.Offset because it's not cheap to retrieve (it's an O(lg n) operation)
DefaultDocument.RequestUpdate: when doing a WholeTextArea update, skip all other updates because they would only duplicate the work done by the WholeTextArea update
Except for the load time, the performance editing large .txt files is now good; though the text editor takes a huge amount of memory (tested with a 1,000,000 lines file).

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2600 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 18 years ago
parent
commit
e8a0736262
  1. 2
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/BookmarkManager/BookmarkManager.cs
  2. 8
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/DefaultDocument.cs
  3. 55
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/DefaultHighlightingStrategy.cs
  4. 40
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/LineManager/DefaultLineManager.cs
  5. 105
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/TextBufferStrategy/GapTextBufferStrategy.cs
  6. 9
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextArea.cs
  7. 31
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaMouseHandler.cs
  8. 8
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextEditorControl.cs
  9. 2
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextView.cs

2
src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/BookmarkManager/BookmarkManager.cs

@ -24,7 +24,7 @@ namespace ICSharpCode.TextEditor.Document @@ -24,7 +24,7 @@ namespace ICSharpCode.TextEditor.Document
List<Bookmark> bookmark = new List<Bookmark>();
/// <value>
/// Contains all bookmarks as int values
/// Contains all bookmarks
/// </value>
public List<Bookmark> Marks {
get {

8
src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/DefaultDocument.cs

@ -423,6 +423,14 @@ namespace ICSharpCode.TextEditor.Document @@ -423,6 +423,14 @@ namespace ICSharpCode.TextEditor.Document
public void RequestUpdate(TextAreaUpdate update)
{
if (updateQueue.Count == 1 && updateQueue[0].TextAreaUpdateType == TextAreaUpdateType.WholeTextArea) {
// if we're going to update the whole text area, we don't need to store detail updates
return;
}
if (update.TextAreaUpdateType == TextAreaUpdateType.WholeTextArea) {
// if we're going to update the whole text area, we don't need to store detail updates
updateQueue.Clear();
}
updateQueue.Add(update);
}

55
src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/DefaultHighlightingStrategy.cs

@ -414,18 +414,15 @@ namespace ICSharpCode.TextEditor.Document @@ -414,18 +414,15 @@ namespace ICSharpCode.TextEditor.Document
Dictionary<LineSegment, bool> processedLines = new Dictionary<LineSegment, bool>();
bool spanChanged = false;
int documentLineSegmentCount = document.LineSegmentCollection.Count;
foreach (LineSegment lineToProcess in inputLines) {
if (!processedLines.ContainsKey(lineToProcess)) {
int lineNumber = document.GetLineNumberForOffset(lineToProcess.Offset);
int lineNumber = lineToProcess.LineNumber;
bool processNextLine = true;
if (lineNumber != -1) {
while (processNextLine && lineNumber < document.TotalNumberOfLines) {
if (lineNumber >= document.LineSegmentCollection.Count) { // may be, if the last line ends with a delimiter
break; // then the last line is not in the collection :)
}
while (processNextLine && lineNumber < documentLineSegmentCount) {
processNextLine = MarkTokensInLine(document, lineNumber, ref spanChanged);
processedLines[currentLine] = true;
++lineNumber;
@ -434,14 +431,17 @@ namespace ICSharpCode.TextEditor.Document @@ -434,14 +431,17 @@ namespace ICSharpCode.TextEditor.Document
}
}
if (spanChanged) {
if (spanChanged || inputLines.Count > 20) {
// if the span was changed (more than inputLines lines had to be reevaluated)
// or if there are many lines in inputLines, it's faster to update the whole
// text area instead of many small segments
document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea));
} else {
// document.Caret.ValidateCaretPos();
// document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, document.GetLineNumberForOffset(document.Caret.Offset)));
//
foreach (LineSegment lineToProcess in inputLines) {
document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, document.GetLineNumberForOffset(lineToProcess.Offset)));
document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, lineToProcess.LineNumber));
}
}
@ -474,8 +474,11 @@ namespace ICSharpCode.TextEditor.Document @@ -474,8 +474,11 @@ namespace ICSharpCode.TextEditor.Document
currentLength = 0;
UpdateSpanStateVariables();
for (int i = 0; i < currentLine.Length; ++i) {
char ch = document.GetCharAt(currentLine.Offset + i);
int currentLineLength = currentLine.Length;
int currentLineOffset = currentLine.Offset;
for (int i = 0; i < currentLineLength; ++i) {
char ch = document.GetCharAt(currentLineOffset + i);
switch (ch) {
case '\n':
case '\r':
@ -516,8 +519,8 @@ namespace ICSharpCode.TextEditor.Document @@ -516,8 +519,8 @@ namespace ICSharpCode.TextEditor.Document
{
// the escape character is a end-doubling escape character
// it may count as escape only when the next character is the escape, too
if (i + 1 < currentLine.Length) {
if (document.GetCharAt(currentLine.Offset + i + 1) == escapeCharacter) {
if (i + 1 < currentLineLength) {
if (document.GetCharAt(currentLineOffset + i + 1) == escapeCharacter) {
currentLength += 2;
PushCurWord(document, ref markNext, words);
++i;
@ -527,7 +530,7 @@ namespace ICSharpCode.TextEditor.Document @@ -527,7 +530,7 @@ namespace ICSharpCode.TextEditor.Document
} else {
// this is a normal \-style escape
++currentLength;
if (i + 1 < currentLine.Length) {
if (i + 1 < currentLineLength) {
++currentLength;
}
PushCurWord(document, ref markNext, words);
@ -537,53 +540,53 @@ namespace ICSharpCode.TextEditor.Document @@ -537,53 +540,53 @@ namespace ICSharpCode.TextEditor.Document
}
// highlight digits
if (!inSpan && (Char.IsDigit(ch) || (ch == '.' && i + 1 < currentLine.Length && Char.IsDigit(document.GetCharAt(currentLine.Offset + i + 1)))) && currentLength == 0) {
if (!inSpan && (Char.IsDigit(ch) || (ch == '.' && i + 1 < currentLineLength && Char.IsDigit(document.GetCharAt(currentLineOffset + i + 1)))) && currentLength == 0) {
bool ishex = false;
bool isfloatingpoint = false;
if (ch == '0' && i + 1 < currentLine.Length && Char.ToUpper(document.GetCharAt(currentLine.Offset + i + 1)) == 'X') { // hex digits
if (ch == '0' && i + 1 < currentLineLength && Char.ToUpper(document.GetCharAt(currentLineOffset + i + 1)) == 'X') { // hex digits
const string hex = "0123456789ABCDEF";
++currentLength;
++i; // skip 'x'
++currentLength;
ishex = true;
while (i + 1 < currentLine.Length && hex.IndexOf(Char.ToUpper(document.GetCharAt(currentLine.Offset + i + 1))) != -1) {
while (i + 1 < currentLineLength && hex.IndexOf(Char.ToUpper(document.GetCharAt(currentLineOffset + i + 1))) != -1) {
++i;
++currentLength;
}
} else {
++currentLength;
while (i + 1 < currentLine.Length && Char.IsDigit(document.GetCharAt(currentLine.Offset + i + 1))) {
while (i + 1 < currentLineLength && Char.IsDigit(document.GetCharAt(currentLineOffset + i + 1))) {
++i;
++currentLength;
}
}
if (!ishex && i + 1 < currentLine.Length && document.GetCharAt(currentLine.Offset + i + 1) == '.') {
if (!ishex && i + 1 < currentLineLength && document.GetCharAt(currentLineOffset + i + 1) == '.') {
isfloatingpoint = true;
++i;
++currentLength;
while (i + 1 < currentLine.Length && Char.IsDigit(document.GetCharAt(currentLine.Offset + i + 1))) {
while (i + 1 < currentLineLength && Char.IsDigit(document.GetCharAt(currentLineOffset + i + 1))) {
++i;
++currentLength;
}
}
if (i + 1 < currentLine.Length && Char.ToUpper(document.GetCharAt(currentLine.Offset + i + 1)) == 'E') {
if (i + 1 < currentLineLength && Char.ToUpper(document.GetCharAt(currentLineOffset + i + 1)) == 'E') {
isfloatingpoint = true;
++i;
++currentLength;
if (i + 1 < currentLine.Length && (document.GetCharAt(currentLine.Offset + i + 1) == '+' || document.GetCharAt(currentLine.Offset + i + 1) == '-')) {
if (i + 1 < currentLineLength && (document.GetCharAt(currentLineOffset + i + 1) == '+' || document.GetCharAt(currentLine.Offset + i + 1) == '-')) {
++i;
++currentLength;
}
while (i + 1 < currentLine.Length && Char.IsDigit(document.GetCharAt(currentLine.Offset + i + 1))) {
while (i + 1 < currentLine.Length && Char.IsDigit(document.GetCharAt(currentLineOffset + i + 1))) {
++i;
++currentLength;
}
}
if (i + 1 < currentLine.Length) {
char nextch = Char.ToUpper(document.GetCharAt(currentLine.Offset + i + 1));
char nextch = Char.ToUpper(document.GetCharAt(currentLineOffset + i + 1));
if (nextch == 'F' || nextch == 'M' || nextch == 'D') {
isfloatingpoint = true;
++i;
@ -593,15 +596,15 @@ namespace ICSharpCode.TextEditor.Document @@ -593,15 +596,15 @@ namespace ICSharpCode.TextEditor.Document
if (!isfloatingpoint) {
bool isunsigned = false;
if (i + 1 < currentLine.Length && Char.ToUpper(document.GetCharAt(currentLine.Offset + i + 1)) == 'U') {
if (i + 1 < currentLineLength && Char.ToUpper(document.GetCharAt(currentLineOffset + i + 1)) == 'U') {
++i;
++currentLength;
isunsigned = true;
}
if (i + 1 < currentLine.Length && Char.ToUpper(document.GetCharAt(currentLine.Offset + i + 1)) == 'L') {
if (i + 1 < currentLineLength && Char.ToUpper(document.GetCharAt(currentLineOffset + i + 1)) == 'L') {
++i;
++currentLength;
if (!isunsigned && i + 1 < currentLine.Length && Char.ToUpper(document.GetCharAt(currentLine.Offset + i + 1)) == 'U') {
if (!isunsigned && i + 1 < currentLineLength && Char.ToUpper(document.GetCharAt(currentLineOffset + i + 1)) == 'U') {
++i;
++currentLength;
}

40
src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/LineManager/DefaultLineManager.cs

@ -144,8 +144,9 @@ namespace ICSharpCode.TextEditor.Document @@ -144,8 +144,9 @@ namespace ICSharpCode.TextEditor.Document
while ((ds = NextDelimiter(text, lastDelimiterEnd)) != null) {
// split line segment at line delimiter
int lineBreakOffset = offset + ds.Offset + ds.Length;
int lengthAfterInsertionPos = segment.Offset + segment.TotalLength - (offset + lastDelimiterEnd);
lineCollection.SetSegmentLength(segment, lineBreakOffset - segment.Offset);
int segmentOffset = segment.Offset;
int lengthAfterInsertionPos = segmentOffset + segment.TotalLength - (offset + lastDelimiterEnd);
lineCollection.SetSegmentLength(segment, lineBreakOffset - segmentOffset);
LineSegment newSegment = lineCollection.InsertSegmentAfter(segment, lengthAfterInsertionPos);
segment.DelimiterLength = ds.Length;
@ -161,8 +162,10 @@ namespace ICSharpCode.TextEditor.Document @@ -161,8 +162,10 @@ namespace ICSharpCode.TextEditor.Document
void SetSegmentLength(LineSegment segment, int newTotalLength)
{
int delta = newTotalLength - segment.TotalLength;
lineCollection.SetSegmentLength(segment, newTotalLength);
OnLineLengthChanged(new LineLengthEventArgs(document, segment, delta));
if (delta != 0) {
lineCollection.SetSegmentLength(segment, newTotalLength);
OnLineLengthChanged(new LineLengthEventArgs(document, segment, delta));
}
}
void RunHighlighter(int firstLine, int lineCount)
@ -186,8 +189,6 @@ namespace ICSharpCode.TextEditor.Document @@ -186,8 +189,6 @@ namespace ICSharpCode.TextEditor.Document
}
}
public int GetVisibleLine(int logicalLineNumber)
{
if (!document.TextEditorProperties.EnableFolding) {
@ -287,8 +288,9 @@ namespace ICSharpCode.TextEditor.Document @@ -287,8 +288,9 @@ namespace ICSharpCode.TextEditor.Document
}
}
// use always the same ISegment object for the DelimiterInfo
// use always the same DelimiterSegment object for the NextDelimiter
DelimiterSegment delimiterSegment = new DelimiterSegment();
DelimiterSegment NextDelimiter(string text, int offset)
{
for (int i = offset; i < text.Length; i++) {
@ -321,28 +323,10 @@ namespace ICSharpCode.TextEditor.Document @@ -321,28 +323,10 @@ namespace ICSharpCode.TextEditor.Document
public event LineLengthEventHandler LineLengthChanged;
public event LineManagerEventHandler LineCountChanged;
sealed class DelimiterSegment : ISegment
sealed class DelimiterSegment
{
int offset;
int length;
public int Offset {
get {
return offset;
}
set {
offset = value;
}
}
public int Length {
get {
return length;
}
set {
length = value;
}
}
internal int Offset;
internal int Length;
}
}
}

105
src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/TextBufferStrategy/GapTextBufferStrategy.cs

@ -25,20 +25,15 @@ namespace ICSharpCode.TextEditor.Document @@ -25,20 +25,15 @@ namespace ICSharpCode.TextEditor.Document
char[] buffer = new char[0];
int gapBeginOffset = 0;
int gapEndOffset = 0;
int gapEndOffset = 0;
int gapLength = 0; // gapLength == gapEndOffset - gapBeginOffset
int minGapLength = 32;
int maxGapLength = 256;
const int minGapLength = 128;
const int maxGapLength = 2048;
public int Length {
get {
return buffer.Length - GapLength;
}
}
int GapLength {
get {
return gapEndOffset - gapBeginOffset;
return buffer.Length - gapLength;
}
}
@ -48,7 +43,7 @@ namespace ICSharpCode.TextEditor.Document @@ -48,7 +43,7 @@ namespace ICSharpCode.TextEditor.Document
text = String.Empty;
}
buffer = text.ToCharArray();
gapBeginOffset = gapEndOffset = 0;
gapBeginOffset = gapEndOffset = gapLength = 0;
}
public char GetCharAt(int offset)
@ -59,7 +54,7 @@ namespace ICSharpCode.TextEditor.Document @@ -59,7 +54,7 @@ namespace ICSharpCode.TextEditor.Document
throw new ArgumentOutOfRangeException("offset", offset, "0 <= offset < " + Length.ToString());
}
#endif
return offset < gapBeginOffset ? buffer[offset] : buffer[offset + GapLength];
return offset < gapBeginOffset ? buffer[offset] : buffer[offset + gapLength];
}
public string GetText(int offset, int length)
@ -80,7 +75,7 @@ namespace ICSharpCode.TextEditor.Document @@ -80,7 +75,7 @@ namespace ICSharpCode.TextEditor.Document
}
if (offset > gapBeginOffset) {
return new string(buffer, offset + GapLength, length);
return new string(buffer, offset + gapLength, length);
}
int block1Size = gapBeginOffset - offset;
@ -120,56 +115,60 @@ namespace ICSharpCode.TextEditor.Document @@ -120,56 +115,60 @@ namespace ICSharpCode.TextEditor.Document
// Math.Max is used so that if we need to resize the array
// the new array has enough space for all old chars
PlaceGap(offset + length, Math.Max(text.Length - length, 0));
text.CopyTo(0, buffer, offset, text.Length);
gapBeginOffset += text.Length - length;
PlaceGap(offset, text.Length - length);
gapEndOffset += length; // delete removed text
text.CopyTo(0, buffer, gapBeginOffset, text.Length);
gapBeginOffset += text.Length;
gapLength = gapEndOffset - gapBeginOffset;
if (gapLength > maxGapLength) {
MakeNewBuffer(gapBeginOffset, minGapLength);
}
}
void PlaceGap(int offset, int length)
void PlaceGap(int newGapOffset, int minRequiredGapLength)
{
int deltaLength = GapLength - length;
// if the gap has the right length, move the chars between offset and gap
if (minGapLength <= deltaLength && deltaLength <= maxGapLength) {
int delta = gapBeginOffset - offset;
// check if the gap is already in place
if (offset == gapBeginOffset) {
return;
} else if (offset < gapBeginOffset) {
int gapLength = gapEndOffset - gapBeginOffset;
Array.Copy(buffer, offset, buffer, offset + gapLength, delta);
} else { //offset > gapBeginOffset
Array.Copy(buffer, gapEndOffset, buffer, gapBeginOffset, -delta);
if (gapLength < minRequiredGapLength) {
// enlarge gap
MakeNewBuffer(newGapOffset, minRequiredGapLength);
} else {
while (newGapOffset < gapBeginOffset) {
buffer[--gapEndOffset] = buffer[--gapBeginOffset];
}
while (newGapOffset > gapBeginOffset) {
buffer[gapBeginOffset++] = buffer[gapEndOffset++];
}
gapBeginOffset -= delta;
gapEndOffset -= delta;
return;
}
}
void MakeNewBuffer(int newGapOffset, int newGapLength)
{
if (newGapLength < minGapLength) newGapLength = minGapLength;
// the gap has not the right length so
// create new Buffer with new size and copy
int oldLength = GapLength;
int newLength = maxGapLength + length;
int newGapEndOffset = offset + newLength;
char[] newBuffer = new char[buffer.Length + newLength - oldLength];
if (oldLength == 0) {
Array.Copy(buffer, 0, newBuffer, 0, offset);
Array.Copy(buffer, offset, newBuffer, newGapEndOffset, newBuffer.Length - newGapEndOffset);
} else if (offset < gapBeginOffset) {
int delta = gapBeginOffset - offset;
Array.Copy(buffer, 0, newBuffer, 0, offset);
Array.Copy(buffer, offset, newBuffer, newGapEndOffset, delta);
Array.Copy(buffer, gapEndOffset, newBuffer, newGapEndOffset + delta, buffer.Length - gapEndOffset);
char[] newBuffer = new char[Length + newGapLength];
if (newGapOffset < gapBeginOffset) {
// gap is moving backwards
// first part:
Array.Copy(buffer, 0, newBuffer, 0, newGapOffset);
// moving middle part:
Array.Copy(buffer, newGapOffset, newBuffer, newGapOffset + newGapLength, gapBeginOffset - newGapOffset);
// last part:
Array.Copy(buffer, gapEndOffset, newBuffer, newBuffer.Length - (buffer.Length - gapEndOffset), buffer.Length - gapEndOffset);
} else {
int delta = offset - gapBeginOffset;
// gap is moving forwards
// first part:
Array.Copy(buffer, 0, newBuffer, 0, gapBeginOffset);
Array.Copy(buffer, gapEndOffset, newBuffer, gapBeginOffset, delta);
Array.Copy(buffer, gapEndOffset + delta, newBuffer, newGapEndOffset, newBuffer.Length - newGapEndOffset);
// moving middle part:
Array.Copy(buffer, gapEndOffset, newBuffer, gapBeginOffset, newGapOffset - gapBeginOffset);
// last part:
int lastPartLength = newBuffer.Length - (newGapOffset + newGapLength);
Array.Copy(buffer, buffer.Length - lastPartLength, newBuffer, newGapOffset + newGapLength, lastPartLength);
}
buffer = newBuffer;
gapBeginOffset = offset;
gapEndOffset = newGapEndOffset;
gapBeginOffset = newGapOffset;
gapEndOffset = newGapOffset + newGapLength;
gapLength = newGapLength;
buffer = newBuffer;
}
}
}

9
src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextArea.cs

@ -490,6 +490,9 @@ namespace ICSharpCode.TextEditor @@ -490,6 +490,9 @@ namespace ICSharpCode.TextEditor
Graphics g = e.Graphics;
Rectangle clipRectangle = e.ClipRectangle;
bool isFullRepaint = clipRectangle.X == 0 && clipRectangle.Y == 0
&& clipRectangle.Width == this.Width && clipRectangle.Height == this.Height;
g.TextRenderingHint = this.TextEditorProperties.TextRenderingHint;
if (updateMargin != null) {
@ -505,6 +508,10 @@ namespace ICSharpCode.TextEditor @@ -505,6 +508,10 @@ namespace ICSharpCode.TextEditor
if (margin.IsVisible) {
Rectangle marginRectangle = new Rectangle(currentXPos , currentYPos, margin.Size.Width, Height - currentYPos);
if (marginRectangle != margin.DrawingPosition) {
// margin changed size
if (!isFullRepaint && !clipRectangle.Contains(marginRectangle)) {
Invalidate(); // do a full repaint
}
adjustScrollBars = true;
margin.DrawingPosition = marginRectangle;
}
@ -891,7 +898,7 @@ namespace ICSharpCode.TextEditor @@ -891,7 +898,7 @@ namespace ICSharpCode.TextEditor
// return;
// }
lineBegin = Math.Min(lineBegin, FirstPhysicalLine);
//lineBegin = Math.Min(lineBegin, FirstPhysicalLine);
int y = Math.Max( 0, (int)(lineBegin * textView.FontHeight));
y = Math.Max(0, y - this.virtualTop.Y);
Rectangle r = new Rectangle(0,

31
src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaMouseHandler.cs

@ -22,8 +22,6 @@ namespace ICSharpCode.TextEditor @@ -22,8 +22,6 @@ namespace ICSharpCode.TextEditor
{
TextArea textArea;
bool doubleclick = false;
int selbegin;
int selend;
bool clickedOnSelectedText = false;
MouseButtons button;
@ -146,14 +144,12 @@ namespace ICSharpCode.TextEditor @@ -146,14 +144,12 @@ namespace ICSharpCode.TextEditor
void TextAreaMouseMove(object sender, MouseEventArgs e)
{
//Point mousepos = textArea.mousepos;
textArea.mousepos = e.Location;
// honour the starting selection strategy
switch (textArea.SelectionManager.selectFrom.where)
{
case WhereFrom.Gutter:
//moveGutter(sender, e);
ExtendSelectionToMouse();
return;
@ -213,22 +209,21 @@ namespace ICSharpCode.TextEditor @@ -213,22 +209,21 @@ namespace ICSharpCode.TextEditor
return;
}
if (textArea.SelectionManager.selectFrom.where == WhereFrom.Gutter)
// the selection is from the gutter
if (textArea.SelectionManager.selectFrom.where == WhereFrom.Gutter) {
if(realmousepos.Y < textArea.SelectionManager.selectionStart.Y) {
// the selection is from the gutter and it has moved above the startpoint
textArea.Caret.Position = new Point(0, realmousepos.Y);
} else {
if(realmousepos.Y == textArea.SelectionManager.selectionStart.Y) {
textArea.Caret.Position = textArea.SelectionManager.NextValidPosition(realmousepos.Y);
// the selection has moved above the startpoint
textArea.Caret.Position = new Point(0, realmousepos.Y);
} else {
// the selection has moved below the startpoint
textArea.Caret.Position = textArea.SelectionManager.NextValidPosition(realmousepos.Y);
}
}
else
} else {
textArea.Caret.Position = realmousepos;
}
// moves selection across whole words
if (minSelection != nilPoint && textArea.SelectionManager.SelectionCollection.Count > 0) {
// moves selection across whole words for double-click initiated selection
if (minSelection != nilPoint && textArea.SelectionManager.SelectionCollection.Count > 0 && textArea.SelectionManager.selectFrom.where == WhereFrom.TArea) {
// Extend selection when selection was started with double-click
ISelection selection = textArea.SelectionManager.SelectionCollection[0];
Point min = textArea.SelectionManager.GreaterEqPos(minSelection, maxSelection) ? maxSelection : minSelection;
@ -236,12 +231,10 @@ namespace ICSharpCode.TextEditor @@ -236,12 +231,10 @@ namespace ICSharpCode.TextEditor
if (textArea.SelectionManager.GreaterEqPos(max, realmousepos) && textArea.SelectionManager.GreaterEqPos(realmousepos, min)) {
textArea.SelectionManager.SetSelection(min, max);
} else if (textArea.SelectionManager.GreaterEqPos(max, realmousepos)) {
//textArea.SelectionManager.SetSelection(realmousepos, max);
int moff = textArea.Document.PositionToOffset(realmousepos);
min = textArea.Document.OffsetToPosition(FindWordStart(textArea.Document, moff));
textArea.SelectionManager.SetSelection(min, max);
} else {
//textArea.SelectionManager.SetSelection(min, realmousepos);
int moff = textArea.Document.PositionToOffset(realmousepos);
max = textArea.Document.OffsetToPosition(FindWordEnd(textArea.Document, moff));
textArea.SelectionManager.SetSelection(min, max);
@ -386,13 +379,12 @@ namespace ICSharpCode.TextEditor @@ -386,13 +379,12 @@ namespace ICSharpCode.TextEditor
textArea.SelectionManager.IsSelected(offset)) {
clickedOnSelectedText = true;
} else {
selbegin = selend = offset;
textArea.SelectionManager.ClearSelection();
if (mousepos.Y > 0 && mousepos.Y < textArea.TextView.DrawingPosition.Height) {
Point pos = new Point();
pos.Y = Math.Min(textArea.Document.TotalNumberOfLines - 1, realmousepos.Y);
pos.X = realmousepos.X;
textArea.Caret.Position = pos;//Math.Max(0, Math.Min(textArea.Document.TextLength, line.Offset + Math.Min(line.Length, pos.X)));
textArea.Caret.Position = pos;
textArea.SetDesiredColumn();
}
}
@ -405,13 +397,12 @@ namespace ICSharpCode.TextEditor @@ -405,13 +397,12 @@ namespace ICSharpCode.TextEditor
if (!textArea.SelectionManager.HasSomethingSelected ||
!textArea.SelectionManager.IsSelected(offset))
{
selbegin = selend = offset;
textArea.SelectionManager.ClearSelection();
if (mousepos.Y > 0 && mousepos.Y < textArea.TextView.DrawingPosition.Height) {
Point pos = new Point();
pos.Y = Math.Min(textArea.Document.TotalNumberOfLines - 1, realmousepos.Y);
pos.X = realmousepos.X;
textArea.Caret.Position = pos;//Math.Max(0, Math.Min(textArea.Document.TextLength, line.Offset + Math.Min(line.Length, pos.X)));
textArea.Caret.Position = pos;
textArea.SetDesiredColumn();
}
}

8
src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextEditorControl.cs

@ -257,10 +257,10 @@ namespace ICSharpCode.TextEditor @@ -257,10 +257,10 @@ namespace ICSharpCode.TextEditor
}
}
Document.UpdateQueue.Clear();
this.primaryTextArea.TextArea.Update();
if (this.secondaryTextArea != null) {
this.secondaryTextArea.TextArea.Update();
}
// this.primaryTextArea.TextArea.Update();
// if (this.secondaryTextArea != null) {
// this.secondaryTextArea.TextArea.Update();
// }
}
#endregion

2
src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextView.cs

@ -148,7 +148,7 @@ namespace ICSharpCode.TextEditor @@ -148,7 +148,7 @@ namespace ICSharpCode.TextEditor
// Just to ensure that fontHeight and char widths are always correct...
if (lastFont != TextEditorProperties.FontContainer.RegularFont) {
OptionsChanged();
base.TextArea.BeginInvoke(new MethodInvoker(base.TextArea.Refresh));
textArea.Invalidate();
}
int horizontalDelta = (int)(textArea.VirtualTop.X * WideSpaceWidth);

Loading…
Cancel
Save