Skip to content

Commit

Permalink
Merge branch 'main' into dev/migrie/b/13066-SW_FLASH-2
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed May 17, 2022
2 parents 50cd051 + e1086de commit f04b892
Show file tree
Hide file tree
Showing 25 changed files with 356 additions and 522 deletions.
5 changes: 5 additions & 0 deletions doc/cascadia/profiles.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1708,6 +1708,11 @@
"description": "Force the terminal to use the legacy input encoding. Certain keys in some applications may stop working when enabling this setting.",
"type": "boolean"
},
"experimental.useBackgroundImageForWindow": {
"default": false,
"description": "When set to true, the background image for the currently focused profile is expanded to encompass the entire window, beneath other panes.",
"type": "boolean"
},
"initialCols": {
"default": 120,
"description": "The number of columns displayed in the window upon first load. If \"launchMode\" is set to \"maximized\" (or \"maximizedFocus\"), this property is ignored.",
Expand Down
3 changes: 3 additions & 0 deletions src/cascadia/TerminalApp/Resources/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,9 @@
<data name="ExportSuccess" xml:space="preserve">
<value>Successfully exported terminal content</value>
</data>
<data name="FindText" xml:space="preserve">
<value>Find</value>
</data>
<data name="PlainText" xml:space="preserve">
<value>Plain Text</value>
</data>
Expand Down
10 changes: 10 additions & 0 deletions src/cascadia/TerminalApp/TabManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,16 @@ namespace winrt::TerminalApp::implementation
}
});

newTabImpl->FindRequested([weakTab, weakThis{ get_weak() }]() {
auto page{ weakThis.get() };
auto tab{ weakTab.get() };

if (page && tab)
{
page->_Find();
}
});

auto tabViewItem = newTabImpl->TabViewItem();
_tabView.TabItems().Append(tabViewItem);

Expand Down
20 changes: 19 additions & 1 deletion src/cascadia/TerminalApp/TerminalTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,23 @@ namespace winrt::TerminalApp::implementation
exportTabMenuItem.Icon(exportTabSymbol);
}

Controls::MenuFlyoutItem findMenuItem;
{
// "Split Tab"
Controls::FontIcon findSymbol;
findSymbol.FontFamily(Media::FontFamily{ L"Segoe Fluent Icons, Segoe MDL2 Assets" });
findSymbol.Glyph(L"\xF78B"); // SearchMedium

findMenuItem.Click([weakThis](auto&&, auto&&) {
if (auto tab{ weakThis.get() })
{
tab->_FindRequestedHandlers();
}
});
findMenuItem.Text(RS_(L"FindText"));
findMenuItem.Icon(findSymbol);
}

// Build the menu
Controls::MenuFlyout contextMenuFlyout;
Controls::MenuFlyoutSeparator menuSeparator;
Expand All @@ -1281,6 +1298,7 @@ namespace winrt::TerminalApp::implementation
contextMenuFlyout.Items().Append(duplicateTabMenuItem);
contextMenuFlyout.Items().Append(splitTabMenuItem);
contextMenuFlyout.Items().Append(exportTabMenuItem);
contextMenuFlyout.Items().Append(findMenuItem);
contextMenuFlyout.Items().Append(menuSeparator);

// GH#5750 - When the context menu is dismissed with ESC, toss the focus
Expand All @@ -1291,7 +1309,7 @@ namespace winrt::TerminalApp::implementation
// GH#10112 - if we're opening the tab renamer, don't
// immediately toss focus to the control. We don't want to steal
// focus from the tab renamer.
if (!tab->_headerControl.InRename())
if (!tab->_headerControl.InRename() && !tab->GetActiveTerminalControl().SearchBoxEditInFocus())
{
tab->_RequestFocusActiveControlHandlers();
}
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/TerminalTab.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ namespace winrt::TerminalApp::implementation
WINRT_CALLBACK(TabRaiseVisualBell, winrt::delegate<>);
WINRT_CALLBACK(DuplicateRequested, winrt::delegate<>);
WINRT_CALLBACK(SplitTabRequested, winrt::delegate<>);
WINRT_CALLBACK(FindRequested, winrt::delegate<>);
WINRT_CALLBACK(ExportTabRequested, winrt::delegate<>);
TYPED_EVENT(TaskbarProgressChanged, IInspectable, IInspectable);

