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

improv: Added multiline search/replace and fixed various crashes. #1911

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

paxcut
Copy link
Contributor

@paxcut paxcut commented Sep 20, 2024

Problem description

Previous implementation ignored everything after the first newline. Other changes include:

  • Added isEmpty() function that checks if editor has no content.
  • replaced asserts with default behavior to avoid unneeded crashes.
  • fixed off by one error in DeleteRange()
  • some crashes occurred because readily available corrective actions were not being taken. For example start/end being -1 in DeleteRange().
  • At the heart of search/replace is the ability to translate from indices into the text string to line/column coordinates used for everything. To this end a function (StringIndexToCoordinates) was added to do the translation taking utf-8 chars into account. This made the recently added Utf8BytesToChars function unneeded, so it was removed.
  • Removed commented out code that is not useful anymore. Also removed tooltip code which is also unused.
  • Removed unused parameter wrapAround to FindNext().

paxcut and others added 3 commits September 20, 2024 03:04
Previous implementation ignored everything after the first newline.
Other changes include:
- Added isEmpty() function that checks if editor has no content.
- replaced asserts with default behavior to avoid unneeded crashes.
- fixed off by one error in DeleteRange()
- some crashes occurred because readily available corrective actions were not being taken. For example start/end being -1 in DeleteRange().
- At the heart of search/replace is the ability to translate from indices into the text string to line/column coordinates used for everything. To this end a function (StringIndexToCoordinates) was added to do the translation taking utf-8 chars into account. This made the recently added Utf8BytesToChars function unneeded, so it was removed.
- Removed commented out code that is not useful anymore. Also removed tooltip code which is also unused.
- Removed unused parameter wrapAround to FindNext().
if (mTopMargin != oldTopMargin) {
static float savedScrollY = 0;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using static here will most likely not going to work correctly if there's multiple editors shown on-screen. Move these to be member variables of the TextEditor class

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still problematic. Besides this, the PR looks good

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I posted an explanation as to why they are ok as static but now i dont see it anymore. I guess i don't really know how to use this user interface. so i'll try just this now.

Copy link
Contributor Author

@paxcut paxcut Nov 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see if i press resolve conversation is erases the comment? thats weird. Anyway ...

The code in question is the one responsible for having the find-replace popup behave like vscode. When using find-replace popup one may open the window as Find, expand it to Replace, shrink it back to Find and close the window. Through those event the variables cycle through 2 or 3 values which are always the same.
Because the window is a popup whenever it is opened for one editor it must be closed before other editors can get focus so the variables will always be reinitialized in the complete open-close cycle so the variables can't be used by several editors at the same time. Being static makes the code simpler as the variables are initialized once and then keep their values between calls. It is impossible to have more than one search-replace window opened so it should be safe to use static variables.

If after reading this you still have issues I can look into converting them to non-static, but the simple naive change that I first tried broke the popup in away that empty lines are added at the end of the file when the popup was opened and then closed. I tested it in every way I can't think and besides an unavoidable artifact when the end of the file is in view when the window is opened it works as expected. The artifact is a consequence of how the maximum scroll value works.

@paxcut paxcut requested a review from WerWolv November 24, 2024 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants