Browse Source

Always append text to the scripting console to prevent text appearing at the current cursor position when lots of console output generated and the cursor is moved by the user.

4.0
Matt Ward 15 years ago
parent
commit
93d09a06c6
  1. 4
      src/AddIns/BackendBindings/Scripting/Project/Src/IScriptingConsoleTextEditor.cs
  2. 4
      src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingConsole.cs
  3. 2
      src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingConsoleOutputStream.cs
  4. 11
      src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingConsoleTextEditor.cs
  5. 4
      src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleOutputStreamTests.cs
  6. 6
      src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleReadTests.cs
  7. 27
      src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleSendLineTests.cs
  8. 32
      src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleSendTextTests.cs
  9. 19
      src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleTextEditorTests.cs
  10. 12
      src/AddIns/BackendBindings/Scripting/Test/Utils/FakeConsoleTextEditor.cs
  11. 26
      src/AddIns/BackendBindings/Scripting/Test/Utils/Tests/MockConsoleTextEditorTests.cs

4
src/AddIns/BackendBindings/Scripting/Project/Src/IScriptingConsoleTextEditor.cs

@ -24,9 +24,9 @@ namespace ICSharpCode.Scripting @@ -24,9 +24,9 @@ namespace ICSharpCode.Scripting
event ConsoleTextEditorKeyEventHandler PreviewKeyDown;
/// <summary>
/// Inserts text at the current cursor location.
/// Appends text to the end of the text editor.
/// </summary>
void Write(string text);
void Append(string text);
/// <summary>
/// Replaces the text at the specified index on the current line with the specified text.

4
src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingConsole.cs

@ -69,7 +69,7 @@ namespace ICSharpCode.Scripting @@ -69,7 +69,7 @@ namespace ICSharpCode.Scripting
/// </summary>
public void Write(string text, ScriptingStyle style)
{
textEditor.Write(text);
textEditor.Append(text);
if (style == ScriptingStyle.Prompt) {
firstPromptDisplayed = true;
promptLength = text.Length;
@ -84,7 +84,7 @@ namespace ICSharpCode.Scripting @@ -84,7 +84,7 @@ namespace ICSharpCode.Scripting
{
if (textSent.HasLine) {
string line = textSent.RemoveFirstLine();
textEditor.Write(line);
textEditor.Append(line);
}
}

2
src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingConsoleOutputStream.cs

@ -69,7 +69,7 @@ namespace ICSharpCode.Scripting @@ -69,7 +69,7 @@ namespace ICSharpCode.Scripting
void ThreadSafeTextEditorWrite(string text)
{
if (dispatcher.CheckAccess()) {
textEditor.Write(text);
textEditor.Append(text);
} else {
Action<string> action = ThreadSafeTextEditorWrite;
dispatcher.Invoke(action, text);

11
src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingConsoleTextEditor.cs

@ -46,16 +46,9 @@ namespace ICSharpCode.Scripting @@ -46,16 +46,9 @@ namespace ICSharpCode.Scripting
get { return customLineColour; }
}
public void Write(string text)
public void Append(string text)
{
TextLocation location = GetCurrentCursorLocation();
int offset = textEditor.Document.GetOffset(location);
textEditor.Document.Insert(offset, text);
}
TextLocation GetCurrentCursorLocation()
{
return new TextLocation(Line + 1, Column + 1);
textEditor.AppendText(text);
}
public int Column {

4
src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleOutputStreamTests.cs

@ -52,7 +52,7 @@ namespace ICSharpCode.Scripting.Tests.Console @@ -52,7 +52,7 @@ namespace ICSharpCode.Scripting.Tests.Console
byte[] bytes = UTF8Encoding.UTF8.GetBytes("test");
stream.Write(bytes, 0, bytes.Length);
string text = textEditor.TextPassedToWrite;
string text = textEditor.TextPassedToAppend;
string expectedText = "test";
Assert.AreEqual(expectedText, text);
@ -65,7 +65,7 @@ namespace ICSharpCode.Scripting.Tests.Console @@ -65,7 +65,7 @@ namespace ICSharpCode.Scripting.Tests.Console
byte[] bytes = UTF8Encoding.UTF8.GetBytes("0output1");
stream.Write(bytes, 1, bytes.Length - 2);
string text = textEditor.TextPassedToWrite;
string text = textEditor.TextPassedToAppend;
string expectedText = "output";
Assert.AreEqual(expectedText, text);

6
src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleReadTests.cs

@ -28,7 +28,7 @@ namespace ICSharpCode.Scripting.Tests.Console @@ -28,7 +28,7 @@ namespace ICSharpCode.Scripting.Tests.Console
TestableScriptingConsole.ReadLine(indent);
string expectedText = " ";
Assert.AreEqual(expectedText, FakeConsoleTextEditor.TextPassedToWrite);
Assert.AreEqual(expectedText, FakeConsoleTextEditor.TextPassedToAppend);
}
[Test]
@ -38,11 +38,11 @@ namespace ICSharpCode.Scripting.Tests.Console @@ -38,11 +38,11 @@ namespace ICSharpCode.Scripting.Tests.Console
FakeConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A);
FakeConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter);
FakeConsoleTextEditor.IsWriteCalled = false;
FakeConsoleTextEditor.IsAppendCalled = false;
TestableScriptingConsole.ReadLine(0);
Assert.IsFalse(FakeConsoleTextEditor.IsWriteCalled);
Assert.IsFalse(FakeConsoleTextEditor.IsAppendCalled);
}
[Test]

