nbspRemover [Official Support]

AnkiWeb: nbspRemover - AnkiWeb

Automatically removes non-breaking spaces during editing and offers a purge button in the Tools menu to clear the collection.


Reasons for its existence:

7 Likes

After 5 days of use, i gotta say i dont know how i was doing without this before

At least a hundred unintended spaces removed so far. And the first purge was around another hundred :slight_smile: (not that many, because i had done the replace manually a week before :wink: )

Would it be possible to do the purge when leaving the text box instead of while typing? Right now, if it detects one space, it removes it and put you at the end of the textbox, even if you are actively typing in between text

Not sure if it would work if you close the window without exiting the text box

Thanks for considering!

2 Likes

Thanks for that report!

editor.loadNoteKeepingFocus() moves the caret to the end - but sadly that call is required so changes made in the backend are reflected in the editing screen. The caret position shift is annoying, so I removed the instantaneus correction altogether. From now on, the add-on will only remove   after clicking on Add. Along with the manual collection purge, this should still suffice.


I might add instant replacements in the future with JS. But that’s really just for fun, it wouldn’t add any benefit other than the satisfaction of more frequent nbsp-kill-notifications.

will that cover normal edit of the card or edits in the browser window? I would like to forget about this forever (not having to click on the remove all nbsp from time time :slight_smile: )

Is there not an losing focus or detroying event for text boxes?

Good point, no it won’t. I’ll see to it in the coming days.

There are hooks like that, but using loadNoteKeepingFocus together with them results in infinite loops.

If you don’t mind that the HTML editor still shows   (even though they’re immediately removed in the backend), then I could add the instant correction back and simply drop that refresh.

If you don’t mind that the HTML editor still shows   (even though they’re immediately removed in the backend), then I could add the instant correction back and simply drop that refresh

Yes, this sounds like the perfect solution tbh :slight_smile:

And just so you know, in its current state it works good enough. Losing focus from time to time is a very small price to pay for not having to deal with nbsp again :wink:

After the update, It doesnt work on the edit or browser window. Only on new cards

Im okay with nbsp while im editing, but id like them to be removed when the field is actually saved. Is it saved every time you type a key?

That’s because I haven’t updated it to reflect this idea yet. The version you got is that one:

You can expect an update today that works in any editor instance, though.

Oh, okay, sorry, since i just got the update right now, i thought i had the latest

No rush or anything!

Thanks again for working on this!

Anki only periodically checks for updates automatically. To get an update immediately after publication, you’ll have to manually check in the add-on screen :slight_smile:

Not immediately, as this would result in unnecessary CPU load. There’s a typing timer of a few hundred ms. If no key is pressed after that time, it saves the content to the database. Anki calls a hook that can be used to alter the field content before it’s saved.

I see, i thought that maybe it was like localc, where you dont save until you exit the cell, which would make it a little easier i guess

Well, no rush! It is doing its job pretty well already! :wink:

Thank you for this! Is there any way to set it so that it runs after every sync on startup?

I have already played around with that, but running a find & replace action synchronously on the whole collection significantly slows startup and closing times of the app.

It’s very wasteful to do this on every sync, because most notes will already be clean and only the few notes which have been added in-between syncs would actually need to be searched.

I could implement an automatic “purge” on the first time the add-on is used + on deck imports. In-editing replacements will take care of the rest.

1 Like

I think running the script on a deck import would be quite smart.

Thanks again for the script, as unnecessary as it should be rolls eyes at Anki

Hey!

I entered the world of addon creation, although i have no idea what i am doing

Recently i made an update where i added a button to the add new note window

For some reason it conflicts with your addon


When loading '<U+2068>nbspRemover<U+2069>':
<U+2068>Traceback (most recent call last):
  File "aqt.addons", line 244, in loadAddons
  File "/home/whatchu/.local/share/Anki2/addons21/1676672391/__init__.py", line 14, in <module>
    init_addcards()
  File "/home/whatchu/.local/share/Anki2/addons21/1676672391/addcards.py", line 33, in init_addcards
    add_cards_did_init(store_addcards)
  File "aqt.hooks_gen", line 133, in __call__
  File "/home/whatchu/.local/share/Anki2/addons21/1181864101/__init__.py", line 42, in insertButtonInAddWindow
    bb = mw.form.buttonBox
AttributeError: 'function' object has no attribute 'form'

This is my addon:

https://ankiweb.net/shared/info/1181864101

Could you take a look?

Thanks!

Mmm, something weird. On the computer im doing the development, it doesnt fail, but on my other computer, with every other addon disabled, if i disable your addon, mine works
:thinking:

I created a new thread. Something weird is going on

Also it has some bugs with AnkiHub.

Thanks for notifying me about these issues. I’m a bit pressed on time lately. For now I recommend disabling my add-on until I get around to fix it.