hsnips icon indicating copy to clipboard operation
hsnips copied to clipboard

Fast typing breaks code evaluation

Open Einlar opened this issue 5 years ago • 4 comments

This is a minor bug, as it happens rarely, and in very specific situations. It can happen with any kind of snippet with code interpolation. For example, by using the box snippet reported in the examples, and holding down the character 'a', evaluation quickly stops, leading to a result like this: quick_typing The same thing happens by repeating different keys (like 'jk', instead of 'a') really fast. I tested this on VS Code 1.39.1, using HyperSnips 0.0.15. It is not a matter of interference with other snippets, as I tested it by leaving only the code for box in the .hsnips file.

Einlar avatar Oct 11 '19 20:10 Einlar

I'm not able to reproduce this issue locally, looking at the image I suppose this could happen if the document edit events were delayed in such a way that the selection change event fired before it and so the extension would think the snippet "lost focus".

If I'm in the right track, this is the kind of timing issue that is really hard to fix without being able to reproduce, so I think this will stay open for now. If you have any more details please send them my way.

draivin avatar Oct 14 '19 16:10 draivin

Just tried it on another (more powerful) pc and it works without problems. It just may be that my laptop is quite slow, resulting in this timing problem. Is there any way to make some sort of "failsafe" to prevent this kind of behavior?

Einlar avatar Oct 14 '19 17:10 Einlar

I have the same issue interestingly. It seems like something goes wrong with how the range of the placeholder updates when typing fast, so the visual selection of the placeholder is different than what the snippet thinks is in scope. As a result, interestingly, the snippet still works closer to the beginning, where the snippet still thinks the changes that are happening are in scope. The HSnippetInstance's this.parts aren't getting updated properly I think.

snip

I'm not too familiar with VSCode's run sequence so if you have any other ideas I'd be happy to try and fix this since I can replicate it on my machine.

itswin avatar Sep 27 '20 15:09 itswin

@draivin try to create a keybinding like this:

  {
    "key": "alt+e",
    "command": "type",
    "when": "editorTextFocus",
    "args": {
      "text": "= "
    }
  },

I mapped some keybindings for latex to type certain things and I have very strange behavior for this snippet when I type > and then use the keyboard shortcut I wrote above:

snippet `(\s*)>=` ">=" A
 \geq $0
endsnippet

grafik The snippet does trigger, but the trigger is appended behind for some reason.

oiiiiiiii avatar Mar 09 '23 20:03 oiiiiiiii