FooSoft / anki-connect

Anki plugin to expose a remote API for creating flash cards.
https://foosoft.net/projects/anki-connect/
Other
1.94k stars 219 forks source link

Feature request: Note field descriptions #362

Closed introt closed 1 year ago

introt commented 1 year ago

Note field descriptions are the "Text to show inside the field when it's empty". They're useful for in-app note template documentation which in turn reduces the cognitive barrier to systematic note creation (eg. "does this factoid belong in the note field named "etiology" or "pathology"?).

Relevant anki source files:

qt/aqt/fields.py:        f.fieldDescription.setText(fld.get("description", ""))
qt/aqt/fields.py:        desc = f.fieldDescription.text()
qt/aqt/fields.py:        if fld.get("description", "") != desc:
qt/aqt/fields.py:            fld["description"] = desc
qt/aqt/forms/fields.ui:      <widget class="QLineEdit" name="fieldDescription">
qt/aqt/forms/fields.ui:        <string>fields_description_placeholder</string>
qt/aqt/forms/fields.ui:  <tabstop>fieldDescription</tabstop>
rslib/src/notetype/fields.rs:                description: "".into(),
ftl/core/fields.ftl:fields-description = Description
ftl/core/fields.ftl:fields-description-placeholder = Text to show inside the field when it's empty
ts/editor/NoteEditor.svelte:    let fieldDescriptions: string[] = [];
ts/editor/NoteEditor.svelte:        fieldDescriptions = fs;
ts/editor/NoteEditor.svelte:        description: fieldDescriptions[index],
ts/editor/NoteEditor.svelte:                        --description-content={`"${field.description}"`}

(introduced in ankitects/anki#1476)

Adding support requires certain considerations, as currently fields are mainly treated as ordered lists (only).

My suggestion is to start with modelFieldDescriptions similar to modelFieldNames on the querying side (implementation here). Besides that, adding inOrderFieldDescriptions to createModel would be one way to proceed in the other direction, followed by modelFieldDescriptionRename akin to modelFieldRename.

introt commented 1 year ago

Related: createModel returns the editing font, direction (rtl) and stickyness, but setting nor querying them is not supported:

"flds":[
            {
                "name":"Field1",
                "ord":0,
                "sticky":false,
                "rtl":false,
                "font":"Arial",
                "size":20,
                "media":[

                ]
            },
            {
                "name":"Field2",
                "ord":1,
                "sticky":false,
                "rtl":false,
                "font":"Arial",
                "size":20,
                "media":[

                ]
            }
introt commented 1 year ago

A modelFieldNames based modelFieldDescriptions is implemented as follows: (pr #363)

    @util.api()
    def modelFieldDescriptions(self, modelName):
        model = self.collection().models.byName(modelName)
        if model is None:
            raise Exception('model was not found: {}'.format(modelName))
        else:
            return [field['description'] for field in model['flds']]

The path forward seems rather simple implementation wise - just need to figure out the appropriate level of support.

I'm personally unable to follow through on the rest for some time; others are free to continue working on these in the meantime.

introt commented 1 year ago

Thanks @Aquafina-water-bottle!