Skip to content

Commit 7cbc786

Browse files
committed
Fix breadcrumbs management when navigating back
Fixes #1269
1 parent d77db30 commit 7cbc786

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed

autoload/NavigationManager.gd

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func confirm_unload() -> void:
9595
func navigate_back() -> void:
9696
if _is_unload_confirmation_required():
9797
_current_unload_type = UNLOAD_TYPE.BACK
98-
emit_signal("last_screen_unload_requested")
98+
last_screen_unload_requested.emit()
9999
return
100100

101101
_navigate_back()
@@ -104,7 +104,7 @@ func navigate_back() -> void:
104104
func navigate_to_outliner() -> void:
105105
if _is_unload_confirmation_required():
106106
_current_unload_type = UNLOAD_TYPE.OUTLINER
107-
emit_signal("all_screens_unload_requested")
107+
all_screens_unload_requested.emit()
108108
return
109109

110110
_navigate_to_outliner()
@@ -121,19 +121,19 @@ func _navigate_back() -> void:
121121
history.remove_at(history.size() - 1)
122122
_js_back()
123123

124-
emit_signal("back_navigation_requested")
124+
back_navigation_requested.emit()
125125

126126

127127
func _navigate_to_outliner() -> void:
128128
# prints("emptying history")
129129
history.resize(0)
130130
_js_to_outliner()
131131

132-
emit_signal("outliner_navigation_requested")
132+
outliner_navigation_requested.emit()
133133

134134

135135
func navigate_to_welcome_screen() -> void:
136-
emit_signal("welcome_screen_navigation_requested")
136+
welcome_screen_navigation_requested.emit()
137137

138138

139139
func navigate_to_lesson(course_id: String, lesson_slug: String) -> void:

resources/lesson_bbcode_parser/BBCodeParser.gd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ func _parse_tokens(tokens: Array, file_path: String) -> ParseNode:
214214
current_paragraph.tag = _parser_data.Tag.PARAGRAPH
215215
current_paragraph.line_number = token.line_number
216216
current_paragraph.bbcode_path = file_path
217+
current_paragraph.parent = current
217218
current.children.append(current_paragraph)
218219
if accumulated_text != "":
219220
current_paragraph.children.append(accumulated_text)
@@ -224,6 +225,7 @@ func _parse_tokens(tokens: Array, file_path: String) -> ParseNode:
224225
inline_node.attributes = token.attributes
225226
inline_node.line_number = token.line_number
226227
inline_node.bbcode_path = file_path
228+
inline_node.parent = current_paragraph
227229
current_paragraph.children.append(inline_node)
228230
continue
229231
else:
@@ -262,6 +264,7 @@ func _parse_tokens(tokens: Array, file_path: String) -> ParseNode:
262264
node.attributes = token.attributes
263265
node.line_number = token.line_number
264266
node.bbcode_path = file_path
267+
node.parent = current
265268
current.children.append(node)
266269

267270
if _parser_data.is_container_tag(token_tag):
@@ -312,6 +315,7 @@ func _parse_tokens(tokens: Array, file_path: String) -> ParseNode:
312315
current_paragraph.tag = _parser_data.Tag.PARAGRAPH
313316
current_paragraph.line_number = 0
314317
current_paragraph.bbcode_path = file_path
318+
current_paragraph.parent = current
315319
current.children.append(current_paragraph)
316320
current_paragraph.children.append(accumulated_text)
317321
else:
@@ -348,6 +352,7 @@ class ParseNode:
348352
var children := []
349353
var line_number := -1
350354
var bbcode_path: String
355+
var parent: ParseNode
351356

352357

353358
class ParseError:

ui/UINavigator.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func _navigate_to() -> void:
162162
var ui_practice_screen: UIPractice = preload("UIPractice.tscn").instantiate()
163163
screen = ui_practice_screen
164164
ui_practice_screen.setup(target, lesson, course_index, lesson_number)
165-
elif target.tag == BBCodeParserData.Tag.LESSON:
165+
elif target is BBCodeParser.ParseNode and target.tag == BBCodeParserData.Tag.LESSON:
166166
var lesson_number := course_index.get_lesson_number(target.bbcode_path)
167167
_lesson_index = lesson_number - 1
168168

