Skip to content

Avoid appending sentence_field on note updates#165

Merged
tatsumoto-ren merged 3 commits into
Ajatt-Tools:masterfrom
yqmmm:fix-append-sentence-field
Mar 25, 2026
Merged

Avoid appending sentence_field on note updates#165
tatsumoto-ren merged 3 commits into
Ajatt-Tools:masterfrom
yqmmm:fix-append-sentence-field

Conversation

@yqmmm

@yqmmm yqmmm commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

Summary

This changes append-mode note updates so they stop appending sentence_field.

Problem

The README says append mode should append to media fields:

  • Ctrl+m - append to the media fields of the newly added note
  • Ctrl+b - append to the media fields of selected notes

However, the current implementation also appends sentence_field.

This causes duplicated sentence content when updating notes created externally, for example by Rikaitan with the new note timer enabled.

Example:

  • existing sentence from Rikaitan:
ヤツらの声に<b>現実味</b>が…
  • fuller sentence captured by mpvacious:
あの遠さはヤツらの声に現実味が…
  • current append-mode result:
ヤツらの声に<b>現実味</b>が…<br>あの遠さはヤツらの声に<b>現実味</b>が…

The existing update_sentence() logic already preserves target-word markup from the stored sentence field. Appending the full sentence field afterward defeats that behavior by concatenating the old and new sentences together.

This also aligns with the existing comment in update_sentence():

  • "if the target word was marked by Rikaitan, this function makes sure that the highlighting doesn't get erased."

That comment implies sentence updates should preserve the marked target in the updated sentence, not concatenate both the old and new sentence text.

Fix

Restrict append-mode field joining to:

  • audio_field
  • image_field
  • miscinfo_field
  • secondary_field

Leave sentence text handling to update_sentence(), which preserves existing target-word markup without duplicating the sentence contents.

Result

Append mode still appends media, but sentence updates now produce the expected single sentence with preserved highlighting, e.g.:

あの遠さはヤツらの声に<b>現実味</b>が…

@tatsumoto-ren

Copy link
Copy Markdown
Member

Hey 👋
Before making a PR please explain your issue in our Telegram group.

@tatsumoto-ren

tatsumoto-ren commented Mar 23, 2026

Copy link
Copy Markdown
Member

However, the current implementation also appends sentence_field.

If you don't want to append, you can overwrite instead. The menu shortcut for that is Shift+m ('m' for modify).

With your patch, if I make a card and add 'govno' to each field, I'll lose it if I update the card. This is exactly what the overwrite code path already does.

Before After
screenshot-2026-03-23-22-07-01 screenshot-2026-03-23-22-10-40

ヤツらの声に現実味が…
あの遠さはヤツらの声に現実味が…

This is apparently because mpvacious fails to detect that ヤツらの声に現実味が… is a substring of あの遠さはヤツらの声に現実味が… . So I think it would be more appropriate to edit join_field_content() and apply a fix there.

@tatsumoto-ren

Copy link
Copy Markdown
Member

I've pushed an alternative fix. Tell me if it fixes your issue.

@yqmmm

yqmmm commented Mar 25, 2026

Copy link
Copy Markdown
Contributor Author

@tatsumoto-ren Hi! I was new to this plugin and didn't see the whoe use case here. Your fixes works great for me. Thank you for helping out with this and also for making mpvacious.

@tatsumoto-ren
tatsumoto-ren merged commit 1a47def into Ajatt-Tools:master Mar 25, 2026
@tatsumoto-ren

Copy link
Copy Markdown
Member

Awesome! Thank you for contributing!

@yqmmm
yqmmm deleted the fix-append-sentence-field branch March 25, 2026 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants