summaryrefslogtreecommitdiff
path: root/alot/widgets
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2021-01-17 15:37:51 +0100
committerAnton Khirnov <anton@khirnov.net>2021-01-18 12:09:05 +0100
commit3c34f37a0ef353fd4eeefc6e3019260719836beb (patch)
treed831c05d8715071ff0fbe5bf38a1ca35fe0328df /alot/widgets
parent60107e18edacf4a53a66145a3888d394746a8a1d (diff)
widgets/thread: fix processing quote blocks into folding tree
Diffstat (limited to 'alot/widgets')
-rw-r--r--alot/widgets/thread.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/alot/widgets/thread.py b/alot/widgets/thread.py
index a1512679..b0276eb0 100644
--- a/alot/widgets/thread.py
+++ b/alot/widgets/thread.py
@@ -349,7 +349,7 @@ class _TextPart(_MIMEPartWidget):
b['level'] = merge_level
fold_stack = []
- cur_fold = _Fold(0, 0, None)
+ cur_fold = _Fold(0, 0, 0)
max_level = 0
for b in blocks:
max_level = max(max_level, b['level'])
@@ -357,14 +357,19 @@ class _TextPart(_MIMEPartWidget):
if b['level'] > cur_fold.level:
fold_stack.append(cur_fold)
cur_fold = _Fold(b['level'], b['start'], b['end'])
- elif b['level'] == cur_fold.level:
- cur_fold.end = b['end']
else:
- child = cur_fold
+ while b['level'] < cur_fold.level:
+ child = cur_fold
+
+ if fold_stack[-1].level < cur_fold.level - 1:
+ cur_fold = _Fold(cur_fold.level - 1, cur_fold.start, cur_fold.end)
+ else:
+ cur_fold = fold_stack.pop()
+
+ cur_fold.children.append(child)
+ cur_fold.end = max(cur_fold.end, child.end)
- cur_fold = fold_stack.pop()
cur_fold.end = b['end']
- cur_fold.children.append(child)
while fold_stack:
fold_stack[-1].children.append(cur_fold)