Normalize entry parsing and display order
This commit is contained in:
@@ -713,17 +713,17 @@ fn viewer_lines<'a>(
|
||||
otp_display: Option<&'a crate::app::OtpDisplay>,
|
||||
) -> Vec<Line<'a>> {
|
||||
let focused = viewer.focused_index();
|
||||
if viewer.document().fields().is_empty() {
|
||||
let fields = viewer.document().display_fields();
|
||||
if fields.is_empty() {
|
||||
return vec![Line::from("This entry is empty.")];
|
||||
}
|
||||
|
||||
let mut lines = Vec::new();
|
||||
for (index, field) in viewer.document().fields().iter().enumerate() {
|
||||
for (index, field) in fields.into_iter().enumerate() {
|
||||
let metadata = field.metadata();
|
||||
let label = metadata.name().map_or_else(
|
||||
|| match metadata.kind() {
|
||||
ironstorage::document::EntryFieldKind::Note => format!("note {}", index + 1),
|
||||
ironstorage::document::EntryFieldKind::Blank => format!("blank {}", index + 1),
|
||||
kind => format!("{kind:?}").to_ascii_lowercase(),
|
||||
},
|
||||
str::to_owned,
|
||||
@@ -1514,14 +1514,19 @@ mod tests {
|
||||
|
||||
render(40, 8, &app);
|
||||
assert_eq!(app.viewer().expect("viewer").scroll(), 0);
|
||||
app.dispatch(crate::action::Action::Next);
|
||||
app.dispatch(crate::action::Action::FocusNext);
|
||||
app.dispatch(crate::action::Action::FocusNext);
|
||||
let wrapped = render(40, 8, &app);
|
||||
assert!(wrapped.contains("url: xxxxxx"));
|
||||
let wrapped_scroll = app.viewer().expect("viewer").scroll();
|
||||
assert_eq!(wrapped_scroll, 0);
|
||||
app.dispatch(crate::action::Action::FocusNext);
|
||||
let login = render(40, 8, &app);
|
||||
assert!(login.contains("login: alice@example.test"));
|
||||
render(40, 8, &app);
|
||||
assert_eq!(
|
||||
app.viewer()
|
||||
.and_then(crate::viewer::EntryViewer::focused_field)
|
||||
.map(|field| field.metadata().kind()),
|
||||
Some(ironstorage::document::EntryFieldKind::Url)
|
||||
);
|
||||
assert!(app.viewer().expect("viewer").scroll() > wrapped_scroll);
|
||||
|
||||
render(140, 20, &app);
|
||||
@@ -1583,6 +1588,7 @@ mod tests {
|
||||
let mut app = App::new();
|
||||
app.open_test_document("documents/multiline", document);
|
||||
app.dispatch(crate::action::Action::FocusNext);
|
||||
app.dispatch(crate::action::Action::FocusNext);
|
||||
|
||||
let viewer = app.viewer().expect("viewer");
|
||||
assert_eq!(
|
||||
@@ -1591,7 +1597,7 @@ mod tests {
|
||||
);
|
||||
let lines = viewer_lines(viewer, None);
|
||||
assert_eq!(lines.len(), 5);
|
||||
for line in &lines[1..4] {
|
||||
for line in &lines[2..5] {
|
||||
assert!(line.spans.iter().all(|span| {
|
||||
span.style.fg == Some(SELECTED_FOREGROUND)
|
||||
&& span.style.bg == Some(SELECTED_BACKGROUND)
|
||||
|
||||
@@ -39,7 +39,7 @@ impl EntryViewer {
|
||||
}
|
||||
|
||||
pub fn focused_field(&self) -> Option<&EntryField> {
|
||||
self.document.fields().get(self.focused)
|
||||
self.document.display_fields().get(self.focused).copied()
|
||||
}
|
||||
|
||||
pub fn focus_next(&mut self) {
|
||||
@@ -231,8 +231,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn copy_uses_only_the_focused_structured_value() {
|
||||
let mut viewer = EntryViewer::new(fixture_document("email/personal"));
|
||||
viewer.focus_next();
|
||||
let viewer = EntryViewer::new(fixture_document("email/personal"));
|
||||
let copied = viewer.copy_focused().expect("copy value");
|
||||
assert_eq!(copied.expose(), b"alice@example.test");
|
||||
assert!(!format!("{viewer:?}").contains("correct horse fixture"));
|
||||
|
||||
Reference in New Issue
Block a user