Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Updates #52

Merged
merged 3 commits into from
Oct 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions nw/gui/doceditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ def _beginSearch(self):
def _beginReplace(self):
"""Opens the replace line of the search bar and sets the replace text.
"""
self._beginSearch()
self.theParent.searchBar.setReplaceText("")
return

Expand Down Expand Up @@ -536,16 +537,21 @@ def _replaceNext(self):
with the replace text. Wraps back to the top if not found.
"""
theCursor = self.textCursor()
searchFor = self.theParent.searchBar.getSearchText()
replWith = self.theParent.searchBar.getReplaceText()
if theCursor.hasSelection():
if theCursor.hasSelection() and theCursor.selectedText() == searchFor:
xPos = theCursor.selectionStart()
theCursor.beginEditBlock()
theCursor.removeSelectedText()
theCursor.insertText(replWith)
theCursor.endEditBlock()
theCursor.setPosition(xPos)
self.setTextCursor(theCursor)
self._findNext()
logger.verbose("Replaced occurrence of '%s' with '%s' on line %d" % (
searchFor, replWith, theCursor.blockNumber()
))
if searchFor != "":
self._findNext()
return

# END Class GuiDocEditor
6 changes: 1 addition & 5 deletions nw/gui/searchbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,11 @@ def __init__(self, theParent):
##

def setSearchText(self, theText):

if not self.isVisible():
self.setVisible(True)

self.searchBox.setText(theText)
self.searchBox.setFocus(True)

logger.debug("Setting search text to '%s'" % theText)

logger.verbose("Setting search text to '%s'" % theText)
return True

def setReplaceText(self, theText):
Expand Down