From 3d4312f85ef6867541fcce0458ee060d398f474a Mon Sep 17 00:00:00 2001 From: James Holderness Date: Mon, 14 Oct 2019 23:43:48 +0100 Subject: [PATCH 1/5] Prevent the TAB control from wrapping onto a new line when it reaches the end of a line. --- src/host/screenInfo.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/host/screenInfo.cpp b/src/host/screenInfo.cpp index ec384715803..6d74214b38d 100644 --- a/src/host/screenInfo.cpp +++ b/src/host/screenInfo.cpp @@ -2219,12 +2219,7 @@ COORD SCREEN_INFORMATION::GetForwardTab(const COORD cCurrCursorPos) const noexce { COORD cNewCursorPos = cCurrCursorPos; SHORT sWidth = GetBufferSize().RightInclusive(); - if (cCurrCursorPos.X == sWidth) - { - cNewCursorPos.X = 0; - cNewCursorPos.Y += 1; - } - else if (_tabStops.empty() || cCurrCursorPos.X >= _tabStops.back()) + if (_tabStops.empty() || cCurrCursorPos.X >= _tabStops.back()) { cNewCursorPos.X = sWidth; } From 02fe5f06f8bea74cec44704e024cd2dda1733e7d Mon Sep 17 00:00:00 2001 From: James Holderness Date: Tue, 15 Oct 2019 00:13:45 +0100 Subject: [PATCH 2/5] Add another TestGetForwardTab test to make sure tabs don't wrap at the end of a line. --- src/host/ut_host/ScreenBufferTests.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/host/ut_host/ScreenBufferTests.cpp b/src/host/ut_host/ScreenBufferTests.cpp index 3281c08543c..40a9d176b99 100644 --- a/src/host/ut_host/ScreenBufferTests.cpp +++ b/src/host/ut_host/ScreenBufferTests.cpp @@ -597,6 +597,19 @@ void ScreenBufferTests::TestGetForwardTab() L"Cursor advanced to end of screen buffer."); } + Log::Comment(L"Find next tab from rightmost column."); + { + coordCursor.X = coordScreenBufferSize.X - 1; + + COORD coordCursorExpected; + coordCursorExpected = coordCursor; + + COORD const coordCursorResult = si.GetForwardTab(coordCursor); + VERIFY_ARE_EQUAL(coordCursorExpected, + coordCursorResult, + L"Cursor remains in rightmost column."); + } + si._tabStops.clear(); } From ed05a23ecdd9815b371ddb5e5f9eeed3a76681da Mon Sep 17 00:00:00 2001 From: James Holderness Date: Tue, 15 Oct 2019 01:27:58 +0100 Subject: [PATCH 3/5] Optimize the DoPrivateTabHelper implementation so it only makes a single call to AdjustCursorPosition. --- src/host/getset.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/host/getset.cpp b/src/host/getset.cpp index 6d979633b56..001fdf3e37f 100644 --- a/src/host/getset.cpp +++ b/src/host/getset.cpp @@ -1567,19 +1567,15 @@ void DoSrvPrivateUseMainScreenBuffer(SCREEN_INFORMATION& screenInfo) { CONSOLE_INFORMATION& gci = ServiceLocator::LocateGlobals().getConsoleInformation(); SCREEN_INFORMATION& _screenBuffer = gci.GetActiveOutputBuffer().GetActiveBuffer(); + COORD cursorPos = _screenBuffer.GetTextBuffer().GetCursor().GetPosition(); - NTSTATUS Status = STATUS_SUCCESS; FAIL_FAST_IF(!(sNumTabs >= 0)); - for (SHORT sTabsExecuted = 0; sTabsExecuted < sNumTabs && NT_SUCCESS(Status); sTabsExecuted++) + for (SHORT sTabsExecuted = 0; sTabsExecuted < sNumTabs; sTabsExecuted++) { - const COORD cursorPos = _screenBuffer.GetTextBuffer().GetCursor().GetPosition(); - COORD cNewPos = (fForward) ? _screenBuffer.GetForwardTab(cursorPos) : _screenBuffer.GetReverseTab(cursorPos); - // GetForwardTab is smart enough to move the cursor to the next line if - // it's at the end of the current one already. AdjustCursorPos shouldn't - // to be doing anything funny, just moving the cursor to the location GetForwardTab returns - Status = AdjustCursorPosition(_screenBuffer, cNewPos, TRUE, nullptr); + cursorPos = (fForward) ? _screenBuffer.GetForwardTab(cursorPos) : _screenBuffer.GetReverseTab(cursorPos); } - return Status; + + return AdjustCursorPosition(_screenBuffer, cursorPos, TRUE, nullptr); } // Routine Description: From 9b8ce5f5c764d019b05339c1097248d59231bfc5 Mon Sep 17 00:00:00 2001 From: James Holderness Date: Tue, 15 Oct 2019 01:36:56 +0100 Subject: [PATCH 4/5] Remove misleading comment. --- src/host/_stream.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/host/_stream.cpp b/src/host/_stream.cpp index 94d4f7c74c3..5c23ef67ea6 100644 --- a/src/host/_stream.cpp +++ b/src/host/_stream.cpp @@ -744,7 +744,6 @@ using Microsoft::Console::VirtualTerminal::StateMachine; if (screenInfo.InVTMode()) { const COORD cCursorOld = cursor.GetPosition(); - // Get Forward tab handles tabbing past the end of the buffer CursorPosition = screenInfo.GetForwardTab(cCursorOld); } else From 6dae6b10fc794084a36776d6f33feaf9ff6a802c Mon Sep 17 00:00:00 2001 From: James Holderness Date: Wed, 23 Oct 2019 10:10:07 +0100 Subject: [PATCH 5/5] Make sure we can cope with tab stops that are greater than the buffer width. --- src/host/screenInfo.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/host/screenInfo.cpp b/src/host/screenInfo.cpp index 6d74214b38d..4ba22c90a70 100644 --- a/src/host/screenInfo.cpp +++ b/src/host/screenInfo.cpp @@ -2230,7 +2230,8 @@ COORD SCREEN_INFORMATION::GetForwardTab(const COORD cCurrCursorPos) const noexce { if (*it > cCurrCursorPos.X) { - cNewCursorPos.X = *it; + // make sure we don't exceed the width of the buffer + cNewCursorPos.X = std::min(*it, sWidth); break; } }