Slash Character in RTextArea

General Discussion on RSyntaxTextArea.

Moderator: robert

Slash Character in RTextArea

Postby thomas » Wed Dec 05, 2012 5:31 pm

Hi,

I am a developer at Institut Pasteur and I'm working on a plugin for our software Icy: http://icy.bioimageanalysis.org/

I am actually developing a script editor based on your nice libraries autocomplete and rsyntaxtextarea (very good job, they are amazing) with the latest SVN version. However, I found a weird issue : I cannot use the '/' character inside an RTextArea (and by extension, RSyntaxTextArea). I tested with a very simple example, but it does not work either.

I am working on an AZERTY keyboard, I have no idea if that changes anything.

By the way: I had a few issues with the integration of AutoComplete library in my software, I don't know if I should post another post about it or not?
thomas
 
Posts: 2
Joined: Wed Dec 05, 2012 5:21 pm

Re: Slash Character in RTextArea

Postby robert » Thu Dec 06, 2012 12:57 pm

Hi Thomas,

Yes, the slash character unfortunately broke for some folks with 2.0.5; you can use 2.0.4 for the time being until I get a fix out.

With Linux machines (English locale, querty keyboard), there was an issue where using the "comment lines" action (ctrl+/ by default) would fire both the comment-lines action, as well as the default "insert a / character" action. This looks to be because of a difference between Linux and Windows/OS X as far as keyTyped vs. keyPressed key events, and what is used to actually insert a "/" character when typing.