Expand Down
14 changes: 14 additions & 0 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,20 @@ namespace winrt::Microsoft::Terminal::Control::implementation
}
}

// Method Description:
// Find if search box text edit currently is in focus
// Return Value:
// - true, if search box text edit is in focus
bool TermControl::SearchBoxEditInFocus() const
{
if (!_searchBox)
{
return false;
}

return _searchBox->TextBox().FocusState() == FocusState::Keyboard;
}

// Method Description:
// - Search text in text buffer. This is triggered if the user click
// search button or press enter.
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalControl/TermControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation

void SearchMatch(const bool goForward);

bool SearchBoxEditInFocus() const;

bool OnDirectKeyEvent(const uint32_t vkey, const uint8_t scanCode, const bool down);

bool OnMouseWheel(const Windows::Foundation::Point location, const int32_t delta, const bool leftButtonDown, const bool midButtonDown, const bool rightButtonDown);
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalControl/TermControl.idl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ namespace Microsoft.Terminal.Control
void ScrollViewport(Int32 viewTop);

void CreateSearchBoxControl();
Boolean SearchBoxEditInFocus();

void SearchMatch(Boolean goForward);

Expand Down
4 changes: 4 additions & 0 deletions src/host/getset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,10 @@ void ApiRoutines::GetLargestConsoleWindowSizeImpl(const SCREEN_INFORMATION& cont
position.Y < 0));
// clang-format on

// MSFT: 15813316 - Try to use this SetCursorPosition call to inherit the cursor position.
auto& gci = ServiceLocator::LocateGlobals().getConsoleInformation();
RETURN_IF_FAILED(gci.GetVtIo()->SetCursorPosition(position));

RETURN_IF_NTSTATUS_FAILED(buffer.SetCursorPosition(position, true));

LOG_IF_FAILED(ConsoleImeResizeCompStrView());
Expand Down
28 changes: 14 additions & 14 deletions src/inc/til/at.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,24 @@ namespace til
// gsl::at will do the check again. As will .at(). And using [] will have a warning in audit.
// This template is explicitly disabled if T is of type gsl::span, as it would interfere with
// the overload below.
template<class T, std::enable_if_t<!details::is_span<T>::value, int> = 0>
constexpr auto at(T& cont, const size_t i) -> decltype(cont[cont.size()])
template<typename T, typename I>
constexpr auto at(T&& cont, const I i) noexcept -> decltype(auto)
{
#pragma warning(suppress : 26482) // Suppress bounds.2 check for indexing with constant expressions
#pragma warning(suppress : 26446) // Suppress bounds.4 check for subscript operator.
#pragma warning(suppress : 26445) // Suppress lifetime check for a reference to gsl::span or std::string_view
return cont[i];
}

#ifdef GSL_SPAN_H
// This is an overload of til::at for span that access its backing buffer directly (UNCHECKED)
template<typename ElementType, size_t Extent>
constexpr auto at(gsl::span<ElementType, Extent> span, const std::ptrdiff_t i) -> decltype(span[span.size()])
{
if constexpr (details::is_span<T>::value)
{
#pragma warning(suppress : 26481) // Suppress bounds.1 check for doing pointer arithmetic
#pragma warning(suppress : 26482) // Suppress bounds.2 check for indexing with constant expressions
#pragma warning(suppress : 26446) // Suppress bounds.4 check for subscript operator.
return span.data()[i];
}
return cont.data()[i];
}
else
#endif
{
#pragma warning(suppress : 26482) // Suppress bounds.2 check for indexing with constant expressions
#pragma warning(suppress : 26446) // Suppress bounds.4 check for subscript operator.
#pragma warning(suppress : 26445) // Suppress lifetime check for a reference to gsl::span or std::string_view
return cont[i];
}
}
}
10 changes: 10 additions & 0 deletions src/inc/til/bit.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,20 @@

namespace til
{
// bit_cast is a backport of the STL's std::bit_cast to C++17.
template<class To, class From, std::enable_if_t<std::conjunction_v<std::bool_constant<sizeof(To) == sizeof(From)>, std::is_trivially_copyable<To>, std::is_trivially_copyable<From>>, int> = 0>
[[nodiscard]] constexpr To bit_cast(const From& _Val) noexcept
{
// TODO: Replace til::bit_cast and __builtin_bit_cast with std::bit_cast
return __builtin_bit_cast(To, _Val);
}

// When you cast a signed integer to an unsigned one, the compiler will use "sign extension"
// so that -1 translates to all bits being set, no matter the size of the target type.
// Sometimes you don't need or want that, which is when you can use this function.
template<typename T>
[[nodiscard]] constexpr auto as_unsigned(const T& v) noexcept
{
return bit_cast<std::make_unsigned_t<T>>(v);
}
}
8 changes: 7 additions & 1 deletion src/inc/til/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#pragma once

