Maintain cursor location between WYSIWYG and HTML

Maintain cursor location between WYSIWYG and HTML

by Theo Hughes -
Number of replies: 10

I'm finding it a great pain that the cursor location is not maintained when switching between WYSIWYG and HTML. Given the need to tidy up messy HTML created by atto, or add html for which a button/function is not available... then the fact you have to search through the HTML for what you were looking at in the WYSIWYG view (and vice versa) is VERY time consuming.

For short pieces of HTML, no problem. Anything vaguely long starts becoming an issue.

I am thinking of putting a feature request into tracker about this but thought I'd check with others first (about this and some other ones I'll make posts about after this). If people agree with me then maybe they'll vote etc. the tracker issue if I put it in.

Then again, perhaps no one / not many use such long sections that tit's a problem for them?

However, even for very short bits of text, I'm guessing it would be a big bonus for people not so familiar with HTML to immediately jump to the point in the HTML underlying what they see in WYSIWYG view?

Average of ratings: -
In reply to Theo Hughes

Re: Maintain cursor location between WYSIWYG and HTML

by Theo Hughes -
Disappointing there has been no replies to this. Perhaps no one else finds it an issue? I might try tracker just to see.

Meanwhile I've made a simple code update (few lines) to my local atto editor to go to the location in the html when switching from WYSIWYG (just before the code switches to HTML / CodeMirror it adds a marker, then in CodeMirror finds it, sets the cursor to that location, and then removes the marker) - though I'm sure others might have better code solutions.
In reply to Theo Hughes

Re: Maintain cursor location between WYSIWYG and HTML

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers
Yes, I like the idea. I get most disturbed when I want to add an emoticon. If you open a Tracker item, I would vote for it.
In reply to Rick Jerz

Re: Maintain cursor location between WYSIWYG and HTML

by Theo Hughes -
Hi Rick,

That's great to hear... though I don't quite understand your example involving an emoticon. Perhaps you could elaborate?

By the way, my current code only does the most basic functionality (and least likely to cause a bug) so:

- It only keeps your location switching to HTML, and then it only puts you at the beginning of the line at which the first point of your current selection was at.

- If you switch back to WYSIWYG it doesn't keep the location you moved to in the html - I wasn't so fussed about this and there was a few things that one has to be careful about that I couldn't be bothered to iron out.

So I'm curious what level of functionality you, or anyone else, cared about, for example:

- Switching to html, would you want the whole selection maintained (possible, just some more lines of code)? i.e. if you had a whole sentence highlighted, would you want the corresponding html highlighted or is it OK just to have the cursor at the beginning of the line on which that sentence starts?

- Do you care about maintaining location switching back to WYSIWYG?

Best wishes, Theo
In reply to Theo Hughes

Re: Maintain cursor location between WYSIWYG and HTML

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers

Actually, my problem (suggestion) is a little different.  When I switch between regular and "advanced" modes, the cursor position is not maintained.  (Sorry about the confusion.)

In reply to Rick Jerz

Re: Maintain cursor location between WYSIWYG and HTML

by Theo Hughes -
No worries. Though I'm curious as to what you mean by "regular" and "advanced".
In reply to Theo Hughes

Re: Maintain cursor location between WYSIWYG and HTML

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers
When I first click "Reply" (to your post), I am in regular editor mode. Then if I click on Advanced, I get more editor features. I believe that the cursor position is not maintained. In this post, my cursor is at the end of the paragraph. If I click Advanced, it is at the beginning of the paragraph.
Attachment advanced.png
In reply to Rick Jerz

Re: Maintain cursor location between WYSIWYG and HTML

by Theo Hughes -
Of course! Apologies. I was thinking about when, for example, an author edits a page etc. I was not thinking about forum posts.

I've got to say that I hadn't come across that problem. I'd either be typing a "basic" reply as now, or click "Advanced" straight away to create a more "designed" reply.

Also, even if I started typing and then click Advanced, I'm not sure my forum posts would be long enough or complex enough to worry.

However, I agree that it seems odd that it would not maintain the cursor position in this case... and I can see that it would be mildly disturbing.
In reply to Theo Hughes

Re: Maintain cursor location between WYSIWYG and HTML

by Theo Hughes -
My initial post is more about extensive authoring of content (often going back and editing)... and I like "clean" html (helps with ensuring it behaves nicely, especially on mobile... otherwise you can get some odd things.

A basic example being odd line breaks due to unintended   which you cannot see in WYSWIG... though I think you should be able to toggle to see, and is another feature that should be added to atto... could potentially even void most/many needs for toggling to HTML view).

Also, I like keeping my semantics and styling as separated as possible to aid design changes... e.g. if I want to change how I have styled "points to remember" in my text, I can just make one change to my css rather than having to go through hundreds of pages to change each one individually.
In reply to Theo Hughes

Re: Maintain cursor location between WYSIWYG and HTML

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers

Yep, different scenarios, but both involving the ATTO editor.  I have no clue if they are related.

In reply to Rick Jerz

Re: Maintain cursor location between WYSIWYG and HTML

by Theo Hughes -
They are related somewhat in use. Not related in code. If you switch to "advanced" that remains "within the atto code" (I'm guessing, haven't actually looked at the code. Whereas the switch to html actually switches out the atto editor for one that uses Code Mirror.