microsoft / microsoft/monaco-editor

[Bug] Down arrow is not working if suggestion dropdown inside snippet only have one item

Open
#3,593 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature-request suggest
Dominant language
JavaScript
Stars
46.8k
Forks
4.1k
Avg merge
17h 58m
Merged PRs (30d)
1

Description

Reproducible in vscode.dev or in VS Code Desktop?
  • Not reproducible in vscode.dev or VS Code Desktop
Reproducible in the monaco editor playground?
Monaco Editor Playground Link

https://microsoft.github.io/monaco-editor/playground.html?source=v0.35.0#XQAAAAJeBQAAAAAAAABBqQkHQ5NjdMjwa-jY7SIQ9S7DNlzs5W-mwj0fe1ZCDRFc9ws9XQE0SJE1jc2VKxhaLFIw9vEWSxW3yscw88CE_XEgGR9Ivd8w3mjpSjZSOKE1xhLc1lhytLzTgHexlZdf13AMmb8eWCqPBcz0ifSqHTfhIHUQQZh3WL4dej8ii7Di1rWv30U56tLLpyEnLGYJN5LChcnzNw6oMDYL4hixkD22ehHpv6594EMs6dJ9P1TYZqJVwAACKjltTzi4D0cADCfK3Io7A_VavD7eK_AwOwZybAyNom2JgPgXBKJrJSQlas-hAE8rHloJ9c1Q8oYCEGTJXhDO5dsK8vMuVdxGPoS1E9rYBmveYEGUTA_BD0jjKRMtBUL4mBtRsNjpdBds59C22m2kWnJy_vNoDo0mPRoiF2I5F-_f4AvyjOf5x3OVk0Cd4y_c9TyLOldsuGAbDyUFujS6UAVf5b0oSr_k7WjOUJZDXj1oRWVYFwLp7M3ryVnGR-TON8vKAKLTQiNn2QT5PFmonEuf5s8KD503xQU4d_aIIbeYBGGg1q2M0iHP6sBFtZrPAS6us2B_MYutA_v-Wo-nKSdJRx96jOzSq8r2k1-EYN1UujXB7QZQEeP8YJrwRlHyeifZcTSTuRSxNtsS00FypOGLikPdCzTyzdyJJrLOoHVxnwijxuoN9G6DO96son9PoB_KqFTzJ-Q7t09uKHQb7dbA9zWrGiv_FXfHAA

Monaco Editor Playground Code
function createSuggestions (range) {
  const kind = monaco.languages.CompletionItemKind.Snippet;
  const insertTextRules = monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet;

  return [
    {
      label: 'line',
      kind,
      detail: 'Line',
      insertText: 'Line 1: $1\nLine2: $2\n',
      insertTextRules,
      range,
    },
    {
      label: 'while-do',
      kind,
      detail: 'Inline note',
      insertText: 'note: \'${1:}\'',
      insertTextRules,
      range,
    },
    {
      label: 'for-each',
      kind,
      detail: 'For each loop',
      insertText: 'Some snippet text',
      insertTextRules,
      range,
    },
    {
      label: 'for-in',
      kind,
      detail: 'For in loop',
      insertText: 'Some snippet text',
      insertTextRules,
      range,
    },
  ];
}

monaco.languages.registerCompletionItemProvider("json", {
	provideCompletionItems: function (model, position) {

		var word = model.getWordUntilPosition(position);
		var range = {
			startLineNumber: position.lineNumber,
			endLineNumber: position.lineNumber,
			startColumn: word.startColumn,
			endColumn: word.endColumn,
		};
		return {
			suggestions: createSuggestions(range),
		};
	},
});

monaco.editor.create(document.getElementById("container"), {
	value: '',
	language: "json",
});
Reproduction Steps
  1. Type li
  2. Press Tab
  3. Type wh
  4. Press Down arrow
    image
  5. The cursor goes to the next line
    image
Actual (Problematic) Behavior

When the suggestion dropdown inside a snippet's tabstop only has 1 item, pressing Down arrow will go to next line instead of selecting that item

Expected Behavior

Press Down arrow should select the suggestion item when it has only 1 item.

Additional Context

If the suggestion dropdown has more than 1 item, it can be selected using Up/Down arrow. For example:

  1. Type li
  2. Press Tab
  3. Type fo
  4. Press Down arrow

Result:
image

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Monaco Editor Playground and the provided TypeScript completion-provider snippet; reproduce the issue by entering the single-item suggestion inside a snippet tabstop and pressing Down. Trace the completion and snippet interaction, then verify that Down selects the sole suggestion instead of moving to the next line, including the contrasting multi-item case.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.