Skip to content

Commit 41a9784

Browse files
committed
switch by arrow keys and by mouse click should repel each other
1 parent 00a6100 commit 41a9784

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

QuickLook/ViewWindowManager.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ internal class ViewWindowManager : IDisposable
1717
private readonly MainWindowNoTransparent _viewWindowNoTransparent;
1818
private readonly MainWindowTransparent _viewWindowTransparentTransparent;
1919
private MainWindowTransparent _currentMainWindow;
20-
private long _lastSwitchTick;
2120

2221
private string _path = string.Empty;
2322

@@ -99,8 +98,6 @@ internal void ClosePreview()
9998

10099
private void TogglePreview()
101100
{
102-
_lastSwitchTick = DateTime.Now.Ticks;
103-
104101
if (_currentMainWindow.Visibility == Visibility.Visible)
105102
{
106103
ClosePreview();
@@ -117,23 +114,25 @@ private void SwitchPreview()
117114
if (_currentMainWindow.Visibility != Visibility.Visible)
118115
return;
119116

120-
_lastSwitchTick = DateTime.Now.Ticks;
117+
// if the switch has been done by SwitchPreviewRemoteInvoke, we'll not do anything
118+
var select = NativeMethods.QuickLook.GetCurrentSelection();
119+
if (_path == select)
120+
return;
121+
122+
_path = select;
121123

122-
_path = NativeMethods.QuickLook.GetCurrentSelection();
124+
Debug.WriteLine($"SwitchPreview: {_path}");
123125

124126
InvokeViewer();
125127
}
126128

127129
private void SwitchPreviewRemoteInvoke(HeartbeatEventArgs e)
128130
{
129-
// sleep for 0.6s
130-
if (e.InvokeTick - _lastSwitchTick < 0.6 * TimeSpan.TicksPerSecond)
131-
return;
132-
131+
// if the switch has been done by SwitchPreview, we'll not do anything
133132
if (e.FocusedFile == _path)
134133
return;
135134

136-
Debug.WriteLine("SwitchPreviewRemoteInvoke:" + (e.InvokeTick - _lastSwitchTick));
135+
Debug.WriteLine($"SwitchPreviewRemoteInvoke: {e.FocusedFile}");
137136

138137
if (string.IsNullOrEmpty(e.FocusedFile))
139138
return;

0 commit comments

Comments
 (0)