}
[Fact]
- public void Back_NoItemsTest()
+ public void SetCurrentItem_Test()
{
var history = new StatusTextHistory();
- history.Back("@hoge aaa", (new TwitterStatusId("111"), "hoge"));
+ history.SetCurrentItem("@hoge aaa", (new TwitterStatusId("111"), "hoge"));
Assert.Single(history.Items);
Assert.Equal(new("@hoge aaa", (new TwitterStatusId("111"), "hoge")), history.Items[0]);
Assert.Equal(0, history.HistoryIndex);
}
[Fact]
+ public void Back_NoItemsTest()
+ {
+ var history = new StatusTextHistory();
+ history.Back();
+ Assert.Single(history.Items);
+ Assert.Equal(new("", null), history.Items[0]);
+ Assert.Equal(0, history.HistoryIndex);
+ }
+
+ [Fact]
public void Back_HasItemsTest()
{
var history = new StatusTextHistory();
history.AddLast("@hoge aaa", (new TwitterStatusId("111"), "hoge"));
- history.Back("@foo bbb", (new TwitterStatusId("222"), "foo"));
+ history.Back();
Assert.Equal(2, history.Items.Count);
Assert.Equal(new("@hoge aaa", (new TwitterStatusId("111"), "hoge")), history.Items[0]);
- Assert.Equal(new("@foo bbb", (new TwitterStatusId("222"), "foo")), history.Items[1]);
+ Assert.Equal(new("", null), history.Items[1]);
Assert.Equal(0, history.HistoryIndex);
}
public void Forward_NoItemsTest()
{
var history = new StatusTextHistory();
- history.Forward("@hoge aaa", (new TwitterStatusId("111"), "hoge"));
+ history.Forward();
Assert.Single(history.Items);
- Assert.Equal(new("@hoge aaa", (new TwitterStatusId("111"), "hoge")), history.Items[0]);
+ Assert.Equal(new("", null), history.Items[0]);
Assert.Equal(0, history.HistoryIndex);
}
{
var history = new StatusTextHistory();
history.AddLast("@hoge aaa", (new TwitterStatusId("111"), "hoge"));
- history.Back("@foo bbb", (new TwitterStatusId("222"), "foo"));
- history.Forward("@hoge aaa 123", (new TwitterStatusId("111"), "hoge"));
+ history.Back();
+ history.Forward();
Assert.Equal(2, history.Items.Count);
- Assert.Equal(new("@hoge aaa 123", (new TwitterStatusId("111"), "hoge")), history.Items[0]);
- Assert.Equal(new("@foo bbb", (new TwitterStatusId("222"), "foo")), history.Items[1]);
+ Assert.Equal(new("@hoge aaa", (new TwitterStatusId("111"), "hoge")), history.Items[0]);
+ Assert.Equal(new("", null), history.Items[1]);
Assert.Equal(1, history.HistoryIndex);
}
public StatusTextHistory()
=> this.items.Add(new(""));
- public HistoryItem Back(string text, (PostId StatusId, string ScreenName)? inReplyTo)
+ public void SetCurrentItem(string text, (PostId StatusId, string ScreenName)? inReplyTo)
{
if (!string.IsNullOrWhiteSpace(text))
this.items[this.historyIndex] = new(text, inReplyTo);
+ }
- this.historyIndex -= 1;
- if (this.historyIndex < 0)
- this.historyIndex = 0;
+ public HistoryItem Back()
+ {
+ if (this.historyIndex > 0)
+ this.historyIndex--;
return this.items[this.historyIndex];
}
- public HistoryItem Forward(string text, (PostId StatusId, string ScreenName)? inReplyTo)
+ public HistoryItem Forward()
{
- if (!string.IsNullOrWhiteSpace(text))
- this.items[this.historyIndex] = new(text, inReplyTo);
-
- this.historyIndex += 1;
- if (this.historyIndex > this.items.Count - 1)
- this.historyIndex = this.items.Count - 1;
+ if (this.historyIndex < this.items.Count - 1)
+ this.historyIndex++;
return this.items[this.historyIndex];
}
public void AddLast(string text, (PostId StatusId, string ScreenName)? inReplyTo)
{
- this.items[this.items.Count - 1] = new(text, inReplyTo);
+ this.historyIndex = this.items.Count - 1;
+ this.SetCurrentItem(text, inReplyTo);
this.items.Add(new(""));
- this.historyIndex = this.items.Count - 1;
+ this.historyIndex++;
}
public HistoryItem? Peek()
private void StatusTextHistoryBack()
{
- var historyItem = this.history.Back(this.StatusText.Text, this.inReplyTo);
+ this.history.SetCurrentItem(this.StatusText.Text, this.inReplyTo);
+ var historyItem = this.history.Back();
this.inReplyTo = historyItem.InReplyTo;
this.StatusText.Text = historyItem.Status;
this.StatusText.SelectionStart = this.StatusText.Text.Length;
private void StatusTextHistoryForward()
{
- var historyItem = this.history.Forward(this.StatusText.Text, this.inReplyTo);
+ this.history.SetCurrentItem(this.StatusText.Text, this.inReplyTo);
+ var historyItem = this.history.Forward();
this.inReplyTo = historyItem.InReplyTo;
this.StatusText.Text = historyItem.Status;
this.StatusText.SelectionStart = this.StatusText.Text.Length;