#include "bit.h"

namespace til
{
template<typename T>
Expand Down Expand Up @@ -129,7 +131,11 @@ namespace til
{
// This runs murmurhash3's finalizer (fmix32/fmix64) on a single integer.
// It's fast, public domain and produces good results.
auto h = static_cast<size_t>(v);
//
// Using til::as_unsigned here allows the compiler to drop the first
// `>> 33` mix for all Ts which are >= 32 bits.
// The existence of sign extension shouldn't change hash quality.
size_t h = til::as_unsigned(v);
if constexpr (sizeof(size_t) == 4)
{
h ^= h >> 16;
Expand Down
64 changes: 40 additions & 24 deletions src/inc/til/point.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned"
return __builtin_memcmp(this, &rhs, sizeof(rhs)) != 0;
}

constexpr explicit operator bool() const noexcept
{
return (x > 0) & (y > 0);
}

constexpr bool operator<(const point other) const noexcept
{
return y < other.y || (y == other.y && x < other.x);
Expand All @@ -87,71 +92,69 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned"

constexpr point operator+(const point other) const
{
return point{
details::extract(::base::CheckAdd(x, other.x)),
details::extract(::base::CheckAdd(y, other.y)),
};
auto copy = *this;
copy += other;
return copy;
}

constexpr point& operator+=(const point other)
{
*this = *this + other;
x = details::extract(::base::CheckAdd(x, other.x));
y = details::extract(::base::CheckAdd(y, other.y));
return *this;
}

constexpr point operator-(const point other) const
{
return point{
details::extract(::base::CheckSub(x, other.x)),
details::extract(::base::CheckSub(y, other.y)),
};
auto copy = *this;
copy -= other;
return copy;
}

constexpr point& operator-=(const point other)
{
*this = *this - other;
x = details::extract(::base::CheckSub(x, other.x));
y = details::extract(::base::CheckSub(y, other.y));
return *this;
}

constexpr point operator*(const point other) const
{
return point{
details::extract(::base::CheckMul(x, other.x)),
details::extract(::base::CheckMul(y, other.y)),
};
auto copy = *this;
copy *= other;
return copy;
}

constexpr point& operator*=(const point other)
{
*this = *this * other;
x = details::extract(::base::CheckMul(x, other.x));
y = details::extract(::base::CheckMul(y, other.y));
return *this;
}

constexpr point operator/(const point other) const
{
return point{
details::extract(::base::CheckDiv(x, other.x)),
details::extract(::base::CheckDiv(y, other.y)),
};
auto copy = *this;
copy /= other;
return copy;
}

constexpr point& operator/=(const point other)
{
*this = *this / other;
x = details::extract(::base::CheckDiv(x, other.x));
y = details::extract(::base::CheckDiv(y, other.y));
return *this;
}

template<typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
constexpr point operator*(const T scale) const
constexpr point operator*(const til::CoordType scale) const
{
return point{
details::extract(::base::CheckMul(x, scale)),
details::extract(::base::CheckMul(y, scale)),
};
}

template<typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
constexpr point operator/(const T scale) const
constexpr point operator/(const til::CoordType scale) const
{
return point{
details::extract(::base::CheckDiv(x, scale)),
Expand Down Expand Up @@ -193,6 +196,19 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned"
{
return { x, y };
}

// til::point and POINT have the exact same layout at the time of writing,
// so this function lets you unsafely "view" this point as a POINT
// if you need to pass it to a Win32 function.
//
// Use as_win32_point() as sparingly as possible because it'll be a pain to hack
// it out of this code base once til::point and POINT aren't the same anymore.
// Prefer casting to POINT and back to til::point instead if possible.
POINT* as_win32_point() noexcept
{
#pragma warning(suppress : 26490) // Don't use reinterpret_cast (type.1).
return std::launder(reinterpret_cast<POINT*>(this));
}
#endif

#ifdef DCOMMON_H_INCLUDED
Expand Down

0 comments on commit f04b892

Please sign in to comment.