From 3b917d707f0dafd6b5d9ee6189a2b621d26c511e Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Sun, 2 Nov 2008 12:03:43 +0000 Subject: [PATCH] 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 --- .../Project/Src/CommandLineHistory.cs | 12 +++++++++--- .../Test/Console/CommandLineHistoryTestFixture.cs | 14 ++++++++++++++ .../OneItemCommandLineHistoryTestFixture.cs | 4 ++-- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/CommandLineHistory.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/CommandLineHistory.cs index 332c81d8be..000959fdf7 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/CommandLineHistory.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/CommandLineHistory.cs @@ -16,7 +16,7 @@ namespace ICSharpCode.PythonBinding public class CommandLineHistory { List lines = new List(); - int position = -1; + int position; public CommandLineHistory() { @@ -55,20 +55,26 @@ namespace ICSharpCode.PythonBinding /// /// Moves to the next command line. /// + /// False if the current position is at the end of the command line history. public bool MoveNext() { - if (position < lines.Count) { + int nextPosition = position + 1; + if (nextPosition < lines.Count) { ++position; } - return position < lines.Count; + return nextPosition < lines.Count; } /// /// Moves to the previous command line. /// + /// False if the current position is at the start of the command line history. public bool MovePrevious() { if (position >= 0) { + if (position == 0) { + return false; + } --position; } return position >= 0; diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/CommandLineHistoryTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/CommandLineHistoryTestFixture.cs index 7056ad925a..756ec17f10 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/CommandLineHistoryTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/CommandLineHistoryTestFixture.cs @@ -64,5 +64,19 @@ namespace PythonBinding.Tests.Console history.MovePrevious(); Assert.AreEqual("c", history.Current); } + + /// + /// After trying to move beyond the end of the list moving previous should not show the last + /// item again. + /// + [Test] + public void MovePreviousThenNextTwiceThenPreviousAgain() + { + history.MovePrevious(); + history.MoveNext(); + history.MoveNext(); + history.MovePrevious(); + Assert.AreEqual("b", history.Current); + } } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/OneItemCommandLineHistoryTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/OneItemCommandLineHistoryTestFixture.cs index f45cf3748e..b1f838228b 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/OneItemCommandLineHistoryTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/OneItemCommandLineHistoryTestFixture.cs @@ -60,7 +60,7 @@ namespace PythonBinding.Tests.Console { history.MovePrevious(); history.MovePrevious(); - Assert.IsNull(history.Current); + Assert.AreEqual("a", history.Current); } [Test] @@ -75,7 +75,7 @@ namespace PythonBinding.Tests.Console { history.MovePrevious(); history.MoveNext(); - Assert.IsNull(history.Current); + Assert.AreEqual("a", history.Current); } [Test]