Opened 9 years ago

Closed 9 years ago

#1081 closed defect (fixed)

Control character is not being removed inside SCRIPT tags or HEAD when switching from textmode to htmlmode.

Reported by: guest Owned by: gogo
Priority: normal Milestone:
Component: Xinha Core Version:
Severity: normal Keywords: cursor, script, javascript, cursor position
Cc:

Description

The control character that keeps track of the cursor position when switching from textmode to htmlmode is not being removed when the cursor is somewhere inside a SCRIPT tag.
This breaks inline javascripts when you are editing them via Xinha.

Example, (I use the pipe character (|), to indicate cursor position):
Textmode:

<p>Some html</p>
<script type="text/javascript">
ale|rt(1);
</script>
<div>more html</div>

When switching back to htmlmode, the cursor position is saved by adding an extra control character in htmlcode. But apparently this control character is not being removed inside script tags.
If we switch back to text mode, we will see a space character in the script (IE 6):

<p>Some html</p>
<script type="text/javascript">
ale rt(1);
</script>
<div>more html</div>

In Firefox the control character is invisible in textmode, but it is there!

This bug is present in (at least) IE (version 6.3790.3959) and Firefox (version 2.0.0.7).

The problem is in the findCC method in the modules/InternetExplorer/InternetExplorer.js and modules/Gecko/Gecko.js files. This method doesn't find the control character. I think that the selection does not work inside script tags (in fac I am almost sure about that). So I think the best solution is to check if the cursor is inside a script tag (in the setCC method) and if that's the case, place the cursor right before or right after that script tag.

You can e-mail me at: joris [at] prezent [dot] nl

Change History (4)

comment:1 Changed 9 years ago by ray

Your analysis is absolutely right. Unfortunately I have no clue for the regex that would do the job. If anyone can make one up, please speak up :)

comment:2 Changed 9 years ago by guest

You could use the following Regexpr / replace to move the control character outside the script tags, the only problem I have with this construction, is that I don't know how to use the unicode character in my RegExp?. CONTROLCHARACTER should be replaced by the control character code.

string.replace(/(<script[^>]*>)(.*?)(CONTROLCHARACTER)(.*?)(<\/script>)/, "$3$1$2$4$5");

I don't have much time to investigate this now, maybe I will sort it out later.

comment:3 Changed 9 years ago by ray

  • Summary changed from Control character is not being removed inside SCRIPT tags when switching from textmode to htmlmode. to Control character is not being removed inside SCRIPT tags or HEAD when switching from textmode to htmlmode.

comment:4 Changed 9 years ago by ray

  • Resolution set to fixed
  • Status changed from new to closed

fixed rev [898], also for cursor inside head/before body

Note: See TracTickets for help on using tickets.