Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #This func is triggered by pressing "Find Next" in the Ctrl+F window
- func _on_find_next_pressed() -> void:
- const Post_Script = preload("res://Scripts/post_display.gd")
- #Grabbing the Search_Term the user typed in.
- Search_Term = $"CtrlF Menu/CtrlF Vertical/CtrlF LineEdit".text
- #Find_Results is a dictionary var I declare outside this func
- #This is what happens the first time Find Result is clicked, when the dict of results is empty
- if Find_Results == {} and Search_Term != "" and Search_Term.length() > 1:
- var dictionary_number = 1
- for post in $"ScrollContainer/Post Scroll".get_children():
- #This if statement filters out UI elements in Post Scroll that aren't true posts
- if post.get_script() == Post_Script:
- var positions = []
- var body = post.get_node("HBoxContainer/VBoxContainer2/Body")
- var match_position = body.text.findn(Search_Term)
- while match_position != -1:
- positions.append(match_position)
- var line_offset = body.get_line_offset(body.get_character_line(match_position))
- var post_scroll = $"ScrollContainer/Post Scroll"
- var body_offset_in_scroll = body.global_position.y - post_scroll.global_position.y
- match_position = body.text.findn(Search_Term, match_position + Search_Term.length())
- var match_scroll_position = int(body_offset_in_scroll + line_offset)
- Find_Results[dictionary_number] = match_scroll_position
- dictionary_number += 1
- positions.reverse()
- #This is where I add in the bgcolor tags, the part that breaks the "img" bbcode tags.
- for textposition in positions:
- body.text = body.text.insert(textposition + Search_Term.length(), "[/bgcolor]")
- body.text = body.text.insert(textposition, "[bgcolor=orange]")
- #Jumps to the scroll position of the first search result.
- if Find_Results != {}:
- $ScrollContainer.set_deferred("scroll_vertical", Find_Results[1] - 520)
- Last_Find_Result = 1
- #This is what happens if Find Result is clicked a second time in a row, jumping scroll positions
- #Including this for completeness but I don't think it's relevant to the phenomenon I'm looking into
- else:
- for key in Find_Results:
- if Find_Results[key] > ($ScrollContainer.scroll_vertical + 520):
- $ScrollContainer.set_deferred("scroll_vertical", Find_Results[key] - 520)
- Last_Find_Result = key
- print("stored: ", Find_Results[key])
- print("scroll: ", $ScrollContainer.scroll_vertical)
- print("comparison position: ", $ScrollContainer.scroll_vertical + 520)
- break
- elif Find_Results[key] == ($ScrollContainer.scroll_vertical + 520) and key > Last_Find_Result:
- Last_Find_Result = key
- $ScrollContainer.set_deferred("scroll_vertical", Find_Results[key] - 520)
- print("stored: ", Find_Results[key])
- print("scroll: ", $ScrollContainer.scroll_vertical)
- print("comparison position: ", $ScrollContainer.scroll_vertical + 520)
- break
- #This func is triggered by exiting the Ctrl+F window
- func _on_exit_pressed() -> void:
- $"CtrlF Menu".visible = false
- Find_Results.clear()
- const Post_Script = preload("res://Scripts/post_display.gd")
- for post in $"ScrollContainer/Post Scroll".get_children():
- #This if statement filters out UI elements in Post Scroll that aren't true posts
- if post.get_script() == Post_Script:
- var body = post.get_node("HBoxContainer/VBoxContainer2/Body")
- #All bgcolor tags are stripped back out of the posts, returning them to their original states
- body.text = body.text.replace("[/bgcolor]", "")
- body.text = body.text.replace("[bgcolor=orange]", "")
Advertisement
Add Comment
Please, Sign In to add comment