Find and Replace Functionality
This PR adds simple search and replace functions.
The first one, searchAndReplace, can replace all occurrences of a search term across the workspace. The second, replaceRange, lets you replace text in a specific range within a file. Depending on the range, it's useful for replacing a single term in a file or even within a function.
Additional Improvements
- Implement visual feedback in the Find Navigator to display current states such as 'Searching...', 'Replacing...', 'Found...', and 'Failed,' in compliance with Apple's human interface guidelines: Apple suggests using visual feedback to acknowledge user input and provide a clear indication that an action is taking place.
- Remove duplicate 'Match Whole Word' option from the search text field
- Fix bug preventing proper functionality of search options such as 'Match Word,' 'Starting with,' and 'Ending with'.
Related Issues
- closes #1466
Checklist
- [x] I read and understood the contributing guide as well as the code of conduct
- [x] The issues this PR addresses are related to each other
- [x] My changes generate no new warnings
- [x] My code builds and runs on my machine
- [x] My changes are all related to the related issue above
- [x] I documented my code
- [x] Performance improvements
- [x] Write some tests
- [x] Indexing
- [x] testAddProjectToIndex()
- [x] Find
- [x] testSearch()
- [x] testSearchWithOptionContaining()
- [x] testSearchWithOptionMatchingWord()
- [x] testSearchWithOptionStartingWith()
- [x] testSearchWithOptionEndingWith()
- [x] testSearchWithOptionCaseSensitive() ~~- [ ] testSearchWithOptionRegularExpression()~~
- [x] Find And Replace
- [x] testFindAndReplace()
- [x] testFindAndReplaceWithOptionContaining()
- [x] testFindAndReplaceWithOptionMatchingWord()
- [x] testFindAndReplaceWithOptionStartingWith()
- [x] testFindAndReplaceWithOptionEndingWith() ~~- [ ] testFindAndReplaceWithOptionRegularExpression()~~
- [x] Indexing
Screenshots
I might use checkmark.circle.fill instead of checkmark.diamond.fill. I believe diamond symbols in Xcode usually indicates tests. We should also replace searching... with a spinner indicator.
What is the difference between No Results, and An Error Occurred? The subtitle is very similar. I might also look into which symbols are being used here as well.
I've changed the symbol and added a ProgressView().
For folks who missed the meetup: I wanted to highlight the difference between an unsuccessful search and a unsuccessful find-and-replace.
https://github.com/CodeEditApp/CodeEdit/assets/83090745/4e781778-e825-4427-8d90-51067c926d92
For reviewers: The existing search and Find And Replace algorithm lacks real-time progress visibility for users, meaning it doesn't promptly display the found files or terms that have been replaced. I already have plans for an upcoming pull request where the results will be delivered incrementally (the result will be returned in chunks).