Browse Source

Changed the Python console window command line history so it behaves the same as ipy. Previously after reaching the start/end of the command line history the start/end command line would be shown again when moving the other way through the history.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3632 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 18 years ago
parent
commit
3b917d707f
  1. 12
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/CommandLineHistory.cs
  2. 14
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/CommandLineHistoryTestFixture.cs
  3. 4
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/OneItemCommandLineHistoryTestFixture.cs

12
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/CommandLineHistory.cs

@ -16,7 +16,7 @@ namespace ICSharpCode.PythonBinding
public class CommandLineHistory public class CommandLineHistory
{ {
List<string> lines = new List<string>(); List<string> lines = new List<string>();
int position = -1; int position;
public CommandLineHistory() public CommandLineHistory()
{ {
@ -55,20 +55,26 @@ namespace ICSharpCode.PythonBinding
/// <summary> /// <summary>
/// Moves to the next command line. /// Moves to the next command line.
/// </summary> /// </summary>
/// <returns>False if the current position is at the end of the command line history.</returns>
public bool MoveNext() public bool MoveNext()
{ {
if (position < lines.Count) { int nextPosition = position + 1;
if (nextPosition < lines.Count) {
++position; ++position;
} }
return position < lines.Count; return nextPosition < lines.Count;
} }
/// <summary> /// <summary>
/// Moves to the previous command line. /// Moves to the previous command line.
/// </summary> /// </summary>
/// <returns>False if the current position is at the start of the command line history.</returns>
public bool MovePrevious() public bool MovePrevious()
{ {
if (position >= 0) { if (position >= 0) {
if (position == 0) {
return false;
}
--position; --position;
} }
return position >= 0; return position >= 0;

14
src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/CommandLineHistoryTestFixture.cs

@ -64,5 +64,19 @@ namespace PythonBinding.Tests.Console
history.MovePrevious(); history.MovePrevious();
Assert.AreEqual("c", history.Current); Assert.AreEqual("c", history.Current);
} }
/// <summary>
/// After trying to move beyond the end of the list moving previous should not show the last
/// item again.
/// </summary>
[Test]
public void MovePreviousThenNextTwiceThenPreviousAgain()
{
history.MovePrevious();
history.MoveNext();
history.MoveNext();
history.MovePrevious();
Assert.AreEqual("b", history.Current);
}
} }
} }

4
src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/OneItemCommandLineHistoryTestFixture.cs

@ -60,7 +60,7 @@ namespace PythonBinding.Tests.Console
{ {
history.MovePrevious(); history.MovePrevious();
history.MovePrevious(); history.MovePrevious();
Assert.IsNull(history.Current); Assert.AreEqual("a", history.Current);
} }
[Test] [Test]
@ -75,7 +75,7 @@ namespace PythonBinding.Tests.Console
{ {
history.MovePrevious(); history.MovePrevious();
history.MoveNext(); history.MoveNext();
Assert.IsNull(history.Current); Assert.AreEqual("a", history.Current);
} }
[Test] [Test]

Loading…
Cancel
Save