Terminal.Gui icon indicating copy to clipboard operation
Terminal.Gui copied to clipboard

`TextFormatter.WordWrapText` with `preserveTrailingSpaces = false` is not working

Open tig opened this issue 2 years ago • 4 comments

Looks like none of the existing unit tests actually test if preserveTrailingSpaces is false.

This test proves that it's not working correctly:

		[Fact, AutoInitShutdown]
		public void WordWrap_PreserveTrailingSpaces_Horizontal_With_Simple_Runes ()
		{
			var text = "A sentence has words. ";
			var width = 3;
			var wrappedLines = TextFormatter.WordWrapText (text, width, preserveTrailingSpaces: true);
			var breakLines = "";
			foreach (var line in wrappedLines) {
				breakLines += $"{line}{Environment.NewLine}";
			}
			var expected = "A " + Environment.NewLine +
					"sen" + Environment.NewLine +
					"ten" + Environment.NewLine +
					"ce " + Environment.NewLine +
					"has" + Environment.NewLine +
					" " + Environment.NewLine +
					"wor" + Environment.NewLine +
					"ds." + Environment.NewLine +
					" " + Environment.NewLine;
			Assert.Equal (expected, breakLines);

			wrappedLines = TextFormatter.WordWrapText (text, width, preserveTrailingSpaces: false);
			foreach (var line in wrappedLines) {
				breakLines += $"{line}{Environment.NewLine}";
			}
			expected = "A s" + Environment.NewLine +
					"ent" + Environment.NewLine +
					"enc" + Environment.NewLine +
					"e h" + Environment.NewLine +
					"as" + Environment.NewLine +
					"wor" + Environment.NewLine +
					"ds." + Environment.NewLine;
			Assert.Equal (expected, breakLines);
		}

tig avatar Apr 09 '23 09:04 tig

Nevermind.

tig avatar Apr 10 '23 03:04 tig

Unfortunately this isn't working again when WordWrap is false. I even had created a unit test before to this doesn't happens again but it seems that the were changed because the tests is passing.

messagebox-wordwrap-false

BDisp avatar Apr 24 '23 13:04 BDisp

https://github.com/gui-cs/Terminal.Gui/blob/f280ded14521268942abc5f0c9b832226d2ff099/Terminal.Gui/Views/MessageBox.cs#L297-L298

@tig I really don't understand what you want doing here. TextFormatter doesn't rely on View, so it's the MessageBox who have to provide the necessary width and height for the Dialog dependent if wrapMessage is true or not. How the TextFormatter will resize the view based on the TextFormatter.WordWrap property? If you have a great idea I'm curious. Otherwise I see that much of the code (#2405) I did before was deleted, so I'll give up on this.

BDisp avatar Apr 24 '23 13:04 BDisp

I'll look at this later and try to fix this. Sorry about screwing this up.

tig avatar Apr 25 '23 13:04 tig