I'd like to say a few words relating to the crash that #627
<https://github.com/leo-editor/leo-editor/issues/627> fixes.
*Prefer positions to vnode in calling conventions*
The reason is straightforward. Positions contain more information than
vnodes.
Given a position p, p.v is its unique vnode. But given a node v, there may
be several positions p with v == p.v.
*The crash was more than botched call*
1. In several places, I replaced code like:
for v in self.c.all_unique_nodes():
p = self.c.vnode2position(v)
with:
for p in self.c.all_unique_positions():
This is a direct application of the principle that positions carry more
data than vnodes.
2. If I have recreated the diffs properly, the old version of item_selected
was:
def item_selected(self):
c = self.c
key = id(self.listWidget.currentItem())
v = self.mapping[key]
pos = c.vnode2position(v)
self.update_current_tags(pos)
c.selectPosition(pos)
c.redraw()
The corrected version of item_selected method is:
def item_selected(self):
c = self.c
key = id(self.listWidget.currentItem())
v = self.mapping[key]
if isinstance(v, leoNodes.VNode):
p = c.vnode2position(v)
assert isinstance(p, leoNodes.Position), repr(p)
self.update_current_tags(p)
c.selectPosition(p)
c.redraw()
self.mapping can contain either vnodes or positions, so the new code is
more robust and more explicit.
Neither type checking nor convention checking would be able to create the
improved code. Neither type checking nor convention checking would be able
to detect any problem at all without lots of help.
3. The nodetags.py plugins caches vnodes. This is fine as long the plugin
(in effect) recreates the cache when the outline changes.
*Summary*
#632 <https://github.com/leo-editor/leo-editor/issues/632> (convention
checking) envisages a tool that would not have completely fixed #627
<https://github.com/leo-editor/leo-editor/issues/627>.
Rather than relying on a non-existent tool to distinguish vnodes from
positions, devs should use positions wherever possible.
In any case, devs must remember that positions *will* become invalid when
the outline changes.
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.