This is an Engineering Notebook post discussing work to be done in the 
color branch. Feel free to ignore unless you are one of Leo's devs.

*tl;dr:* Read the summary.

This post affects three issues:

#388: wikiview.py plugin problem with new colorizing code 
<https://github.com/leo-editor/leo-editor/issues/388>

#372: Support something like emacs electric url's 
<https://github.com/leo-editor/leo-editor/issues/372>

#396: Show images in Leo's body pane 
<https://github.com/leo-editor/leo-editor/issues/396>

*Hiding text*

There are two fundamental tasks:

1. Toggling between showing "raw" urls and more human-readable versions.

2. Toggling between <img> elements and the pictures to which they refer.

Each involves *hiding text* while colorizing it. The wikiview plugin does 
this by setting point size to 0.1. Other approaches would be to alter 
fonts, pens or layouts in order to complete hide text. In any case, the 
guiding principle must be:

    *The colorizer is never allowed to change text*

This principle can be paraphrased as:

    *What happens in the colorizer, stays in the colorizer*

It would be suicidally bad design to allow the colorizer to change text, 
even temporarily. Doing so could cause time bombs that corrupt text.  We 
aren't going there, regardless of the complications in the colorizer itself.

*Strategy*
 
Hiding text should be straightforward:

- Several pattern matchers will change, in obvious ways.

- Pattern matches will *indicate *hidden text by calling colorRangeWithTag 
with "hidden" as the tag.

- Only setTag will actually hide text. As a prototype, setTag can color 
"hidden" text using a different color, say yellow.  The next step will be 
to use a small point size, as the wikiview plugin does. Finally, setTag 
might use do-nothing QFont, QPen or QLayout. setTag can do *anything*, 
provided that it *never *changes text.

*Handling pictures*

>From the docs for QTextImageFormat 
<http://doc.qt.io/qt-5/qtextimageformat.html>: Inline images are 
represented by a Unicode value U+FFFC (ord = 65532) which has an associated 
QTextImageFormat <http://doc.qt.io/qt-5/qtextimageformat.html>. Let's call 
such characters *picture characters*. 

I have just verified that this scheme allows multiple *different *images in 
text, each represented by the *same* picture character (ord = 65532). 
Presumably Qt maintains some hidden state. Leo will probably have to access 
this magic.

Pictures can be inserted into scripts, as long as they are in a comment. 
Tests show that Leo reads and writes picture characters correctly.  But 
that *doesn't *mean that picture characters will "just work".  In addition, 
Leo must do at least the following:

- Use uA's to associate replacement characters with images.

- Keep permanent references to pictures so they won't go away.

The colorizer can insert pictures characters as follows:

    widget.insertHtml('<img src="%s">' % path_to_picture)

This is an allowable (necessary) exception to the "no text changes" rule. 
The colorizer will have to check to see whether a picture character already 
follows each <img> element.

*Summary*

Issues #372 <https://github.com/leo-editor/leo-editor/issues/372> and #396 
<https://github.com/leo-editor/leo-editor/issues/396> are two aspects of 
the same problem. The colorizer will handle both.

The colorizer will replace the wikiview plugin. Issue #388 
<https://github.com/leo-editor/leo-editor/issues/388> is moot, and will be 
closed today. The wikiview plugin is deprecated, effective immediately.

jedit.setTag will hide text when called with tag='hidden'. It can hide text 
any way it likes, provided that it *never ever* changes text.

Hiding <img> tags will use the same machinery as hiding parts of urls. But 
full support for pictures will involve numerous complications. Happily, 
problems should be readily apparent.

All comments welcome.

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To post to this group, send email to leo-editor@googlegroups.com.
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.

Reply via email to