diff --git a/mu/interface/main.py b/mu/interface/main.py index 8c92e8214..2dcf8a8d9 100644 --- a/mu/interface/main.py +++ b/mu/interface/main.py @@ -1174,7 +1174,7 @@ def replace_text(self, target_text, replace, global_replace): if global_replace: counter = 0 found = self.current_tab.findFirst( - target_text, True, True, False, False, line=0, index=0 + target_text, False, True, False, False, line=0, index=0 ) if found: counter += 1 @@ -1185,7 +1185,7 @@ def replace_text(self, target_text, replace, global_replace): return counter else: found = self.current_tab.findFirst( - target_text, True, True, False, True + target_text, False, True, False, True ) if found: self.current_tab.replace(replace) @@ -1207,7 +1207,7 @@ def highlight_text(self, target_text, forward=True): line, index, _el, _ei = self.current_tab.getSelection() return self.current_tab.findFirst( target_text, # Text to find, - True, # Treat as regular expression + False, # Treat as regular expression True, # Case sensitive search False, # Whole word matches only True, # Wrap search diff --git a/tests/interface/test_main.py b/tests/interface/test_main.py index 42dff3832..b16e7b60f 100644 --- a/tests/interface/test_main.py +++ b/tests/interface/test_main.py @@ -1828,6 +1828,22 @@ def test_Window_replace_text_global_missing(): assert w.replace_text("foo", "bar", True) == 0 +def test_Window_replace_text_highlight_text_correct_selection(): + """ + Check that replace_text and highlight_text are actually highlighting text + without regex matching. + """ + view = mu.interface.main.Window() + text = "ofafefifoof." + tab = mu.interface.editor.EditorPane("path", text) + with mock.patch("mu.interface.Window.current_tab") as current: + current.findFirst = tab.findFirst + view.highlight_text("f.") + assert tab.selectedText() == "f." + assert view.replace_text("of.", "", False) + assert tab.selectedText() == "of." + + def test_Window_highlight_text(): """ Given target_text, highlights the first instance via Scintilla's findFirst @@ -1841,7 +1857,7 @@ def test_Window_highlight_text(): mock_tab.getSelection.return_value = 0, 0, 0, 0 assert w.highlight_text("foo") mock_tab.findFirst.assert_called_once_with( - "foo", True, True, False, True, forward=True, index=-1, line=-1 + "foo", False, True, False, True, forward=True, index=-1, line=-1 ) @@ -1858,7 +1874,7 @@ def test_Window_highlight_text_backward(): mock_tab.getSelection.return_value = 0, 0, 0, 0 assert w.highlight_text("foo", forward=False) mock_tab.findFirst.assert_called_once_with( - "foo", True, True, False, True, forward=False, index=0, line=0 + "foo", False, True, False, True, forward=False, index=0, line=0 )