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

Add "Ignore Comments" option to Find & Replace #67796

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nonunknown
Copy link
Contributor

@nonunknown nonunknown commented Oct 23, 2022

This PR add a new checkbox to find tool to allow ignoring comments

2022-10-24.08-33-17.mp4

@Calinou
Copy link
Member

Calinou commented Oct 23, 2022

Personally, I'd add 3 checkboxes instead like in JetBrains IDEs:

Search in:   [x] Code   [x] Comments   [x] Strings

By default, all 3 are checked.

@nonunknown nonunknown changed the title W.I.P - Allow ignore comments on search Add "Ignore Comments" option to Find & Replace Oct 24, 2022
@nonunknown nonunknown marked this pull request as ready for review October 24, 2022 11:40
@nonunknown nonunknown requested review from a team as code owners October 24, 2022 11:40
int end = from;

if (ignore_comments) {
if (line.begins_with("#")) {
Copy link
Contributor

@alfredbaudisch alfredbaudisch Oct 24, 2022

Choose a reason for hiding this comment

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

This is still a problem, after you updated the commit, it only matches if the line has no tabbing.
Searching "clicked" correctly ignores the comment here:

func clicked():
	print("Clicked!")
# clicked

But not here:

func clicked():
	print("Clicked!")
	# clicked

line is not being stripped out of tabs before the check.

@@ -4000,6 +4000,11 @@ Point2i TextEdit::search(const String &p_key, uint32_t p_search_flags, int p_fro
int last_pos = -1;

while (true) {
if (p_search_flags & SEARCH_IGNORE_COMMENTS) {
if (text_line.begins_with("#")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The same as my other comment regarding \t

Copy link
Contributor

Choose a reason for hiding this comment

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

Debug dump

text_line = {String} U"\t# clicked"
 _cowdata = {CowData<char32_t>} {_ptr=0x0000026460c04320 U"\t# clicked"}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm need to find a way to remove \t's

Copy link
Contributor Author

Choose a reason for hiding this comment

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

also there's a case where the comment can be in front of the code, so I need to modify the text_line var to remove that comment!

@MewPurPur
Copy link
Contributor

MewPurPur commented Oct 24, 2022

This implementation seems GDScript-specific. Is this a problem? (edit: I actually don't think it's a problem for code_editor)

Suppose it's not, other than comments appended by whitespace, as a review suggested, inline comments also wouldn't be caught. You can catch them by doing line_text = line_text.get_slice('#', 0); before everything.

The GDScriptLanguage singleton also has get_comment_delimiters and get_string_delimiters functions BTW.

@nonunknown
Copy link
Contributor Author

nonunknown commented Oct 24, 2022

can someone help me covers those 3 use cases to fix this pr? I did the code in gdscript so I can convert to c++ later on

extends Control


# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	var full_line := "\t\t# this is a comment"
	var end_of_line := "var t = 10 # number 10"
	var middle_of_line := "var string = \"#hello world\" # another comment"
	
	print("expected: ->\"\"<- got: ", remove_comments(full_line))
	print("expected: ->var t = 10<- got: ", remove_comments(end_of_line))
	print("expected: ->var string = \"#hello world#\"<- got:  ", remove_comments(middle_of_line))
	
#	print("hellou world")
	pass # Replace with function body.

func remove_comments(line:String) -> String:

	print(line)
	line = line.strip_edges(true, true)
	
	# Covers full line comment
	if (line.begins_with("#")): 
		return ""
	
	return line

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
	pass

@nonunknown nonunknown marked this pull request as draft October 24, 2022 14:14
@nonunknown nonunknown marked this pull request as ready for review October 24, 2022 14:21
@MewPurPur

This comment was marked as duplicate.

Copy link
Member

@Paulb23 Paulb23 left a comment

Choose a reason for hiding this comment

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

This needs to be language agnostic and TextEdit in particular should have no coding concept such as comments.

I would recommend taking a look into using CodeEdit::is_in_comment

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

Successfully merging this pull request may close these issues.

8 participants