manuskript/manuskript/ui
Jan Wester 12390a9aab Fix occasional crashes when (re)moving items
Describing all the rabbitholes that I and kakaroto have gone through
while debugging this one until dawn can frankly not do enough justice to
the crazy amount of rubberducking that went on while trying to fix this.

This bug would be triggered whenever you had a document open in the
editor and then moved an ancestor object downwards (visually) in the tree.
Or when you simply deleted the ancestor. Depending on the exact method
that caused the opened item to be removed from the internal model, the
exact nature of the bug would vary, which means this commit fixes a few
different bits of code that lead to what appears to be the same bug.

In order of appearance, the bugs that ruined our sleep were:

1) The editor widget was trying to handle the removed item at too late a
stage.

2) The editor widget tried to fix its view after a move by searching for
the new item with the same ID, but in the case of moving an object down
it came across its own old item, ruining the attempt.

3) The editor widget did not properly account for the hierarchical
nature of the model.

Upon fixing these the next day, it was revealed that:

4) The outlineItem.updateWordCount(emit=False) flag is broken. This
function would call setData() in several spots which would still cause
emits to bubble through the system despite emit=False, and we simply got
lucky that it stopped enough of them until now.

This last one was caused by a small mistake in the fixes for the first
three bugs, but it has led to a couple of extra changes to make any
future bug hunts slightly less arduous and frustrating:

a) When calling item.removeChild(c), it now resets the associated parent
and model to mirror item.insertChild(c). This has also led to an extra
check in model.parent() to check for its validity.

b) The outlineItem.updateWordCount(emit=) flag has been removed entirely
and it now emits away with reckless abandon. I have been unable to
reproduce the crashes the code warned about, so I consider this a code
quality fix to prevent mysterious future issues where things sometimes
do not properly update right.

Worthy of note is that the original code clearly showed the intention to
close tabs for items that were removed. Reworking the editor to support
closing a tab is unfortunately way out of scope, so this intention was
left in and the new fix was structured to make it trivial to implement
such a change when the time comes. An existing FIXME regarding unrelated
buggy editor behaviour was left in, too.

Many thanks to Kakaroto for burning the midnight oil with me to get to
the bottom of this. (I learned a lot that night!)

Issues #479, #516 and #559 are fixed by this commit. And maybe some others,
too.
2019-05-19 09:33:19 -06:00
..
editors Fix occasional crashes when (re)moving items 2019-05-19 09:33:19 -06:00
exporters Ensure text file open methods use utf-8 encoding 2019-02-27 09:30:16 -07:00
highlighters Add a Spellchecker abstraction layer and clean up code 2019-04-30 09:54:31 -06:00
importers Fix spelling mistake "chose" should be "choose" 2019-02-07 12:34:57 -07:00
tools Fix typos that are visible to end-users. 2018-01-29 10:30:41 -07:00
views Fix occasional crashes when (re)moving items 2019-05-19 09:33:19 -06:00
__init__.py Renaming source folder 2016-02-06 08:38:33 +01:00
about.py Update copyright year 2019-04-04 10:33:08 -06:00
about_ui.py Put software version in one sigle label to allow easier copy/pasting 2017-10-11 08:32:44 +02:00
about_ui.ui Put software version in one sigle label to allow easier copy/pasting 2017-10-11 08:32:44 +02:00
cheatSheet.py Clear Cheatsheet results when filter text empty 2018-08-14 09:04:00 -06:00
cheatSheet_ui.py Flatified a lot of buttons, and added some stylesheets 2016-04-08 14:49:15 +02:00
cheatSheet_ui.ui Flatified a lot of buttons, and added some stylesheets 2016-04-08 14:49:15 +02:00
collapsibleDockWidgets.py Fix typos in code comments, invisible to end-users. 2018-01-29 10:30:41 -07:00
collapsibleGroupBox.py Removes most of hard-coded colors 2017-11-14 14:56:11 +01:00
collapsibleGroupBox2.py Removes most of hard-coded colors 2017-11-14 14:56:11 +01:00
helpLabel.py Cleaning up imports, at last 2016-02-06 12:34:22 +01:00
mainWindow.py Remove unimplemented snowflake view mode menu entry 2018-11-30 09:42:42 -07:00
mainWindow.ui Remove unimplemented snowflake view mode menu entry 2018-11-30 09:42:42 -07:00
revisions.py Changes Outline enums to IntEnum 2017-11-15 20:58:12 +01:00
revisions_ui.py Adds a few more icons 2017-10-16 10:48:04 +02:00
revisions_ui.ui Adds a few more icons 2017-10-16 10:48:04 +02:00
search.py Fix typos in code comments, invisible to end-users. 2018-01-29 10:30:41 -07:00
search_ui.py Some more UI tweaks 2016-04-12 00:01:51 +02:00
search_ui.ui Some more UI tweaks 2016-04-12 00:01:51 +02:00
settings_ui.py Fix typos that are visible to end-users. 2018-01-29 10:30:41 -07:00
settings_ui.ui Spelling: Manuscript, may have to be restarted (#454) 2019-01-10 10:26:14 -07:00
statusLabel.py Fixes #307: Overlay status bar prevents access to add/delete world item icons when displaying a message 2018-01-22 18:19:22 +01:00
style.py Fix typos in code comments, invisible to end-users. 2018-01-29 10:30:41 -07:00
welcome.py Open/Save As/Create last accessed directory 2018-12-07 12:01:33 -07:00
welcome_ui.py Fix typos that are visible to end-users. 2018-01-29 10:30:41 -07:00
welcome_ui.ui Fix typos that are visible to end-users. 2018-01-29 10:30:41 -07:00