vscode-markdown: Non-keyboard IME doesn't work correctly (Alfred, aText, AutoHotkey, Beeftext, Breevy, EVKey, Keyboard Maestro, UniKey, etc.)

Workaround

Delete key bindings for the markdown.extension.onBackspaceKey command. This effectively removes some of our list editing features.

This issue cannot be resolved in foreseeable future due to how input is handled. https://markdown-all-in-one.github.io/docs/guide/compatibility.html

@Lemmingh 2021-07-02


Introduction

I use Alfred.app for text expansion. I noticed that when I try to expand text snippets in VS Code with Markdown All in One enabled, the text snippets fail to expand completely.

Expected behavior

When using Alfred.app to expand text snippets, the text snippets should expand fully. For example, I’ve configured Alfred.app to expand ,ymd into the current date, using this format: 2018-06-08.

Another example is lipsum1 that expands into the following:

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Actual behavior

Instead of expanding these simple snippets correctly, the snippets expand partially, leaving the first character of two of the snippet in place. Here is a demonstration of text expansion with Markdown All in One disabled, and enabled):

Steps to reproduce behavior

  1. I started VS Code with all extensions disabled. My text snippets expanded correctly, so this isn’t an issue with VS Code.
  2. I restarted VS Code normally, and tested my snippets again. I was able to reproduce the issue.
  3. I disabled Markdown All in One, attempted the snippets again. This time, the snippets expanded correctly.
  4. I re-enabled Markdown All in One again, the issue returned.

I captured the following error logs using VS Code’s Developer Tools while testing with the Markdown All in One extension enabled:

https://gist.github.com/pauljacobson/e726698e68d7be5deeb727079fa8cf78

When I tested with Markdown All in One disabled, there were no errors in the Developer Tools console.

System information

OS: macOS 10.13.4 RAM: 16GB 2133 MHz Model: MacBook Pro (15-inch, 2017) VS Code version: 1.24.0 (this issue manifested with previous versions of VS Code)

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 14
  • Comments: 38 (11 by maintainers)

Most upvoted comments

The same thing that this extension and Vim extension both do is listening to some certain key pressing and then do some text editing.

This extension override these keys (enter, tab, backspace etc.)

https://github.com/neilsustc/vscode-markdown/blob/cdbe30420f1d2740c9232a2e249628ffa31d9935/src/listEditing.ts#L8-L20

It does nothing with ASCII characters, so it is wired why this issue happens

So disabling the keyboard shortcut markdown.extension.onBackspaceKey does the job for me. It looks like the only place this is used is when backspacing on list markers which I don’t mind not having.

I have the same problem with AutoHotKey and Markdown All in One. It recently started to be an issue. In non .md files, my text expand correctly. However, it does not in .md files. Maybe this is caused by an update of VS Code, Markdown all in One, or AutoHotKey?

Yes, I have the same issue. markdown all in one is a great ext. But it doesn’t let me expand my AHK snippets. Using it on windows 10 and autohotkey.com. For example, this snippet:

::dxt::DevExtreme

So when I type “dxt”, it’ll expand to “DevExtreme”. However, I get this with the extension enabled:

“dxDevExtrem”

aText was not mentioned here but it’s another text expanding tool that has this issue when Markdown All in One is enabled.

Ok, for AutoHotkey Hotstrings, this works:

:SE, K1:dx::DevExpress

One millisecond delay but it does the job.

From here: https://autohotkey.com/board/topic/63377-delay-in-hotstring/

I have a lot of hotstrings so I likely may not use it since I can live w/o MarkDownAllInOne Ext. But hopefully it helps others.

@yzhang-gh One of my colleagues suggested a workaround for macOS users who encounter this sort of issue with Alfred.app. They suggested adjusted the text expansion speed in the app, starting with this option in the Snippets section in Alfred Preferences:

Screen Shot 2020-05-31 at 08 03 10

Next, adjust the Simulated key event speed to Average or Slow, here:

Screen Shot 2020-05-31 at 08 03 28

I had this set to Fastest. When I adjusted the speed to Average, I didn’t see the text expansion issue in VS Code with the Markdown All in One extension enabled. I still want to do some more testing, but this adjustment in the Alfred.app settings seems to do the trick.

Tested on:

  • Alfred v4.0.9
  • macOS 10.15.5
  • VS Code 1.45.1
  • Markdown All in One v3.0.0

Copied from VSCodeVim/Vim#2845

Workaround

I have also experienced this issue, and was successfully able to work around it by opening Alfred Preferences > Snippets > Auto Expansion Options > Tweaking and setting Simulated key event speed to 4/5 (the level below Faster). Still, would be nice if this was fixed!