27
src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleSendLineTests.cs

@ -52,41 +52,18 @@ namespace ICSharpCode.Scripting.Tests.Console @@ -52,41 +52,18 @@ namespace ICSharpCode.Scripting.Tests.Console
public void SendLine_NoUnreadLines_LineWrittenToConsoleTextEditor()
{
SendLineToConsole("test");
string text = FakeConsoleTextEditor.TextPassedToWrite;
string text = FakeConsoleTextEditor.TextPassedToAppend;
string expectedTextWritten = "test\r\n";
Assert.AreEqual(expectedTextWritten, text);
}
[Test]
public void SendLine_TwoLinesInConsoleTextEditorCursorOnFirstLine_CursorMovedToEndOfLastLineBeforeTextWritten()
{
base.CreateConsole();
WritePrompt();
FakeConsoleTextEditor.Text =
">>> first\r\n" +
">>> second\r\n" +
">>> ";
FakeConsoleTextEditor.Line = 0;
FakeConsoleTextEditor.Column = 0;
TestableScriptingConsole.SendLine("test");
int expectedLine = 2;
int expectedColumn = 4;
Location expectedLocation = new Location(expectedColumn, expectedLine);
Location location = FakeConsoleTextEditor.CursorLocationWhenWriteTextCalled;
Assert.AreEqual(expectedLocation, location);
}
[Test]
public void SendLine_NoUnreadLines_NoTextWrittenToConsoleTextEditorBeforeFirstPromptIsWritten()
{
base.CreateConsole();
TestableScriptingConsole.SendLine("test");
string text = FakeConsoleTextEditor.TextPassedToWrite;
string text = FakeConsoleTextEditor.TextPassedToAppend;
Assert.IsNull(text);
}

32
src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleSendTextTests.cs

