estruyf / vscode-front-matter

Front Matter is a CMS running straight in Visual Studio Code. Can be used with static site generators like Hugo, Jekyll, Hexo, NextJs, Gatsby, and many more...
https://frontmatter.codes
MIT License
1.86k stars 70 forks source link

Issue: Input fields need debounce — typing is laggy and often misses characters #730

Closed T3sT3ro closed 4 months ago

T3sT3ro commented 6 months ago

Describe the bug Typing in the fields like "Description" in the blog's metadata results in instant updates to the file's content. At the same time the field is not very responsive and sometimes "eats" characters when typing fast.

To Reproduce Steps to reproduce the behavior:

  1. Create blog post, assure the schema and metadata allow for inputting in the description field in the sidebar's "Metadata" section
  2. Type very fast (e.g. move your finger very quickly over "qwertyuiop")
  3. See that some characters were eaten during typing

Expected behavior The text should be input as user typed.

Possible solution Add debounce, for example for 300ms (or longer), to the text inputs after which you will update the text file. It is possible that longer markdown files can produce even more lag (updates to frontmatter in them can be time consuming), so maybe you should stress test it against some longer blog posts.

Screenshots

https://github.com/estruyf/vscode-front-matter/assets/5300963/a6315658-7816-4749-9d61-ed6ef72f7370

Desktop (please complete the following information):

estruyf commented 6 months ago

Thanks @T3sT3ro for your suggestion. I have added it to the text input fields, feel free to give it a try in the latest beta.

T3sT3ro commented 6 months ago

It's a much smoother experience now, thanks!

I noticed some issues with the undo system however — it is pretty hard to reproduce reliably, so you might want to try several times. The steps go like this:

  1. input some sentence into the "description" field
  2. Use CTRL+BACKSPACE to erase last word
  3. Use CTRL+Z to undo the action of deleting the word

You have to trigger step 3. at appropriate time, somewhere between the step 2. and around the time the debounce triggers and the file is changed. Try to trigger 3. "at the same time" the debounce kicks in and you may see that there is a frame when the world appears successfully (after undo) and then disappears again (and you can't redo again).

The similar thing happens in the reverse case , for example when you first type, then wait for debounce to kick in and rougly at the same time (few ms before) press undo — the word is erased for a brief moment and pasted again. The first case is worse however, assuming you type some lengthy description you accidentally select and erase a part of the text (e.g. you brush the touchpad and press backspace at the same time) then you can lose all of your input when you mistime your CTRL+Z, because input action is erased from the input history.

Another thing you could do is also consider adding debounce to other types of inputs, for example toggles (for me draft input seems to trigger immediately introducing some delay to responsiveness)

estruyf commented 6 months ago

Thanks, @T3sT3ro, for testing it out! I will do some extra testing as well.

T3sT3ro commented 6 months ago

I also noticed some with undo for categories and tags input — which most probably need their own issue - adding a category/tag is not undoable. Other inputs may also require some testing.