Skip to content

Commit 14453e3

Browse files
author
PavelTorgashov
committed
Fixed bug with replacing and undo/redo
1 parent 07bc500 commit 14453e3

8 files changed

Lines changed: 85 additions & 5 deletions

File tree

Binary/FastColoredTextBox.dll

1.5 KB
Binary file not shown.

Binary/FastColoredTextBox.xml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Binary/Tester.exe

512 Bytes
Binary file not shown.

FastColoredTextBox/Commands.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,8 @@ internal static void ClearSelected(TextSource ts)
347347
{
348348
var tb = ts.CurrentTB;
349349

350+
tb.Selection.Normalize();
351+
350352
Place start = tb.Selection.Start;
351353
Place end = tb.Selection.End;
352354
int fromLine = Math.Min(end.iLine, start.iLine);

FastColoredTextBox/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("2.10.8.0")]
36-
[assembly: AssemblyFileVersion("2.10.8.0")]
35+
[assembly: AssemblyVersion("2.10.9.0")]
36+
[assembly: AssemblyFileVersion("2.10.9.0")]

FastColoredTextBox/Range.cs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,8 @@ public IEnumerable<Range> GetRangesByLines(string regexPattern, RegexOptions opt
836836
//create regex
837837
Regex regex = new Regex(regexPattern, options);
838838
//
839-
var fts = tb.TextSource as FileTextSource;//<----!!!! ugly
839+
var fts = tb.TextSource as FileTextSource; //<----!!!! ugly
840+
840841
//enumaerate lines
841842
for (int iLine = Start.iLine; iLine <= End.iLine; iLine++)
842843
{
@@ -855,6 +856,44 @@ public IEnumerable<Range> GetRangesByLines(string regexPattern, RegexOptions opt
855856
}
856857
}
857858

859+
/// <summary>
860+
/// Finds ranges for given regex pattern.
861+
/// Search is separately in each line (order of lines is reversed).
862+
/// This method requires less memory than GetRanges().
863+
/// </summary>
864+
/// <param name="regexPattern">Regex pattern</param>
865+
/// <returns>Enumeration of ranges</returns>
866+
public IEnumerable<Range> GetRangesByLinesReversed(string regexPattern, RegexOptions options)
867+
{
868+
Normalize();
869+
//create regex
870+
Regex regex = new Regex(regexPattern, options);
871+
//
872+
var fts = tb.TextSource as FileTextSource; //<----!!!! ugly
873+
874+
//enumaerate lines
875+
for (int iLine = End.iLine; iLine >= Start.iLine; iLine--)
876+
{
877+
//
878+
bool isLineLoaded = fts != null ? fts.IsLineLoaded(iLine) : true;
879+
//
880+
var r = new Range(tb, new Place(0, iLine), new Place(tb[iLine].Count, iLine));
881+
if (iLine == Start.iLine || iLine == End.iLine)
882+
r = r.GetIntersectionWith(this);
883+
884+
var list = new List<Range>();
885+
886+
foreach (var foundRange in r.GetRanges(regex))
887+
list.Add(foundRange);
888+
889+
for (int i = list.Count - 1; i >= 0; i--)
890+
yield return list[i];
891+
892+
if (!isLineLoaded)
893+
fts.UnloadLine(iLine);
894+
}
895+
}
896+
858897
/// <summary>
859898
/// Finds ranges for given regex
860899
/// </summary>

Tester/Sandbox.Designer.cs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tester/Sandbox.cs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,39 @@ public Sandbox()
1414
InitializeComponent();
1515
}
1616

17+
private void fctb_AutoIndentNeeded(object sender, AutoIndentEventArgs e)
18+
{
19+
if (Regex.IsMatch(e.PrevLineText, @"^\s*For\(.*\)"))
20+
{
21+
e.Shift = e.Shift + e.TabLength;
22+
e.ShiftNextLines = e.ShiftNextLines + e.TabLength;
23+
return;
24+
}
25+
if (Regex.IsMatch(e.PrevLineText, @"^\s*If\(.*\)"))
26+
{
27+
e.Shift = e.Shift + e.TabLength;
28+
e.ShiftNextLines = e.ShiftNextLines + e.TabLength;
29+
return;
30+
}
31+
if (Regex.IsMatch(e.LineText, @"###"))
32+
{
33+
e.Shift = e.Shift - e.TabLength;
34+
e.ShiftNextLines = e.ShiftNextLines - e.TabLength;
35+
return;
36+
}
37+
if (Regex.IsMatch(e.LineText, @"\$\$\$"))
38+
{
39+
e.Shift = e.Shift - e.TabLength;
40+
e.ShiftNextLines = e.ShiftNextLines - e.TabLength;
41+
return;
42+
}
43+
}
44+
1745
private void button1_Click(object sender, EventArgs e)
1846
{
19-
var bmp = new Bitmap(fctb.Width, fctb.Height);
20-
fctb.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
47+
fctb.Visible = false;
48+
var bmp = new Bitmap(fctb.Width,fctb.Height);
49+
fctb.DrawToBitmap(bmp, new Rectangle(0, 0, fctb.Width, fctb.Height));
2150
bmp.Save("c:\\temp.png");
2251
}
2352
}

0 commit comments

Comments
 (0)