diff --git a/.github/actions/spell-check/expect.txt b/.github/actions/spell-check/expect.txt
index 4dd0018f68..33c5b20c01 100644
--- a/.github/actions/spell-check/expect.txt
+++ b/.github/actions/spell-check/expect.txt
@@ -149,6 +149,7 @@ Cangjie
CANRENAME
CAPTUREBLT
CAPTURECHANGED
+CARETBLINKING
CAtl
cch
CCHDEVICENAME
diff --git a/src/modules/peek/Peek.UI/Helpers/FileExplorerHelper.cs b/src/modules/peek/Peek.UI/Helpers/FileExplorerHelper.cs
index 2c3931c218..763ba94532 100644
--- a/src/modules/peek/Peek.UI/Helpers/FileExplorerHelper.cs
+++ b/src/modules/peek/Peek.UI/Helpers/FileExplorerHelper.cs
@@ -3,12 +3,14 @@
// See the LICENSE file in the project root for more information.
using System;
+using System.Runtime.InteropServices;
using Peek.Common.Models;
using Peek.UI.Extensions;
using SHDocVw;
using Windows.Win32;
using Windows.Win32.Foundation;
using Windows.Win32.UI.Shell;
+using Windows.Win32.UI.WindowsAndMessaging;
using IServiceProvider = Peek.Common.Models.IServiceProvider;
namespace Peek.UI.Helpers
@@ -27,7 +29,12 @@ namespace Peek.UI.Helpers
private static IShellItemArray? GetItemsInternal(HWND foregroundWindowHandle, bool onlySelectedFiles)
{
- if (foregroundWindowHandle.IsDesktopWindow())
+ // If the caret is visible, we assume the user is typing and we don't want to interfere with that
+ if (CaretVisible(foregroundWindowHandle))
+ {
+ return null;
+ }
+ else if (foregroundWindowHandle.IsDesktopWindow())
{
return GetItemsFromDesktop(foregroundWindowHandle, onlySelectedFiles);
}
@@ -104,5 +111,21 @@ namespace Peek.UI.Helpers
return null;
}
+
+ ///
+ /// Returns whether the caret is visible in the specified window.
+ ///
+ private static bool CaretVisible(HWND hwnd)
+ {
+ GUITHREADINFO guiThreadInfo = new() { cbSize = (uint)Marshal.SizeOf() };
+
+ // Get information for the foreground thread
+ if (PInvoke.GetGUIThreadInfo(0, ref guiThreadInfo))
+ {
+ return guiThreadInfo.hwndActive == hwnd && (guiThreadInfo.flags & GUITHREADINFO_FLAGS.GUI_CARETBLINKING) != 0;
+ }
+
+ return false;
+ }
}
}
diff --git a/src/modules/peek/Peek.UI/NativeMethods.txt b/src/modules/peek/Peek.UI/NativeMethods.txt
index e65e72c12f..102eaa1ebd 100644
--- a/src/modules/peek/Peek.UI/NativeMethods.txt
+++ b/src/modules/peek/Peek.UI/NativeMethods.txt
@@ -19,4 +19,5 @@ GetWindowRect
SET_WINDOW_POS_FLAGS
SetWindowPos
GetWindowPlacement
-SetWindowPlacement
\ No newline at end of file
+SetWindowPlacement
+GetGUIThreadInfo
\ No newline at end of file