Skip to content

Commit 1a83df0

Browse files
committed
Put new fields at the end
1 parent 9f08eb5 commit 1a83df0

File tree

2 files changed

+5
-42
lines changed

2 files changed

+5
-42
lines changed

src/anking_notetypes/notetype_setting.py

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,7 @@ def order_names(
500500
) -> List[str]:
501501
"""Order new names based on the order of current names.
502502
All new_names will be included in output, ordered based on the current_names,
503-
and if they are not in current names, this tries to put it next to names with the same first word,
504-
or otherwise puts them at the end.
503+
and if they are not in current names, they are appended to the end.
505504
506505
Args:
507506
current_names: List defining preferred ordering
@@ -513,25 +512,6 @@ def order_names(
513512
if not current_names:
514513
return new_names
515514

516-
result = [name for name in current_names if name in new_names]
517-
518-
def get_first_word(name: str) -> str:
519-
return name.split()[0] if name else ""
520-
515+
existing_names = [name for name in current_names if name in new_names]
521516
missing_names = [name for name in new_names if name not in current_names]
522-
for name in missing_names:
523-
insert_position = None
524-
for i, setting_name in enumerate(result):
525-
if (
526-
setting_name
527-
and name
528-
and get_first_word(setting_name).lower() == get_first_word(name).lower()
529-
):
530-
insert_position = i + 1
531-
532-
if insert_position is None:
533-
insert_position = len(result)
534-
535-
result.insert(insert_position, name)
536-
537-
return result
517+
return existing_names + missing_names

tests/test_unit.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,21 @@ def test_basic(self):
66
assert order_names(
77
new_names=[
88
"Lecture Notes",
9-
"Boards and Beyond",
10-
"Boards and Beyond Links",
119
"First Aid",
12-
"First Aid Links",
1310
"Extra",
14-
"Missed Questions",
11+
"First Aid Links",
1512
],
1613
current_names=[
1714
"Extra",
1815
"First Aid",
19-
"Missed Questions",
20-
"Boards and Beyond",
2116
],
2217
) == [
23-
# We are keeping the order of the current names and adding the new names which are missing
24-
# after related current names (matching by their first word) if any matches exist,
25-
# otherwise at the end.
2618
"Extra",
2719
"First Aid",
28-
"First Aid Links",
29-
"Missed Questions",
30-
"Boards and Beyond",
31-
"Boards and Beyond Links",
3220
"Lecture Notes",
21+
"First Aid Links",
3322
]
3423

35-
def test_with_multiple_first_word_matches(self):
36-
assert order_names(
37-
new_names=["Sketchy", "Sketchy 1", "Sketchy 2", "Extra"],
38-
current_names=["Sketchy", "Sketchy 1", "Extra"],
39-
) == ["Sketchy", "Sketchy 1", "Sketchy 2", "Extra"]
40-
4124
def test_no_matches(self):
4225
assert order_names(
4326
new_names=["Apple", "Banana"], current_names=["Cherry", "Date"]

0 commit comments

Comments
 (0)