@ -17,7 +17,7 @@ namespace ICSharpCode.Scripting.Tests.Console @@ -17,7 +17,7 @@ namespace ICSharpCode.Scripting.Tests.Console
{
SendTextToConsole("test");
string text = base.FakeConsoleTextEditor.TextPassedToWrite;
string text = base.FakeConsoleTextEditor.TextPassedToAppend;
string expectedText = "test";
Assert.AreEqual(expectedText, text);
}
@ -29,32 +29,12 @@ namespace ICSharpCode.Scripting.Tests.Console @@ -29,32 +29,12 @@ namespace ICSharpCode.Scripting.Tests.Console
TestableScriptingConsole.SendText(text);
}
[Test]
public void SendText_TextEditorHasTextAfterPrompt_CursorMovedToEndOfLastLineBeforeTextWritten()
{
base.CreateConsole();
WritePrompt();
FakeConsoleTextEditor.Text = ">>> first";
FakeConsoleTextEditor.Line = -1;
FakeConsoleTextEditor.Column = -1;
TestableScriptingConsole.SendText("test");
int expectedLine = 0;
int expectedColumn = 9;
Location expectedLocation = new Location(expectedColumn, expectedLine);
Location location = FakeConsoleTextEditor.CursorLocationWhenWriteTextCalled;
Assert.AreEqual(expectedLocation, location);
}
[Test]
public void SendText_FirstPromptNotYetWrittenToConsole_NoTextWrittenToConsoleTextEditor()
{
base.CreateConsole();
TestableScriptingConsole.SendText("test");
string text = FakeConsoleTextEditor.TextPassedToWrite;
string text = FakeConsoleTextEditor.TextPassedToAppend;
Assert.IsNull(text);
}
@ -66,7 +46,7 @@ namespace ICSharpCode.Scripting.Tests.Console @@ -66,7 +46,7 @@ namespace ICSharpCode.Scripting.Tests.Console
TestableScriptingConsole.SendText("test");
TestableScriptingConsole.Write(">>> ", ScriptingStyle.Prompt);
string text = FakeConsoleTextEditor.TextPassedToWrite;
string text = FakeConsoleTextEditor.TextPassedToAppend;
string expectedText = "test";
Assert.AreEqual(expectedText, text);
@ -84,7 +64,7 @@ namespace ICSharpCode.Scripting.Tests.Console @@ -84,7 +64,7 @@ namespace ICSharpCode.Scripting.Tests.Console
TestableScriptingConsole.Write(">>> ", ScriptingStyle.Prompt);
TestableScriptingConsole.Write(">>> ", ScriptingStyle.Prompt);
string textPassedToWrite = FakeConsoleTextEditor.TextPassedToWrite;
string textPassedToWrite = FakeConsoleTextEditor.TextPassedToAppend;
string expectedText = "second";
Assert.AreEqual(expectedText, textPassedToWrite);
@ -99,7 +79,7 @@ namespace ICSharpCode.Scripting.Tests.Console @@ -99,7 +79,7 @@ namespace ICSharpCode.Scripting.Tests.Console
SendTextToConsole(selectedText);
string text = base.FakeConsoleTextEditor.TextPassedToWrite;
string text = base.FakeConsoleTextEditor.TextPassedToAppend;
string expectedText = "first\r\n";
Assert.AreEqual(expectedText, text);
}
@ -114,7 +94,7 @@ namespace ICSharpCode.Scripting.Tests.Console @@ -114,7 +94,7 @@ namespace ICSharpCode.Scripting.Tests.Console
SendTextToConsole(selectedText);
WritePrompt();
string text = base.FakeConsoleTextEditor.TextPassedToWrite;
string text = base.FakeConsoleTextEditor.TextPassedToAppend;
string expectedText = "second";
Assert.AreEqual(expectedText, text);
}

19
src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleTextEditorTests.cs

