Guest User

Untitled

a guest
Sep 9th, 2026
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.55 KB | None | 0 0
  1. #This func is triggered by pressing "Find Next" in the Ctrl+F window
  2. func _on_find_next_pressed() -> void:
  3. const Post_Script = preload("res://Scripts/post_display.gd")
  4.  
  5. #Grabbing the Search_Term the user typed in.
  6. Search_Term = $"CtrlF Menu/CtrlF Vertical/CtrlF LineEdit".text
  7.  
  8. #Find_Results is a dictionary var I declare outside this func
  9. #This is what happens the first time Find Result is clicked, when the dict of results is empty
  10. if Find_Results == {} and Search_Term != "" and Search_Term.length() > 1:
  11. var dictionary_number = 1
  12. for post in $"ScrollContainer/Post Scroll".get_children():
  13. #This if statement filters out UI elements in Post Scroll that aren't true posts
  14. if post.get_script() == Post_Script:
  15. var positions = []
  16. var body = post.get_node("HBoxContainer/VBoxContainer2/Body")
  17. var match_position = body.text.findn(Search_Term)
  18.  
  19. while match_position != -1:
  20. positions.append(match_position)
  21. var line_offset = body.get_line_offset(body.get_character_line(match_position))
  22. var post_scroll = $"ScrollContainer/Post Scroll"
  23. var body_offset_in_scroll = body.global_position.y - post_scroll.global_position.y
  24. match_position = body.text.findn(Search_Term, match_position + Search_Term.length())
  25. var match_scroll_position = int(body_offset_in_scroll + line_offset)
  26.  
  27. Find_Results[dictionary_number] = match_scroll_position
  28. dictionary_number += 1
  29.  
  30. positions.reverse()
  31.  
  32. #This is where I add in the bgcolor tags, the part that breaks the "img" bbcode tags.
  33. for textposition in positions:
  34. body.text = body.text.insert(textposition + Search_Term.length(), "[/bgcolor]")
  35. body.text = body.text.insert(textposition, "[bgcolor=orange]")
  36.  
  37. #Jumps to the scroll position of the first search result.
  38. if Find_Results != {}:
  39. $ScrollContainer.set_deferred("scroll_vertical", Find_Results[1] - 520)
  40. Last_Find_Result = 1
  41.  
  42. #This is what happens if Find Result is clicked a second time in a row, jumping scroll positions
  43. #Including this for completeness but I don't think it's relevant to the phenomenon I'm looking into
  44. else:
  45. for key in Find_Results:
  46. if Find_Results[key] > ($ScrollContainer.scroll_vertical + 520):
  47. $ScrollContainer.set_deferred("scroll_vertical", Find_Results[key] - 520)
  48. Last_Find_Result = key
  49. print("stored: ", Find_Results[key])
  50. print("scroll: ", $ScrollContainer.scroll_vertical)
  51. print("comparison position: ", $ScrollContainer.scroll_vertical + 520)
  52. break
  53. elif Find_Results[key] == ($ScrollContainer.scroll_vertical + 520) and key > Last_Find_Result:
  54. Last_Find_Result = key
  55. $ScrollContainer.set_deferred("scroll_vertical", Find_Results[key] - 520)
  56. print("stored: ", Find_Results[key])
  57. print("scroll: ", $ScrollContainer.scroll_vertical)
  58. print("comparison position: ", $ScrollContainer.scroll_vertical + 520)
  59. break
  60.  
  61. #This func is triggered by exiting the Ctrl+F window
  62. func _on_exit_pressed() -> void:
  63. $"CtrlF Menu".visible = false
  64. Find_Results.clear()
  65. const Post_Script = preload("res://Scripts/post_display.gd")
  66.  
  67. for post in $"ScrollContainer/Post Scroll".get_children():
  68. #This if statement filters out UI elements in Post Scroll that aren't true posts
  69. if post.get_script() == Post_Script:
  70. var body = post.get_node("HBoxContainer/VBoxContainer2/Body")
  71. #All bgcolor tags are stripped back out of the posts, returning them to their original states
  72. body.text = body.text.replace("[/bgcolor]", "")
  73. body.text = body.text.replace("[bgcolor=orange]", "")
Advertisement
Add Comment
Please, Sign In to add comment