eclipse.platform.ui icon indicating copy to clipboard operation
eclipse.platform.ui copied to clipboard

Typing open bracket should surround the selected text element with brackets

Open vogella opened this issue 2 years ago • 4 comments

If I select an text element and type an opening bracket, e.g. "(" VScode the selected work is surrounded by brackets, if I do the same in Eclipse the work is deleted.

I think the VScode behavior is much nicer and noticed this difference while testing @mickaelistria LS-JDT integration for Eclipse.

Would be also adjust the behavior in Eclipse? If yes, which editor would be good to implement this? Text editor or generic editor?

vogella avatar May 26 '23 08:05 vogella

@vogella: Sorry I didn't get it. What is a "text element" and was is the "selected work"?

BeckerWdf avatar Jun 28 '23 13:06 BeckerWdf

Type WORD in an editor Double-click on WORD to select it Now type "(" -> WORD gets deleted in Eclipse

Do the same in code, the result is: -> (WORD)

vogella avatar Jun 28 '23 13:06 vogella

Note that since we already have in most editors some strategy to auto-insert a closing brackets, this request is most likely just an extension of the existing strategies to tweak the handling of insertion with a non-empty selection. For the generic editor (and TM4E that already provide all the matching bracket smartness for a given language), it's mostly a matter of updating the org.eclipse.tm4e.languageconfiguration.internal.LanguageConfigurationAutoEditStrategy, for JDT it looks like it's a matter of changing CompilationUnitEditor.verifyKey() to add the overridden content between buffer.append(character) and buffer.append(closingCharacter).

mickaelistria avatar Mar 08 '24 14:03 mickaelistria

FWIW, this just got implemented in TM4E (so it would serve many editors already, but not default JDT one): https://github.com/eclipse/tm4e/commit/501ede88852ec05ac9f0414c75783effa33cb1e9

mickaelistria avatar Mar 11 '24 08:03 mickaelistria

Awesome, thanks @lathapatil

Also thanks @mickaelistria. I hope at some point the base JDT editor is changed to the generic code editor to benefit from such developments.

vogella avatar Dec 06 '24 15:12 vogella

The feature is now always active, unless overridden in code.

Shouldn't this feature be made optional using a preference page and/or coupled to the 'Smart Insert Mode'?

sratz avatar Jan 16 '25 15:01 sratz

Optional features are hard be discover for users. Why do you think it should not be active by default?

vogella avatar Jan 16 '25 15:01 vogella

The way I read it, this is suggesting for a way to control the behavior with no comment about what the default should be...

merks avatar Jan 16 '25 16:01 merks

Yes, enabled by default is is fine, but I think there should be a way to disable this functionality, similar to Java-specific preferences:

Image

sratz avatar Jan 16 '25 16:01 sratz