The fix that was put into 2.0.5 for this was to edit RsyntaxTextAreaDefaultInputMap to change the KeyStrokes for the slash-related actions, to force them to be identical across all OSes, and also to make them work across all OSes (Windows, Linux, OS X, even tested Solaris). Unfortunately, this was all done on English locale, querty system setups. I evidently broke folks in other environments by doing this. :(

Once I can determine a way to get these actions working everywhere, I plan on creating a 2.0.5.1 release that has just this keyboard fix. If you have access to qwerty systems as well, and have the time/motivation, feel free to look into it :D You can look at the 2.0.4 tag for RSyntaxTextAreaDefaultInputMap.java if you want to see the older, working, version. A diff of the changes is here.

Sorry about the breakage!
User avatar
robert
 
Posts: 788
Joined: Sat May 10, 2008 5:16 pm

Re: Slash Character in RTextArea

Postby thomas » Wed Dec 12, 2012 9:53 am

Hi,

It works like a charm, at least on Mac OS X and Windows. But as of now, the plugin is still in beta and we don't have a lot of Linux users, so, I can wait for the "real" patch.

Thank you very much for your quick answer!
thomas
 
Posts: 2
Joined: Wed Dec 05, 2012 5:21 pm

Re: Slash Character in RTextArea

Postby oliver » Thu Dec 13, 2012 7:59 pm

Hi,

wouldn"t this code snipplet be a work-around for the os issue?
It works fine for me. Maybe this is what solves the *nix problem?

String osName = System.getProperty("os.name");
if (osName!=null && (osName.startsWith("SOLARIS") || osName.startsWith("SUNOS") || osName.startsWith("LINUX"))) {
put(KeyStroke.getKeyStroke(KeyEvent.VK_SLASH, 0), RSyntaxTextAreaEditorKit.rstaCloseMarkupTagAction);
put(KeyStroke.getKeyStroke('/'), "DoNothing");
} else {
put(KeyStroke.getKeyStroke('/'), RSyntaxTextAreaEditorKit.rstaCloseMarkupTagAction);
}


Regards,
Oliver
oliver
 

Re: Slash Character in RTextArea

Postby robert » Thu Dec 13, 2012 10:50 pm

I'd need someone with access to a Linux environment, and using a qwertz, azerty, or other problematic keyboard layout to try that scenario. It's possible that they would be unable to type a '/' character with that fix, but that should certainly fix it for Windows & OS X everywhere, and *nix with qwerty keyboard layouts. I'll patch that in tomorrow or this weekend and get someone to try it out in that environment. Anxious to get this fixed.
User avatar
robert
 
Posts: 788
Joined: Sat May 10, 2008 5:16 pm

Re: Slash Character in RTextArea

Postby Oliver » Thu Dec 13, 2012 11:00 pm

Hi robert,

sorry, this does not fix the issue with the QWERTZ layout at all, but the toggle comment still does not work with this layout. If you path the next line after the if-statement

put(KeyStroke.getKeyStroke(KeyEvent.VK_7, defaultMod|shift), RSyntaxTextAreaEditorKit.rstaToggleCommentAction);


to the source, then it works again with the QUERTZ layout on WINDOWS systems. Unfortunately I do not have a *nx environment to test the behaviour on *nix.

Regards,
Oliver
Oliver
 

Re: Slash Character in RTextArea

Postby robert » Fri Dec 14, 2012 5:04 am

I realize now that there's no way to install a single set of entries into an InputMap/ActionMap for all OS/keyboard layout combinations. This, combined with the fact that you cannot detect input method Locale changes at runtime in Java, means there's simply no easy, "simple" fix for this.

I started to hack together a solution that tried to detect your IM locale and OS, and did its best to install ToggleCommentAction and CloseMarkupTagAction appropriately so it would work on your system, but then decided that this was a bad idea. I'm going with the KISS principle here instead. CloseMarkupTagAction will be available everywhere (I believe in 2.0.4 and prior, it worked across all environments). ToggleCommentAction (which, in 2.0.4 and earlier, was "broken" on *nix, since those OSes would trigger both a KEY_TYPED '/' and a KEY_PRESSED ctrl+'/' when the user pressed ctrl+/, causing both a ToggleCommentAction and CloseMarkupTagAction to fire) will simply no longer be installed by default on *nix.

What this means in practical terms: Windows and OS X users will be able to type Ctrl+/ (or Cmd+/ on OS X) to toggle line comments on selected lines. On *nix, this shortcut will do nothing in 2.0.6. If an application using RSTA wants this action on Linux, they can easily assign a shortcut to it in the InputMap/ActionMap, but they're going to run into the problems outlined above.

Anybody interested, please try the latest code in Subversion, or grab this test jar, try it out, and report back and let me know how it works. I'd like to know:

  • Your OS (feel free to test more than one!)
  • Your keyboard layout (QWERTY, AZERTY, QWERTZ, something else?)
  • Your input locale (which is likely your system locale)

I believe #3 is practically tied to #2, unless you go mucking with your input method locale in your system settings. Anyway, once it's verified that things are working as expected everywhere, I'll release 2.0.6 and we'll all be happy again. 8-)

  • Windows, QWERTY: Working ('/' and ctrl+'/')
  • Windows, QWERTZ:
  • Windows, AZERTY:
  • OS X, QWERTY: Working ('/' and ctrl+'/')
  • OS X, QWERTZ:
  • OS X, AZERTY:
  • Linux, QWERTY:
  • Linux, QWERTZ:
  • Linux, AZERTY:
User avatar
robert
 
Posts: 788
Joined: Sat May 10, 2008 5:16 pm

Re: Slash Character in RTextArea

Postby Oliver » Fri Dec 14, 2012 9:26 pm

Hi robert,

I tried your solution currently available in svn. Everything works fine on the QWERTY keyboard layout on Windows in Locale.US. But on the QWERTZ keyboard layout on Windows in Locale.US the toggling of the comment still doesn't work, but entering a slash works fine again.
But as I mentioned yesterday, this seems to be the issue, that on a German keyboard, the slash is entered by pressing Shift & 7 keys.
Hope this is of any help for you.

Regards,
Oliver
Oliver
 

Re: Slash Character in RTextArea

Postby robert » Sat Dec 15, 2012 7:28 pm

Yes, that means that means that you couldn't use the ToggleCommentAction with the 2.0.4 release and that keyboard layout either. I'm going to release 2.0.5.1 the same way. If you want to have that action available with a non-QWERTY keyboard, you'll have to assign it yourself.

If someone can show me a foolproof means of detecting the keyboard layout, so I can dynamically assign the keyboard shortcut for that action, I'll be happy to do so. But I'm hesitant to start checking locales to try to determine what to do (more complex code => higher chance for bugs).
User avatar
robert
 
Posts: 788
Joined: Sat May 10, 2008 5:16 pm

Re: Slash Character in RTextArea

Postby robert » Tue Dec 18, 2012 4:07 am

This fix was published as 2.0.5.1 on SourceForge.
User avatar
robert
 
Posts: 788
Joined: Sat May 10, 2008 5:16 pm


Return to Open Discussion

Who is online

Users browsing this forum: No registered users and 3 guests

cron