Skip to content

Commit

Permalink
Merge branch 'master' of github.com:mu-editor/mu
Browse files Browse the repository at this point in the history
  • Loading branch information
ntoll committed Jan 31, 2021
2 parents 195fcf8 + 4dc0a11 commit f11f797
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
6 changes: 3 additions & 3 deletions mu/interface/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down
20 changes: 18 additions & 2 deletions tests/interface/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
)


Expand All @@ -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
)


Expand Down

0 comments on commit f11f797

Please sign in to comment.