OSDN Git Service

SetLastItemとAddLastメソッドを統合
authorKimura Youichi <kim.upsilon@bucyou.net>
Mon, 8 Jan 2024 00:28:41 +0000 (09:28 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Mon, 8 Jan 2024 00:28:41 +0000 (09:28 +0900)
OpenTween.Tests/Models/StatusTextHistoryTest.cs
OpenTween/Models/StatusTextHistory.cs
OpenTween/Tween.cs

index 922522c..c33fe44 100644 (file)
@@ -48,8 +48,7 @@ namespace OpenTween.Models
         public void Back_HasItemsTest()
         {
             var history = new StatusTextHistory();
-            history.SetLastItem("@hoge aaa", (new TwitterStatusId("111"), "hoge"));
-            history.AddLast();
+            history.AddLast("@hoge aaa", (new TwitterStatusId("111"), "hoge"));
             history.Back("@foo bbb", (new TwitterStatusId("222"), "foo"));
 
             Assert.Equal(2, history.Items.Count);
@@ -72,8 +71,7 @@ namespace OpenTween.Models
         public void Forward_HasItemsTest()
         {
             var history = new StatusTextHistory();
-            history.SetLastItem("@hoge aaa", (new TwitterStatusId("111"), "hoge"));
-            history.AddLast();
+            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"));
 
@@ -87,8 +85,7 @@ namespace OpenTween.Models
         public void AddLast_Test()
         {
             var history = new StatusTextHistory();
-            history.SetLastItem("@hoge aaa", (new TwitterStatusId("111"), "hoge"));
-            history.AddLast();
+            history.AddLast("@hoge aaa", (new TwitterStatusId("111"), "hoge"));
             Assert.Equal(2, history.Items.Count);
             Assert.Equal(new("@hoge aaa", (new TwitterStatusId("111"), "hoge")), history.Items[0]);
             Assert.Equal(new("", null), history.Items[1]);
@@ -106,8 +103,7 @@ namespace OpenTween.Models
         public void Peek_HasItemsTest()
         {
             var history = new StatusTextHistory();
-            history.SetLastItem("@hoge aaa", (new TwitterStatusId("111"), "hoge"));
-            history.AddLast();
+            history.AddLast("@hoge aaa", (new TwitterStatusId("111"), "hoge"));
 
             Assert.Equal(new("@hoge aaa", (new TwitterStatusId("111"), "hoge")), history.Peek());
         }
index ec1d8fe..f84c66d 100644 (file)
@@ -68,11 +68,10 @@ namespace OpenTween.Models
             return this.items[this.historyIndex];
         }
 
-        public void SetLastItem(string text, (PostId StatusId, string ScreenName)? inReplyTo)
-            => this.items[this.items.Count - 1] = new(text, inReplyTo);
-
-        public void AddLast()
+        public void AddLast(string text, (PostId StatusId, string ScreenName)? inReplyTo)
         {
+            this.items[this.items.Count - 1] = new(text, inReplyTo);
+
             this.items.Add(new(""));
             this.historyIndex = this.items.Count - 1;
         }
index 7d924e3..51974e0 100644 (file)
@@ -1140,8 +1140,6 @@ namespace OpenTween
                     return;
             }
 
-            this.history.SetLastItem(this.StatusText.Text, this.inReplyTo);
-
             if (this.settings.Common.Nicoms)
             {
                 this.StatusText.SelectionStart = this.StatusText.Text.Length;
@@ -1201,9 +1199,10 @@ namespace OpenTween
                 uploadService = this.ImageSelector.Model.GetService(serviceName);
             }
 
+            this.history.AddLast(this.StatusText.Text, this.inReplyTo);
+
             this.inReplyTo = null;
             this.StatusText.Text = "";
-            this.history.AddLast();
             if (!this.settings.Common.FocusLockToStatusText)
                 this.CurrentListView.Focus();
             this.urlUndoBuffer = null;