-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
base: master
Are you sure you want to change the base?
Conversation
Personally, I'd add 3 checkboxes instead like in JetBrains IDEs:
By default, all 3 are checked. |
12ed2f8
to
4d8a51e
Compare
int end = from; | ||
|
||
if (ignore_comments) { | ||
if (line.begins_with("#")) { |
There was a problem hiding this comment.
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("#")) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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"}
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
This implementation seems GDScript-specific. Is this a problem? (edit: I actually don't think it's a problem for 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 The GDScriptLanguage singleton also has |
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
|
This comment was marked as duplicate.
This comment was marked as duplicate.
There was a problem hiding this 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
This PR add a new checkbox to find tool to allow ignoring comments
2022-10-24.08-33-17.mp4