Skip to content

Add standard text search and replace#2559

Merged
gsantner merged 98 commits intogsantner:masterfrom
guanglinn:search_improvement
Mar 6, 2026
Merged

Add standard text search and replace#2559
gsantner merged 98 commits intogsantner:masterfrom
guanglinn:search_improvement

Conversation

@guanglinn
Copy link
Copy Markdown
Contributor

@guanglinn guanglinn commented Apr 7, 2025

This PR makes Markor support standard text search and replace that are widely adopted by most text editors.

Related Issues:

#2164 - Show search as find in page, not in a popup

#2341 - Highlight in-search results

#2582 - Markor search jumps not to exact finding position

Supported features are as follows:

  1. Standard UI for text find & replace

  2. Highlight all matches/occurrences

  3. Highlight current active match

  4. Jump to previous/next match

  5. Match case

  6. Match whole word

  7. Use regular expression

  8. Find in selection

  9. Replace once

  10. Replace all

  11. Preserve case when replacing

  12. Toggle to line based text search

@guanglinn
Copy link
Copy Markdown
Contributor Author

guanglinn commented Apr 7, 2025

Screenshot

Screenshot_20250411-080021_Marder.png

@guanglinn guanglinn changed the title Add support for normal/standard text find and replace Add support for normal text find and replace Apr 7, 2025
Comment thread app/src/main/java/net/gsantner/markor/frontend/search/Occurrence.java Outdated
@guanglinn guanglinn changed the title Add support for normal text find and replace Add normal text find and replace Apr 9, 2025
@gsantner
Copy link
Copy Markdown
Owner

gsantner commented Apr 14, 2025

Thanks for working on this and the screenshot! To me at least it looks quite complicated at first, user will next ask where can I replace only this highlighted one? Where can I replace all? Thats the two most important buttons to be easy recognizable

@guanglinn
Copy link
Copy Markdown
Contributor Author

guanglinn commented Apr 14, 2025

User will next ask where can I replace only this highlighted one?
Where can I replace all?

These two features have already been implemented in this PR, and these two buttons can popup tool tips, users can easily recognize it.

Comment thread app/src/main/res/xml/preferences_master.xml Outdated
@guanglinn
Copy link
Copy Markdown
Contributor Author

guanglinn commented Feb 6, 2026

I will check it, but it works well on my phone.

SVID_20260206_080628_1.mp4

@gsantner
Copy link
Copy Markdown
Owner

gsantner commented Feb 6, 2026

Guess it's also due multiline field there:

Is it intentionally multiline? I'm rather unfimilar with search/replace not being normal single text search+replace or regex search+replace

@gsantner
Copy link
Copy Markdown
Owner

gsantner commented Feb 6, 2026

A crash I could get, but thats not whats currently on the branch, I just tried with

                      android:inputType="text"
                        android:maxLines="1"
FATAL EXCEPTION: main
Process: net.gsantner.markor_test, PID: 10864
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.KeyEvent.getKeyCode()' on a null object reference
	at net.gsantner.markor.frontend.textsearch.TextSearchFragment.lambda$onViewCreated$3$net-gsantner-markor-frontend-textsearch-TextSearchFragment(TextSearchFragment.java:138)
	at net.gsantner.markor.frontend.textsearch.TextSearchFragment$$ExternalSyntheticLambda15.onEditorAction(D8$$SyntheticClass:0)
	at android.widget.TextView.onEditorAction(TextView.java:8333)
	at com.android.internal.inputmethod.EditableInputConnection.performEditorAction(EditableInputConnection.java:175)
	at android.view.inputmethod.InputConnectionWrapper.performEditorAction(InputConnectionWrapper.java:253)
	at android.view.inputmethod.RemoteInputConnectionImpl.lambda$performEditorAction$22(RemoteInputConnectionImpl.java:732)
	at android.view.inputmethod.RemoteInputConnectionImpl.$r8$lambda$Jl5UsxtFJ64KyE-rGTA_d_NwhC4(Unknown Source:0)
	at android.view.inputmethod.RemoteInputConnectionImpl$$ExternalSyntheticLambda33.run(D8$$SyntheticClass:0)
	at android.os.Handler.handleCallback(Handler.java:995)
	at android.os.Handler.dispatchMessage(Handler.java:103)
	at android.os.Looper.loopOnce(Looper.java:248)
	at android.os.Looper.loop(Looper.java:338)
	at android.app.ActivityThread.main(ActivityThread.java:9079)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:596)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:932)

@guanglinn
Copy link
Copy Markdown
Contributor Author

Hello, @gsantner
I have fixed all known issues. You can test it on your phone.

@gsantner gsantner force-pushed the master branch 3 times, most recently from d3c16f5 to c3bd617 Compare March 6, 2026 18:41
@gsantner gsantner merged commit 0837cd1 into gsantner:master Mar 6, 2026
1 check passed
@gsantner
Copy link
Copy Markdown
Owner

gsantner commented Mar 6, 2026

Thanks for creating this and working on it for quite some time. I merged it!

@gsantner gsantner added this to the Markor v2.16 milestone Mar 6, 2026
@guanglinn guanglinn deleted the search_improvement branch March 7, 2026 02:44
});

listView.setOnItemLongClickListener((parent, view, pos, id) -> directActivate.callback(pos, true));
// listView.setOnItemLongClickListener((parent, view, pos, id) -> directActivate.callback(pos, true));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@guanglinn

Why was this disabled?!

Long pressing was extremely useful and I had it set up for many actions.

For example:

  • Long press snippet to directly jump to and edit the snippet
  • Long press todo in the search field to directly jump to it
  • Long press context / project in the filtering dialogs to see them directly

All of these are now not working

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hi, @harshad1

I find it easy to trigger incorrect action by long pressing. For example, it may cause incorrect jumps due to unintentionally long pressing an item when you slide the TOC list, so I disabled it at that time.

I will revert it soon.

searchEditText.setTextColor(dopt.textColor);
searchEditText.setHintTextColor(ColorUtils.setAlphaComponent(dopt.textColor, 0x99));
searchEditText.setHint(dopt.searchHintText);
searchEditText.setText(dopt.searchText);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We have dopt.state.searchText

That is what should be set here. I am making the change in #2736

Copy link
Copy Markdown
Contributor Author

@guanglinn guanglinn Apr 8, 2026

Choose a reason for hiding this comment

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

The reason why I added searchEditText.setText(dopt.searchText) at that time is as follows:
Assuming you input a search text in search dialog, then you switch to replace dialog. dopt.searchText can keep search text from search dialog to replace dialog. This can avoid typing the same search text again.

Here is an example, see search text 'hello':

petal_20260408_233837.mp4

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yes. Setting state.searchText does that :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants