spring-shell icon indicating copy to clipboard operation
spring-shell copied to clipboard

Tab auto-complete will always put a space after selected option

Open gaetPax opened this issue 6 years ago • 1 comments
trafficstars

Currently, when selecting an option through auto-complete (implemented with ValueProvider), the selected option will always put a a space in the command line after the selected option. This is not always the desired behaviour, especially when autocompleting a file path (i.e. using the FileValueProvider). You would like to go deeper into the path and keep the cursor on the last character.

I think this occurs because the 'complete' field when instantiating the 'Candidate' Jline classes is always set to true in the 'CompleterAdapter' class: https://github.com/spring-projects/spring-shell/blob/master/spring-shell-core/src/main/java/org/springframework/shell/jline/JLineShellAutoConfiguration.java#L217

This behaviour should be parametrised.

gaetPax avatar Aug 30 '19 08:08 gaetPax

This always true assignment seems to currently be at CompleterAutoConfiguration

		@Override
		public void complete(LineReader reader, ParsedLine line, List<Candidate> candidates) {
			CompletingParsedLine cpl = (line instanceof CompletingParsedLine) ? ((CompletingParsedLine) line) : t -> t;

			CompletionContext context = new CompletionContext(sanitizeInput(line.words()), line.wordIndex(), line.wordCursor(), null, null);

			List<CompletionProposal> proposals = shell.complete(context);
			proposals.stream()
				.map(p -> new Candidate(
					p.dontQuote() ? p.value() : cpl.emit(p.value()).toString(),
					p.displayText(),
					p.category(),
					p.description(),
					null,
					null,
					true) // <-----  COMPLETE ALWAYS TRUE 
				)
				.forEach(candidates::add);
		}

tincore avatar Apr 15 '23 13:04 tincore