From 66445a117fc35342fed64405d23f559a086516bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20B=C3=BCchel?= Date: Tue, 31 May 2022 12:34:01 +0200 Subject: [PATCH] SEBWIN-568: Implemented functionality to automatically reperform text search on browser navigation or reload. --- SafeExamBrowser.Browser/BrowserWindow.cs | 17 +++++++++++++++++ .../Windows/BrowserWindow.xaml.cs | 6 ++++-- .../Windows/BrowserWindow.xaml.cs | 6 ++++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/SafeExamBrowser.Browser/BrowserWindow.cs b/SafeExamBrowser.Browser/BrowserWindow.cs index 33a5ee16..0985eedf 100644 --- a/SafeExamBrowser.Browser/BrowserWindow.cs +++ b/SafeExamBrowser.Browser/BrowserWindow.cs @@ -44,6 +44,7 @@ namespace SafeExamBrowser.Browser { internal class BrowserWindow : IApplicationWindow { + private const string CLEAR_FIND_TERM = "thisisahacktoclearthesearchresultsasitappearsthatthereisnosuchfunctionalityincef"; private const double ZOOM_FACTOR = 0.2; private readonly AppConfig appConfig; @@ -60,6 +61,7 @@ namespace SafeExamBrowser.Browser private readonly IText text; private readonly IUserInterfaceFactory uiFactory; + private (string term, bool isInitial, bool caseSensitive, bool forward) findParameters; private IBrowserWindow window; private double zoomLevel; @@ -278,6 +280,8 @@ namespace SafeExamBrowser.Browser window.UpdateTitle(address); TitleChanged?.Invoke(address); } + + AutoFind(); } private void Control_LoadFailed(int errorCode, string errorText, bool isMainRequest, string url) @@ -715,6 +719,11 @@ namespace SafeExamBrowser.Browser { if (settings.AllowFind) { + findParameters.caseSensitive = caseSensitive; + findParameters.forward = forward; + findParameters.isInitial = isInitial; + findParameters.term = term; + Control.Find(term, isInitial, caseSensitive, forward); } } @@ -763,6 +772,14 @@ namespace SafeExamBrowser.Browser } } + private void AutoFind() + { + if (settings.AllowFind && !string.IsNullOrEmpty(findParameters.term) && !CLEAR_FIND_TERM.Equals(findParameters.term, StringComparison.OrdinalIgnoreCase)) + { + Control.Find(findParameters.term, findParameters.isInitial, findParameters.caseSensitive, findParameters.forward); + } + } + private double CalculateZoomPercentage() { return (zoomLevel * 25.0) + 100.0; diff --git a/SafeExamBrowser.UserInterface.Desktop/Windows/BrowserWindow.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Windows/BrowserWindow.xaml.cs index fbde4baf..45d07e82 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Windows/BrowserWindow.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Windows/BrowserWindow.xaml.cs @@ -33,6 +33,8 @@ namespace SafeExamBrowser.UserInterface.Desktop.Windows { internal partial class BrowserWindow : Window, IBrowserWindow { + private const string CLEAR_FIND_TERM = "thisisahacktoclearthesearchresultsasitappearsthatthereisnosuchfunctionalityincef"; + private readonly bool isMainWindow; private readonly BrowserSettings settings; private readonly IText text; @@ -330,7 +332,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Windows private void FindbarCloseButton_Click(object sender, RoutedEventArgs e) { - FindRequested?.Invoke("thisisahacktoclearthesearchresultsasitappearsthatthereisnosuchfunctionalityincef", true, false); + FindRequested?.Invoke(CLEAR_FIND_TERM, true, false); Findbar.Visibility = Visibility.Collapsed; } @@ -348,7 +350,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Windows { if (string.IsNullOrEmpty(FindTextBox.Text)) { - FindRequested?.Invoke("thisisahacktoclearthesearchresultsasitappearsthatthereisnosuchfunctionalityincef", true, false); + FindRequested?.Invoke(CLEAR_FIND_TERM, true, false); } else { diff --git a/SafeExamBrowser.UserInterface.Mobile/Windows/BrowserWindow.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Windows/BrowserWindow.xaml.cs index 5569fb06..9efbbc72 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Windows/BrowserWindow.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Windows/BrowserWindow.xaml.cs @@ -32,6 +32,8 @@ namespace SafeExamBrowser.UserInterface.Mobile.Windows { internal partial class BrowserWindow : Window, IBrowserWindow { + private const string CLEAR_FIND_TERM = "thisisahacktoclearthesearchresultsasitappearsthatthereisnosuchfunctionalityincef"; + private readonly bool isMainWindow; private readonly ILogger logger; private readonly BrowserSettings settings; @@ -234,7 +236,7 @@ namespace SafeExamBrowser.UserInterface.Mobile.Windows private void FindbarCloseButton_Click(object sender, RoutedEventArgs e) { - FindRequested?.Invoke("thisisahacktoclearthesearchresultsasitappearsthatthereisnosuchfunctionalityincef", true, false); + FindRequested?.Invoke(CLEAR_FIND_TERM, true, false); Findbar.Visibility = Visibility.Collapsed; } @@ -252,7 +254,7 @@ namespace SafeExamBrowser.UserInterface.Mobile.Windows { if (string.IsNullOrEmpty(FindTextBox.Text)) { - FindRequested?.Invoke("thisisahacktoclearthesearchresultsasitappearsthatthereisnosuchfunctionalityincef", true, false); + FindRequested?.Invoke(CLEAR_FIND_TERM, true, false); } else {