18/06/2014 14:49, Scott Kostyshak:
Often when using LyX I come across empty selections. The easiest way
to see what I mean by an empty selection is to select one character to
the right, then select one character to the left (this will undo the
first). Such issues are annoying for a few reasons:

(1) some functions behave differently depending on whether there is a
selection. If you press delete, nothing happens (where I expect the
character or inset before the cusor to be deleted). If you toggle bold
or emphasize nothing happens (where if there is no selection the
entire word is toggled). There are other LyX functions that depend on
whether there is a selection or not. Further, I wonder if any part of
LyX's code assumes that if there is a selection it is non-empty.

(2) menu options are incorrectly set. For example, the scissors icon.

What about having Cursor::selection() return false if selection is empty?

I don't know how to fix these at the core, in Cursor::selHandle(bool
sel) or Cursor::setSelection(). I think the following comment in
Cursor::setSelection is relevant:

         // A selection with no contents is not a selection
         // FIXME: doesnt look ok
         if (idx() == normalAnchor().idx() &&
             pit() == normalAnchor().pit() &&
             pos() == normalAnchor().pos())
                 setSelection(false);

I think like Richard that the comment is incorrect.

Does someone have an idea to fix it there?

Get rid of setSelection(bool). Use selHandle whenever possible.

Set transient selection mode (M-x mark-on) and move with regular cursor commands. It will show you places when selection is suddenly reset. This is not good.

Attached are patches that fix the selection issues one by one. The
final patch adds an assertion that the selection is not empty. The
patches do not feel right for a few reasons. Mainly though I think it
should be fixed in Cursor::setSelection().

The patches that add extra checks all over the code are not a good idea. Our helper code should be good enough for what we want to do.

JMarc

Reply via email to