@ -38,7 +38,7 @@ namespace ICSharpCode.Scripting.Tests.Console @@ -38,7 +38,7 @@ namespace ICSharpCode.Scripting.Tests.Console
public void MakeCurrentContentReadOnly_OneLineOfTextInTextEditor_ExtendsReadOnlyRegionToEntireDocument()
{
avalonEditTextEditor.Text = String.Empty;
consoleTextEditor.Write("abc" + Environment.NewLine);
consoleTextEditor.Append("abc" + Environment.NewLine);
consoleTextEditor.MakeCurrentContentReadOnly();
IReadOnlySectionProvider readOnlySection = avalonEditTextEditor.TextArea.ReadOnlySectionProvider;
@ -47,10 +47,10 @@ namespace ICSharpCode.Scripting.Tests.Console @@ -47,10 +47,10 @@ namespace ICSharpCode.Scripting.Tests.Console
}
[Test]
public void Write_TextEditorHasNoText_UpdatesTextEditor()
public void Append_TextEditorHasNoText_UpdatesTextEditor()
{
avalonEditTextEditor.Text = String.Empty;
consoleTextEditor.Write("abc");
consoleTextEditor.Append("abc");
string text = avalonEditTextEditor.Text;
string expectedText = "abc";
@ -58,6 +58,19 @@ namespace ICSharpCode.Scripting.Tests.Console @@ -58,6 +58,19 @@ namespace ICSharpCode.Scripting.Tests.Console
Assert.AreEqual(expectedText, text);
}
[Test]
public void Append_CursorNotAtEndOfText_TextIsWrittenAtEnd()
{
avalonEditTextEditor.Text = "abc";
avalonEditTextEditor.CaretOffset = 0;
consoleTextEditor.Append("d");
string text = avalonEditTextEditor.Text;
string expectedText = "abcd";
Assert.AreEqual(expectedText, text);
}
[Test]
public void Column_TextEditorColumnSetToThree_ZeroBasedConsoleTextEditorColumnPositionReturnsTwoWhichIsOneLessThanAvalonTextEditorColumnPositionWhichIsOneBased()
{

12
src/AddIns/BackendBindings/Scripting/Test/Utils/FakeConsoleTextEditor.cs

@ -15,16 +15,15 @@ namespace ICSharpCode.Scripting.Tests.Utils @@ -15,16 +15,15 @@ namespace ICSharpCode.Scripting.Tests.Utils
public class FakeConsoleTextEditor : IScriptingConsoleTextEditor
{
public bool IsDisposed;
public bool IsWriteCalled;
public bool IsAppendCalled;
public bool IsShowCompletionWindowCalled;
public bool IsMakeCurrentContentReadOnlyCalled;
public ScriptingConsoleCompletionDataProvider CompletionProviderPassedToShowCompletionWindow;
public string TextPassedToWrite;
public string TextPassedToAppend;
public string TextPassedToReplace;
public int LengthPassedToReplace = -1;
public int IndexPassedToReplace = -1;
public Location CursorLocationWhenWriteTextCalled;
public bool IsColumnChangedBeforeTextWritten;
public StringBuilder PreviousLines = new StringBuilder();
@ -42,11 +41,10 @@ namespace ICSharpCode.Scripting.Tests.Utils @@ -42,11 +41,10 @@ namespace ICSharpCode.Scripting.Tests.Utils
IsDisposed = true;
}
public void Write(string text)
public void Append(string text)
{
TextPassedToWrite = text;
CursorLocationWhenWriteTextCalled = new Location(Column, Line);
IsWriteCalled = true;
TextPassedToAppend = text;
IsAppendCalled = true;
LineBuilder.Append(text);
Column += text.Length;
}

26
src/AddIns/BackendBindings/Scripting/Test/Utils/Tests/MockConsoleTextEditorTests.cs

@ -26,40 +26,40 @@ namespace ICSharpCode.Scripting.Tests.Utils.Tests @@ -26,40 +26,40 @@ namespace ICSharpCode.Scripting.Tests.Utils.Tests
}
[Test]
public void TextReturnsTextWritten()
public void TextReturnsTextAppended()
{
textEditor.Write("abc");
textEditor.Append("abc");
Assert.AreEqual("abc", textEditor.Text);
}
[Test]
public void ColumnReturnsPositionAfterTextWritten()
public void ColumnReturnsPositionAfterTextAppended()
{
textEditor.Write("ab");
textEditor.Append("ab");
Assert.AreEqual(2, textEditor.Column);
}
[Test]
public void TextReturnsAllTextWritten()
public void TextReturnsAllTextAppended()
{
textEditor.Write("a");
textEditor.Write("b");
textEditor.Append("a");
textEditor.Append("b");
Assert.AreEqual("ab", textEditor.Text);
}
[Test]
public void ColumnReturnsPositionAfterTextWhenWriteCalledTwice()
public void ColumnReturnsPositionAfterTextWhenAppendCalledTwice()
{
textEditor.Write("a");
textEditor.Write("bb");
textEditor.Append("a");
textEditor.Append("bb");
Assert.AreEqual(3, textEditor.Column);
}
[Test]
public void IsWriteCalledReturnsTrueAfterWriteMethodCalled()
public void IsAppendCalledReturnsTrueAfterAppendMethodCalled()
{
textEditor.Write("a");
Assert.IsTrue(textEditor.IsWriteCalled);
textEditor.Append("a");
Assert.IsTrue(textEditor.IsAppendCalled);
}
[Test]

Loading…
Cancel
Save