Skip to content

Commit 8331e2b

Browse files
committed
Move the fallback text logic for navigation into Rust.
1 parent 0f790d0 commit 8331e2b

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

app/document_manager.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ void document_manager::navigate_to_section(bool next) const {
300300
}
301301
const long offset = static_cast<long>(result.offset);
302302
text_ctrl->SetInsertionPoint(offset);
303-
const wxString current_line = rust_to_wx(session_get_line_text(*tab->get_session(), offset));
303+
const wxString current_line = rust_to_wx(rust::String(result.marker_text));
304304
if (result.wrapped)
305305
speak((next ? _("Wrapping to start. ") : _("Wrapping to end. ")) + current_line);
306306
else
@@ -347,7 +347,7 @@ void document_manager::navigate_to_page(bool next) const {
347347
}
348348
const long offset = static_cast<long>(result.offset);
349349
text_ctrl->SetInsertionPoint(offset);
350-
const wxString current_line = rust_to_wx(session_get_line_text(*tab->get_session(), offset));
350+
const wxString current_line = rust_to_wx(rust::String(result.marker_text));
351351
wxString message = wxString::Format(_("Page %d: %s"), result.marker_index + 1, current_line);
352352
if (result.wrapped) message = (next ? _("Wrapping to start. ") : _("Wrapping to end. ")) + message;
353353
speak(message);
@@ -433,10 +433,7 @@ void document_manager::navigate_to_link(bool next) const {
433433
}
434434
const long offset = static_cast<long>(result.offset);
435435
text_ctrl->SetInsertionPoint(offset);
436-
wxString link_text = rust_to_wx(rust::String(result.marker_text));
437-
if (link_text.IsEmpty()) {
438-
link_text = rust_to_wx(session_get_line_text(*tab->get_session(), offset));
439-
}
436+
const wxString link_text = rust_to_wx(rust::String(result.marker_text));
440437
wxString message = link_text + _(" link");
441438
if (result.wrapped) message = (next ? _("Wrapping to start. ") : _("Wrapping to end. ")) + message;
442439
speak(message);
@@ -518,7 +515,7 @@ void document_manager::navigate_to_list(bool next) const {
518515
}
519516
const long offset = static_cast<long>(result.offset);
520517
text_ctrl->SetInsertionPoint(offset);
521-
const wxString current_line = rust_to_wx(session_get_line_text(*tab->get_session(), offset));
518+
const wxString current_line = rust_to_wx(rust::String(result.marker_text));
522519
wxString message = current_line;
523520
if (result.wrapped) message = (next ? _("Wrapping to start. ") : _("Wrapping to end. ")) + message;
524521
speak(message);
@@ -548,7 +545,7 @@ void document_manager::navigate_to_list_item(bool next) const {
548545
}
549546
const long offset = static_cast<long>(result.offset);
550547
text_ctrl->SetInsertionPoint(offset);
551-
const wxString current_line = rust_to_wx(session_get_line_text(*tab->get_session(), offset));
548+
const wxString current_line = rust_to_wx(rust::String(result.marker_text));
552549
wxString message = current_line;
553550
if (result.wrapped) message = (next ? _("Wrapping to start. ") : _("Wrapping to end. ")) + message;
554551
speak(message);
@@ -874,9 +871,6 @@ void document_manager::navigate_to_table(bool next) const {
874871
text_ctrl->SetInsertionPoint(offset);
875872
// Use marker_text (caption or first row) if available, otherwise use line text.
876873
wxString message = rust_to_wx(rust::String(result.marker_text));
877-
if (message.IsEmpty()) {
878-
message = rust_to_wx(session_get_line_text(*tab->get_session(), offset));
879-
}
880874
if (result.wrapped) message = (next ? _("Wrapping to start. ") : _("Wrapping to end. ")) + message;
881875
speak(message);
882876
}

lib/src/session.rs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,11 @@ impl DocumentSession {
208208
level_filter: 0,
209209
};
210210
let result = reader_navigate(&self.handle, &req);
211-
NavigationResult::from_nav_result(&result)
211+
let mut nav_result = NavigationResult::from_nav_result(&result);
212+
if nav_result.found && nav_result.marker_text.is_empty() {
213+
nav_result.marker_text = self.get_line_text(nav_result.offset);
214+
}
215+
nav_result
212216
}
213217

214218
#[must_use]
@@ -245,6 +249,9 @@ impl DocumentSession {
245249
if nav_result.found {
246250
let offset = usize::try_from(nav_result.offset).unwrap_or(0);
247251
nav_result.marker_index = self.handle.page_index(offset).unwrap_or(-1);
252+
if nav_result.marker_text.is_empty() {
253+
nav_result.marker_text = self.get_line_text(nav_result.offset);
254+
}
248255
}
249256
nav_result
250257
}
@@ -263,7 +270,11 @@ impl DocumentSession {
263270
level_filter: 0,
264271
};
265272
let result = reader_navigate(&self.handle, &req);
266-
NavigationResult::from_nav_result(&result)
273+
let mut nav_result = NavigationResult::from_nav_result(&result);
274+
if nav_result.found && nav_result.marker_text.is_empty() {
275+
nav_result.marker_text = self.get_line_text(nav_result.offset);
276+
}
277+
nav_result
267278
}
268279

269280
#[must_use]
@@ -283,7 +294,11 @@ impl DocumentSession {
283294
level_filter: 0,
284295
};
285296
let result = reader_navigate(&self.handle, &req);
286-
NavigationResult::from_nav_result(&result)
297+
let mut nav_result = NavigationResult::from_nav_result(&result);
298+
if nav_result.found && nav_result.marker_text.is_empty() {
299+
nav_result.marker_text = self.get_line_text(nav_result.offset);
300+
}
301+
nav_result
287302
}
288303

289304
#[must_use]
@@ -303,7 +318,11 @@ impl DocumentSession {
303318
level_filter: 0,
304319
};
305320
let result = reader_navigate(&self.handle, &req);
306-
NavigationResult::from_nav_result(&result)
321+
let mut nav_result = NavigationResult::from_nav_result(&result);
322+
if nav_result.found && nav_result.marker_text.is_empty() {
323+
nav_result.marker_text = self.get_line_text(nav_result.offset);
324+
}
325+
nav_result
307326
}
308327

309328
#[must_use]
@@ -320,7 +339,11 @@ impl DocumentSession {
320339
level_filter: 0,
321340
};
322341
let result = reader_navigate(&self.handle, &req);
323-
NavigationResult::from_nav_result(&result)
342+
let mut nav_result = NavigationResult::from_nav_result(&result);
343+
if nav_result.found && nav_result.marker_text.is_empty() {
344+
nav_result.marker_text = self.get_line_text(nav_result.offset);
345+
}
346+
nav_result
324347
}
325348

326349
#[must_use]

0 commit comments

Comments
 (0)