For AutoHotKey users, you can try if there is any similar “speed” option.

I just tested text expansion using TextExpander (another text expansion app for macOS and Windows), and I don’t see the same issue with that app. It looks like there may be something about how Alfred interacts with VS Code, and Markdown All in One, that causes the issue I reported.

I’ve asked for some insights into how Alfred interacts with editors over at the Alfred forum, in case the team there has any they can share: Text expansion issue when working in VS Code - Discussion & Help - Alfred App Community Forum.

Thank you for this really detailed bug report.

Could you please describe how Alfred.app works? Expanding on tab key? (I’m not a Mac user so not familiar with those tools)

The same thing that this extension and Vim extension both do is listening to some certain key pressing and then do some text editing. This extension override these keys (enter, tab, backspace etc.) neilsustc/vscode-markdown@cdbe304/src/listEditing.ts#L8-L20 It does nothing with ASCII characters, so it is wired why this issue happens

So disabling the keyboard shortcut markdown.extension.onBackspaceKey does the job for me. It looks like the only place this is used is when backspacing on list markers which I don’t mind not having.

In case anyone find useful, I’m using https://github.com/espanso/espanso with the trigger :det for:

<details>
<summary>
$|$
</summary>
</details>

and it wasn’t working until I disabled markdown.extension.onEnterKey as well (disabling markdown.extension.onBackspaceKey was not enough).

Before: 2022-08-27 20-16

After: 2022-08-27 20-17

To disable, on keybindings.json:

[
	...
    {
        "key": "enter",
        "command": "-markdown.extension.onEnterKey",
        "when": "editorTextFocus && !editorHasMultipleSelections && !editorReadonly && !suggestWidgetVisible && editorLangId == 'markdown' && vim.mode != 'CommandlineInProgress' && vim.mode != 'EasyMotionInputMode' && vim.mode != 'EasyMotionMode' && vim.mode != 'Normal' && vim.mode != 'Replace' && vim.mode != 'SearchInProgressMode' && vim.mode != 'SurroundInputMode' && vim.mode != 'Visual' && vim.mode != 'VisualBlock' && vim.mode != 'VisualLine'"
    },	
	...
]

I can confirm that the exact same issue is also present on Windows 8.1 with the Breevy text expander and the Beeftext text expander.

I couldn’t get Beeftext to work with Markdown All in One, but there’s a workaround for Breevy:

Set “Output Method” to “Clipboard” in the preferences. (The default is “Key press simulation”.) Now it takes noticeably longer to expand the snippets, though, so I might not use Markdown All in One (I just started using VS Code).

A permanent fix would be wonderful.

Thanks. Looks like the same solution as #200 (comment)?

Ah, right! Sorry! I finally caught up with you there.

Another Authotkey user here! 😃

On my machine, Mehul’s solution with the 1ms delay takes noticeably longer to actually insert some text. I found the following solution which inserts it in a less “chunky” manner. Adjust the 1ms till it works for your setup 😃

; This worked
::dx::{Sleep 1}DevExpress

; For longer hotstrings, I needed more
::azerty::{Sleep 60}DevExpress

With 250ms pretty much any length of hotstring expanded correctly. I answered this Stackoverflow question with details from this issue.


The same bug might have been present in an earlier version of VSCode: https://github.com/microsoft/vscode/issues/1934

They make mention of this commit fixing it. Unfortunately it’s a rather large commit 😦 https://github.com/microsoft/vscode/commit/a1bd50f63fd8185a13495ff3d4c67396109e4e71 Commit msg: “Fixes #1168: Read synchronously from textarea”

The problem has to do with the backspace remapping.

Take the following autohotkey hotstring:

::tada::🎉

This will make typing “tada” followed by one of the “EndingChars” (space, tab, comma, dot, …) expand to the 🎉 emoji.

What you see visually happening on the screen is that Autohotkey does this by first sending a backspace to the editor 4 times (length of hotstring “tada”) and then inserts the replacement text (🎉)

What happens when this (pretty fantastic) extension is active is that the first x characters get deleted then the replacement text gets inserted and then the remaining (hotstring length - x) characters get deleted. But because the cursor is now at the end of the replacement text… which gets chewed on 😃

I’ll have to learn how to debug the IDE itself or always add a {Sleep 250} to my hotstrings…

Thanks for checking.

Just checked VSCode and VSCodeVim repo and Alfred forum but none of them has any update. It is hard to tell what is the root cause.

I’ve created a bug in the Vim plugin for anyone that wants to follow it: https://github.com/VSCodeVim/Vim/issues/2845