Normalize entry parsing and display order

This commit is contained in:
2026-08-11 07:28:15 +02:00
parent 2a8c941a65
commit d21f5bd467
6 changed files with 262 additions and 74 deletions

View File

@@ -25,7 +25,7 @@ pub enum FieldNavigation {
impl EntryEditor {
pub fn new(document: EntryDocument) -> Self {
let focused = document.fields().first().map(EntryField::id);
let focused = document.display_fields().first().map(|field| field.id());
let multiline = document
.fields()
.iter()
@@ -86,7 +86,7 @@ impl EntryEditor {
}
pub fn focused_ratio(&self) -> f32 {
let fields = self.document.fields();
let fields = self.document.display_fields();
self.focused
.and_then(|id| fields.iter().position(|field| field.id() == id))
.map_or(0.0, |index| {
@@ -128,7 +128,7 @@ impl EntryEditor {
}
pub fn navigate(&mut self, navigation: FieldNavigation) {
let fields = self.document.fields();
let fields = self.document.display_fields();
if fields.is_empty() {
self.focused = None;
return;

View File

@@ -4945,7 +4945,6 @@ fn viewer_label(field: &EntryField) -> String {
EntryFieldKind::OtpUri => "One-time password".to_owned(),
EntryFieldKind::Field => "Field".to_owned(),
EntryFieldKind::Note => "Note".to_owned(),
EntryFieldKind::Blank => "Blank line".to_owned(),
},
str::to_owned,
)
@@ -4982,7 +4981,7 @@ fn viewer_view<'a>(app: &'a App, editor: &'a EntryEditor) -> Element<'a, Message
column![text("Up/Down/Home/End select fields · ⌘C copies the selected value").size(12),]
.spacing(8);
for field in editor.fields() {
for field in editor.document().display_fields() {
let id = field.id();
let label = viewer_label(field);
let selected = editor.focused() == Some(id);
@@ -5943,7 +5942,7 @@ mod tests {
let temporary = editor.fields().last().expect("temporary field").id();
editor.remove(temporary).expect("remove temporary line");
let expected =
b"password\nusername: alice\nfirst note line\ncustom-field: opaque\nsecond note line";
b"password\nusername: alice\n first note line\ncustom-field: opaque\n second note line";
assert_eq!(editor.document().serialize().expose(), expected);
save_document(&storage, &editor).expect("initial save");
@@ -5966,7 +5965,7 @@ mod tests {
assert!(stale.is_dirty());
assert_eq!(
stale.document().serialize().expose(),
b"complete stale draft\nusername: alice\nfirst note line\ncustom-field: opaque\nsecond note line"
b"complete stale draft\nusername: alice\n first note line\ncustom-field: opaque\n second note line"
);
}
@@ -6057,12 +6056,32 @@ mod tests {
.text()
);
assert!(document_has_single_totp(editor.document()));
assert_eq!(
editor
.document()
.display_fields()
.into_iter()
.map(EntryField::id)
.collect::<Vec<_>>(),
[
editor.fields()[1].id(),
editor.fields()[0].id(),
editor.fields()[7].id(),
editor.fields()[8].id(),
editor.fields()[4].id(),
editor.fields()[5].id(),
editor.fields()[6].id(),
editor.fields()[9].id(),
editor.fields()[2].id(),
editor.fields()[3].id(),
]
);
editor.navigate(FieldNavigation::First);
assert_eq!(editor.focused(), Some(password));
editor.navigate(FieldNavigation::Next);
assert_eq!(editor.focused(), Some(editor.fields()[1].id()));
editor.navigate(FieldNavigation::Next);
assert_eq!(editor.focused(), Some(password));
editor.navigate(FieldNavigation::Last);
assert_eq!(editor.focused(), Some(editor.fields()[9].id()));
assert_eq!(editor.focused(), Some(editor.fields()[3].id()));
assert!(!authentication_allows_content(&AuthenticationView::Locked));
assert!(authentication_allows_content(