ui/components/BreadCrumbs.gd

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ func update_breadcrumbs(course_index: CourseIndex, target: BBCodeParser.ParseNod
2323

2424

2525
func _rebuild_breadcrumbs() -> void:
26+
_clear_navigation_nodes()
27+
2628
if not _last_course_index or not _last_target:
2729
return
2830

29-
_clear_navigation_nodes()
30-
3131
if _last_target is BBCodeParser.ParseNode and _last_target.tag == BBCodeParserData.Tag.LESSON:
3232
var lesson := _last_target as BBCodeParser.ParseNode
3333
var lesson_index := -1
@@ -46,23 +46,22 @@ func _rebuild_breadcrumbs() -> void:
4646
if lesson_index >= 0:
4747
node_text = "%s. %s" % [lesson_index + 1, tr(title)]
4848

49-
_create_navigation_node(node_text, "", true)
49+
_create_navigation_node(node_text, null, "", true)
5050
return
5151

52-
if _last_target is BBCodeParser.ParseNode and _last_target.tag == BBCodeParserData.Tag.PRACTICE:
52+
elif _last_target is BBCodeParser.ParseNode and _last_target.tag == BBCodeParserData.Tag.PRACTICE:
5353
var practice := _last_target as BBCodeParser.ParseNode
5454
# TODO: Should probably avoid relying on content ID for getting paths.
55+
5556
var practice_id := BBCodeUtils.get_practice_id(practice)
56-
var lesson_path = practice_id.get_base_dir().path_join("lesson.bbcode")
5757

58-
var lesson: BBCodeParser.ParseNode
58+
var lesson: BBCodeParser.ParseNode = practice.parent
5959
var lesson_index := -1
6060

6161
var i := 0
6262
for l in _last_course_index.get_lessons_count():
6363
var lesson_data := NavigationManager.get_navigation_resource(_last_course_index.get_lesson_path(l)) as BBCodeParser.ParseNode
64-
if lesson_data.bbcode_path == lesson_path:
65-
lesson = lesson_data
64+
if lesson_data.bbcode_path == lesson.bbcode_path:
6665
lesson_index = i
6766
break
6867

@@ -71,7 +70,7 @@ func _rebuild_breadcrumbs() -> void:
7170
if lesson and lesson_index >= 0:
7271
var title := BBCodeUtils.get_lesson_title(lesson)
7372
var lesson_text := "%d. %s" % [lesson_index + 1, tr(title)]
74-
_create_navigation_node(lesson_text, lesson.bbcode_path)
73+
_create_navigation_node(lesson_text, _last_course_index, lesson.bbcode_path)
7574

7675
var practice_count := BBCodeUtils.get_lesson_practice_count(lesson)
7776
var practice_index := -1
@@ -83,7 +82,7 @@ func _rebuild_breadcrumbs() -> void:
8382
break
8483
var practice_title := BBCodeUtils.get_practice_title(practice)
8584
var node_text: String = "%d. %s" % [practice_index + 1, tr(practice_title)]
86-
_create_navigation_node(node_text, "", true)
85+
_create_navigation_node(node_text, null, "", true)
8786
return
8887

8988

@@ -93,7 +92,7 @@ func _clear_navigation_nodes() -> void:
9392
child_node.queue_free()
9493

9594

96-
func _create_navigation_node(text: String, path: String = "", current: bool = false) -> void:
95+
func _create_navigation_node(text: String, course_index: CourseIndex, path: String = "", current: bool = false) -> void:
9796
if get_child_count() > 0:
9897
var separator := Label.new()
9998
separator.text = "•"
@@ -117,7 +116,8 @@ func _create_navigation_node(text: String, path: String = "", current: bool = fa
117116
navigation_node.add_theme_font_size_override("font_size", NODE_FONT_SIZE)
118117
navigation_node.mouse_default_cursor_shape = CURSOR_POINTING_HAND
119118
add_child(navigation_node)
120-
navigation_node.pressed.connect(_on_navigation_pressed.bind(path))
119+
var slug := "#%s/%s" % [course_index.get_course_id(), course_index.get_lesson_slug_from_path(path)]
120+
navigation_node.pressed.connect(_on_navigation_pressed.bind(slug))
121121

122122

123123
func _on_navigation_pressed(path: String) -> void:

0 commit comments

Comments
 (0)