TextEdit edit mode lost after undo...shouldn't be deselected
repo steps:
1. start with default "Untitled" score
2. double click the Title text
3. select the first character ('T')
4. cut it (ctrl->X)
5. click between the 'i' and 't'
6. paste it (ctrl->V)
7. undo that (ctrl->Z)
8. paste again (ctrl->V)
9. select the first character ('i')
10. cut it (ctrl->X)
Observe a strange upward arrow symbol:
Note that the moment user clicks outside of the textbox, that strange symbol dissapears. But it is still indicative that there is some corruption going on, possibly either in the undo stack or in the text.
On MuseScore 3.0 rc1 OS: Windows 10 (10.0), Arch.: x86_64, MuseScore version (64-bit): 3.0.0.4747, revision: 96c1f7b
(Aside: I also notice I can create some corruptions in 2.3.2, but that is without using the undo command which is actually not allowed in 2.3.2)
Comments
I will fix this as I discovered it while fixing:
#280504: Unicode surrogate-pair text cutting and pasting and undoing produces corruption
While at first I thought this issue had to do with Supplemental Unicode handling in that issue, it turns out that this problem can be produced seemingly related, these are separate issues. But I will fix it together, as they still deal with similar code.
Simplified, more minimal reproduction steps:
Result, the 'a' turns into an up arrow.
Again, clicking outside of textbox seems to fix the glitch.
Even more simplified minimal steps (probably as minimal as can get):
recording of the bug:
What I'm discoverring is strange...when the final cut is performed, for some reason in
void ScoreView::keyPressEvent(QKeyEvent* ev)
the line
editData.s = ev->text();
gets assigned to a string with 1 entry 0x18 which turns out to be the mysterious up arrow (http://www.fileformat.info/info/unicode/char/18/index.htm which calls it "CANCEL").
So maybe the whole problem has nothing to do with stack being corrputed? I will have to see why hat ev->txt() contains the up arrow....
So I've determined that it has nothing to do with undo stack being corrupted. Rather what it is is that upon the last undo, ScoreView's state get's set incorrectly and so ScoreView::keyPressEvent() performs a test state != ViewState::EDIT, which messes everything up, such that the user subsequently enters special characters produced by holding Ctrl and the keys. It turns out that Ctrl->X produces the special unicode character of an uparrow that means "CANCEL". And other funny chracters can be produced with other key combinations.
Here is an illustration of how after the edit mode disappears (when text no longer becomes blue), then I can press other Ctrl->key combinations like Ctrl->x, Ctrl->c, Ctrl->v, Ctrl->b which are interpreted as their actual unicode text, rather than as the special commands they should be:
So the absolute minimal repro steps can be created by causing an undo to happen. Step 1 here is
commit 68f87040f8b92fd4a588f5997b7fbc74cb5a17be sems suspect....particularly the
score->deselectAll();
in UndoMacro::undo(). If I comment that out, then the text edit works, since it doesn't get deselected. So I guess the solution might lie in not deselecting everything if in text edit mode. I don't know quite the best wa to check if in text edit mode, though....
I figured out the problem and have a basic PR, but I honestly don't know if this is the best way to determine if user is currently editing a text box: https://github.com/musescore/MuseScore/pull/4501
Fixed in branch master, commit 6f07a47e41
fix #280522 undo text edit keep TextBase selected
Previously when undid an edit in a TextBase element, that TextBase element would be unintentionally deselected, resulting in subsequent inputs with Ctrl-> to produced undesired unicode values instead of performing their typical commands of cut, copy, etc.
This commit tries to make sure TextBase elements aren't deselected if undid an edit that was simply for text in that textedit box.
Dmitrio suggeseted adding TextBase to the list of elements for which single selection will be restored, and that works.
Fixed in branch master, commit 657d2adcb3
Merge pull request #4501 from ericfont/280522-dont-deselect-texedit-box-on-undo
fix #280522 undo text edit keep TextBase selected
Automatically closed -- issue fixed for 2 weeks with no activity.