Scott Kostyshak
2014-06-18 12:49:46 UTC
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.
Here are some situations where empty selection occur(ed):
- when dragging in math mode (now fixed, see #9074)
- when spell checking (now fixed, see a117a512)
- when you click and drag slightly on a reference inset.
- when dragging inside an empty table cell.
- if you go select up and then select down inside an empty table cell.
- write some text, put your cursor in the middle of it, do shift
right, then shift left. Selection is set and delete does nothing.
- similar to previous, do the same in math mode. Also in text, do
ctrl+shift+right, then ctrl+shift+left.
- write a few words, then with the mouse click and drag upwards
(without moving horizontally). Note, however, that the selection is
removed on mouse release, but you can see that the scissors icon
became active.
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);
Does someone have an idea to fix it there?
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().
Any thoughts?
Scott
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.
Here are some situations where empty selection occur(ed):
- when dragging in math mode (now fixed, see #9074)
- when spell checking (now fixed, see a117a512)
- when you click and drag slightly on a reference inset.
- when dragging inside an empty table cell.
- if you go select up and then select down inside an empty table cell.
- write some text, put your cursor in the middle of it, do shift
right, then shift left. Selection is set and delete does nothing.
- similar to previous, do the same in math mode. Also in text, do
ctrl+shift+right, then ctrl+shift+left.
- write a few words, then with the mouse click and drag upwards
(without moving horizontally). Note, however, that the selection is
removed on mouse release, but you can see that the scissors icon
became active.
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);
Does someone have an idea to fix it there?
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().
Any thoughts?
Scott