Skip to content
This repository has been archived by the owner on Nov 30, 2023. It is now read-only.

Fix erase_fields() and Fix for issue #132 #138

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ __pycache__
chinese/config_saved.json
chinese/meta.json
Pipfile.lock
.vscode
8 changes: 5 additions & 3 deletions chinese/behavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,10 @@ def fill_all_rubies(hanzi, note):
def update_fields(note, focus_field, fields):
copy = dict(note)
hanzi = get_first(config['fields']['hanzi'], copy)
if not hanzi:

if hanzi is None: # check if hanzi field exists
return False

hanzi = cleanup(hanzi)

transcript_fields = (
Expand All @@ -261,8 +263,8 @@ def update_fields(note, focus_field, fields):
fill_color(hanzi, copy)
fill_all_rubies(hanzi, copy)

if focus_field in config['fields']['hanzi']:
if copy[focus_field]:
if focus_field in config['fields']['hanzi']: #focus field is hanzi field
if copy[focus_field]: #hanzi field is not empty
fill_all_defs(hanzi, copy)
fill_classifier(hanzi, copy)
fill_transcript(hanzi, copy)
Expand Down
5 changes: 1 addition & 4 deletions chinese/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@ def onFocusLost(self, _, note, index):
field = allFields[index]

if update_fields(note, field, allFields):
if index == len(allFields) - 1:
self.editor.loadNote(focusTo=index)
else:
self.editor.loadNote(focusTo=index+1)
self.editor.loadNote()

return False

Expand Down
3 changes: 1 addition & 2 deletions chinese/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ def all_fields_empty(note, fields):


def erase_fields(note, fields):
for f in fields:
set_all(f, note, to='')
set_all(fields, note, to='')


def get_first(fields, note):
Expand Down