Author Topic: Document mode goes wonky in JSP files  (Read 4624 times)

RobFreundlich

  • Community Member
  • Posts: 47
  • Hero Points: 2
Document mode goes wonky in JSP files
« on: August 16, 2006, 02:54:37 pm »
If I'm editing a JSP file with embedded Java, sometimes the Document Mode goes to Java instead of HTML and stays there unless I close and re-open the file.  To make it happen, open the following file:

Code: [Select]
<%@ page language="java" contentType="text/html;charset=UTF-8" %>

<%
    Integer someNumber = new Integer(37);
%>

<html>
<head>
    <title>Test</title>
</head>

<body>
Hello World
</body>

</html>

Position your cursor at the end of the "Integer someNumber" line, hit Enter, and type something like Abc.  Now look at your Document Mode (Document -> Select Mode...) and see that it's Java instead of HTML.

I've tracked it to the following code, I think:

Code: [Select]
   // from _UpdateContext() in context.e

   // if in embedded code, bail out of here
   if (p_embedded==VSEMBEDDED_ONLY) {
      typeless orig_values;
      _EmbeddedSave(orig_values);
      _EmbeddedEnd(p_embedded_orig_values);
      _UpdateContext2(ForceUpdate, nUpdateFlags );
      _EmbeddedRestore(orig_values);
      return;
   }

Before _EmbeddedSave(), p_mode_name is Java.  Before _EmbeddedEnd(), it is Java.  Before UpdateContext2(), it is HTML.  Before _EmbeddedRestore, it is HTML.  Before the return, it is Java.

That sorta makes sense, since I'm still in the Java portion of the file.  However, when I leave the Java portion, the mode never goes back to HTML, probably because somehow the "base" mode for the file has been flipped by the above sequence.

Any suggestions or patches for this?

acklenx

  • Guest
Re: Document mode goes wonky in JSP files
« Reply #1 on: August 17, 2006, 06:17:48 pm »
I have encounter the same(or very similar) thing in simple html with javascript.  The big difference being that all context appears to be lost (that is the highlighting and formatting/assistance goes away - for both html and javascript).  I didn't even begin to look behind the curtain - being a simple front end guy, but this sure does seem like the same problem to me.  I submitted a bug on this a few months back, but have heard nothing thus far.  It's very annoying when it happens, particuarly because you can't just undo to fix it, you must close and reopen.  I've included my steps to reproduce below with more than one odd scenario (the last section is the problem most like the parent post):


If I open a  new file ( File > New > HTML > OK
and then _type_ (cutting and pasting has a different behavior) the following...

<div>
 <script>
   function test()
   {
     alert();
   }
 </script>
</div>

When I then beautify the code ( though this already conforms to the
style I've set up ) Tools > Beautify > Beautify, all the formatting
(except for the indent before the alert() is removed and I end up
with:

<div>
<script>
function test()
{
 alert();
}
</script>
</div>


If however I copy and paste the exact block (either formatted or
unformatted) into a new file and beautify it works just fine.

Also if I _type_ a very similar block it will work just fine (even typing):
<div>
 <script>
   function a()
   {
     b();
   }
 </script>
</div>

And changing b() to test() will cause the beautify to fail.

Last but not least, if I save the new document, beautify starts to
work again ... but now there are other problems - tag completion
doesn't work (as well as the new tag highlighting feature -which is
very very nice by the way).  If I type <div>, I would expect the end
tag ( </div> ) to be added automatically (as it was while I typed the
examples above).  This actually happens as soon as the beautify fails.
 But if I now close the document and reopen every thing is back to
working.  To make things fail again I just change the inner function
call twice and beautify.

RobFreundlich

  • Community Member
  • Posts: 47
  • Hero Points: 2
Re: Document mode goes wonky in JSP files
« Reply #2 on: August 18, 2006, 12:25:23 pm »
I've noticed the problem with embedded JavaScript too.  I'm pretty sure it's the same root cause - if the document mode is mucked up, then all of the symptoms you describe will appear.

I think the problem is that there are two places where the current mode are stored - the documentwide p_current_mode variable and a temporary (stacked?) object - and that they aren't being kept in proper sync.

Can any SlickEdit developer offer any suggestions?

PlanetPratt

  • Senior Community Member
  • Posts: 145
  • Hero Points: 6
Re: Document mode goes wonky in JSP files
« Reply #3 on: September 19, 2006, 07:53:12 pm »
Add me to the list of annoyed users on this bug, but it's not nearly as annoying as the problem SlickEdit has with the new JSP Expression Language (EL) constructs.  If the parser runs into ${ it loses it's mind and the color code goes bananas.  I reported it back during the beta test for 11, and was told it had been added to the list, but we have had two patches and it's not fixed yet.

buggyfunbunny

  • Senior Community Member
  • Posts: 234
  • Hero Points: 4
Re: Document mode goes wonky in JSP files
« Reply #4 on: September 21, 2006, 01:09:45 am »
I brought this up back when jsp and (V)SE support for it first appeared.  Perhaps a SE folk can chime in and confirm, or refute, my recollection of the explanation (and perhaps stickify the thread; java related topics such as this come up a lot).  SE really only knows about 2 languages/syntax at a time.  jsp files always (if one is using it as intended) more than that.  In order to do its syntax voodoo, SE would need to track the active language at the cursor; this is a tall order.  I don't recall jsp support has ever been stable; EL just makes the situation more difficult.  Those of us stuck in jsp land may have to switch to Eclipse, or the like.  Even then, whether the SE plug-in does any better there, I don't know.

PlanetPratt

  • Senior Community Member
  • Posts: 145
  • Hero Points: 6
Re: Document mode goes wonky in JSP files
« Reply #5 on: September 21, 2006, 02:35:32 am »
That makes some sense, but it makes me wonder why they haven't worked on enhancing it to compete with a free editor.  Free is hard to beat if you don't have a better feature set.  I love SlickEdit, but the last few releases have been less than stellar.

I've even tried to just define ${ } as a comment, but that doesn't seem to have any effect.  As far as I'm concerned, if it just didn't wig out, I'd be happy with it not recognizing the third language on the page.
  (*Chris*)