Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use enter to commit auto-completion in JavaDoc style comment #6597

Open
GreenLightning opened this issue Jan 17, 2025 · 0 comments
Open

Comments

@GreenLightning
Copy link

GreenLightning commented Jan 17, 2025

Description of the bug

The enter key cannot be used to commit the auto-complete dialog in a JavaDoc style comment. Instead a newline is inserted. Outside of JavaDoc style comments enter works as expected. The tab key still works inside JavaDoc style comments.

With JavaDoc style comment, I mean this particular style to format comments:

/**
 * example text
 */

Steps to reproduce

  1. Open a new document.
  2. Set the syntax to C.
  3. Type SymbolWithAReallyLongName.
  4. Go to a new line and type S.
  5. Press ctrl+space to open the auto-complete window. (It should suggest SymbolWithAReallyLongName).
  6. Press enter. (It should complete SymbolWithAReallyLongName).
  7. Go to a new line and type /** S.
  8. Press ctrl+space to open the auto-complete window. (It should suggest SymbolWithAReallyLongName).
  9. Press enter.

Expected behavior

The name is completed as before. Final output:

SymbolWithAReallyLongName
SymbolWithAReallyLongName
/** SymbolWithAReallyLongName

Actual behavior

A newline is inserted, respecting the comment formatting. Final output:

SymbolWithAReallyLongName
SymbolWithAReallyLongName
/** S
 *

Sublime Text build number

4189

Operating system & version

Windows 11

(Linux) Desktop environment and/or window manager

No response

Additional information

  1. I do have "auto_complete": false in my settings.

  2. This is caused by conflicting default keybindings:

// Default enter command
{ "keys": ["enter"], "command": "insert", "args": {"characters": "\n"} },

// Autocomplete enter command
{ "keys": ["enter"], "command": "commit_completion", "context":
	[
		{ "key": "auto_complete_visible" },
		{ "key": "setting.auto_complete_commit_on_tab", "operand": false }
	]
},

// Special commands for enter in JavaDoc style comments that insert the "*" for formatting.
// Note that these do not respect the auto_complete settings.
{ "keys": ["enter"], "command": "insert", "args": {"characters": "\n* "}, "context":
	[
		{ "key": "setting.auto_indent", "operator": "equal", "operand": true },
		{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
		{ "key": "selector", "operator": "equal", "operand": "source comment", "match_all": true },
		{ "key": "preceding_text", "operator": "regex_contains", "operand": "^\\s*\\*", "match_all": true },
		{ "key": "following_text", "operator": "regex_match", "operand": "(?!/).*", "match_all": true },
		{ "key": "is_javadoc", "operator": "equal", "operand": true, "match_all": true },
	]
},
{ "keys": ["enter"], "command": "insert", "args": {"characters": "\n * "}, "context":
	[
		{ "key": "setting.auto_indent", "operator": "equal", "operand": true },
		{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
		{ "key": "selector", "operator": "equal", "operand": "source comment", "match_all": true },
		{ "key": "preceding_text", "operator": "regex_contains", "operand": "^\\s*/\\*[*!]", "match_all": true },
		{ "key": "following_text", "operator": "regex_match", "operand": "(?!/).*", "match_all": true },
		{ "key": "is_javadoc", "operator": "equal", "operand": true, "match_all": true },
	]
},

All of these commands apply in the given situation. I assume the javadoc commands take precedence because they appear later in the "Default (Windows).sublime-keymap" file or maybe because they have a bigger / more specific context. It would be nice, if the docs explained how this works.

  1. As a workaround the following commands can be inserted into the user's keymap file:
// Fix enter cannot be used to commit auto-completion in javadoc style comments.
// See: https://github.com/sublimehq/sublime_text/issues/6597
{ "keys": ["enter"], "command": "commit_completion", "args": {"characters": "\n* "}, "context":
	[
		{ "key": "setting.auto_indent", "operator": "equal", "operand": true },
		{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
		{ "key": "selector", "operator": "equal", "operand": "source comment", "match_all": true },
		{ "key": "preceding_text", "operator": "regex_contains", "operand": "^\\s*\\*", "match_all": true },
		{ "key": "following_text", "operator": "regex_match", "operand": "(?!/).*", "match_all": true },
		{ "key": "is_javadoc", "operator": "equal", "operand": true, "match_all": true },

		{ "key": "auto_complete_visible" },
		{ "key": "setting.auto_complete_commit_on_tab", "operand": false }
	]
},
{ "keys": ["enter"], "command": "commit_completion", "args": {"characters": "\n * "}, "context":
	[
		{ "key": "setting.auto_indent", "operator": "equal", "operand": true },
		{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
		{ "key": "selector", "operator": "equal", "operand": "source comment", "match_all": true },
		{ "key": "preceding_text", "operator": "regex_contains", "operand": "^\\s*/\\*[*!]", "match_all": true },
		{ "key": "following_text", "operator": "regex_match", "operand": "(?!/).*", "match_all": true },
		{ "key": "is_javadoc", "operator": "equal", "operand": true, "match_all": true },

		{ "key": "auto_complete_visible" },
		{ "key": "setting.auto_complete_commit_on_tab", "operand": false }
	]
},

OpenGL context information


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants