monaco-editor icon indicating copy to clipboard operation
monaco-editor copied to clipboard

[Bug] Tab only accept the empty space

Open BeishaoCao-db opened this issue 1 year ago • 3 comments

Reproducible in vscode.dev or in VS Code Desktop?

  • [X] 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.47.0#XQAAAAJQAgAAAAAAAABBqQkHQ5NjdMjwa-jY7SIQ9S7DNlzs5W-mwj0fe1ZCDRFc9ws9XQE0SJE1jc2VKxhaLFIw9vEWSxW3yscw1r3sCnGBGpWlpVktocO7_BJCkQTDFxvol36GvVmJLcE84C3knSa45xr2hL4V3CzK7RsXTTl3GKNcoe1EOluseUOqlAiRzt565Aikzvea61xWU_C6O4O4af9d95Ho8N37E04AP_F4QgtoH62aRToKkEAPJZoSsZZfAcW23V_8iVY6IVDJixX7Qj5iTFcYx3oLLpyOrtWl5zCHbN-ayZrwUeHldP8jznwshtDv_rgKRk-aCws0DDW2EPOv5b5f_xemFBnpV9OH_7CG5c1Z7OsTHfGIu7oi9k30gjuf2n26CCHN7kRQ-Sye4CP3wTY_3KIXJzrmOTR4TMCrfTPmM8Oi2diYm4dP9RHHrmilKrj-bUnY

Monaco Editor Playground Code

monaco.languages.registerInlineCompletionsProvider("sql", {
	provideInlineCompletions: function (model, position, context, token) {
		console.log('Provide new completion', position, context, token)
		return {items: [
                    {
                        insertText: '  buhao'
                    },
                ]};
	},
	freeInlineCompletions: function (completions) {
		console.log(completions);
	},
}); 

monaco.editor.create(document.getElementById("container"), {
	value: 'SELECT\n  *',
	language: "sql",
});

Reproduction Steps

  1. Open the playground
  2. Type an enter
  3. You will see ' buhao' suggested
  4. Tab
  5. You will see empty space accepted

Actual (Problematic) Behavior

Tab can only accept empty space

Expected Behavior

Tab accept the full suggestion

Additional Context

https://github.com/microsoft/monaco-editor/assets/109033553/81f3a38b-1bd9-4201-8034-3e3b6bcf6ed7

Try on 0.43,0.44,0.47, all don't work. Have to mention, sometimes it works, sometimes it doesn't. Not sure what's the pattern

BeishaoCao-db avatar Mar 29 '24 21:03 BeishaoCao-db

This Is seems to InlineCompletion's inside strategy rather than a bug,When the current line is empty and your insertText is start with more than a tab size blank string(eg: text), The cursor will close to your completion first rather then accept it, you should change your insertText at first tab to handle this situation. Apr-01-2024 16-04-23

qirong77 avatar Apr 01 '24 08:04 qirong77

@qirong77 Yes, that's my first assumption. However, in the example I provided, if you change the initial code to be select\n rather than select\n *, then you will see tab can accept something with tab size blank string.

e.g. Is it because monaco detect size to be 4 then?

If that's the case, let me change the logic then

BeishaoCao-db avatar Apr 04 '24 01:04 BeishaoCao-db

@BeishaoCao-db Wow, You are right. May be because the initial code changes the editor's tab size in some case. When you set your insertText to a larger blank string like buhao,you will find it don't work again. e.g.

qirong77 avatar Apr 04 '24 13:04 qirong77