commit 0af6a43b6aec8ccc4afe36545a76cd6be727c7b6
Author: Scott Kostyshak <[email protected]>
Date: Fri Jul 27 15:28:22 2018 -0400
Fix crash when selecting text with changes
When selecting text, in some cases a DocIterator could be forwarded
to a (non-existant) paragraph after the end. The critical part of
this fix is to break the loop at the correct place. The following
are additional improvements:
- increase readability by defining a bool named "in_last_par"
- use cur.selectionEnd().pit() instead of
cur.selectionEnd().paragraph().id()
- use it.lastpos() instead of it.paragraph().size()
This commit fixes a regression introduced by 23de5e5e, and reported
at #11204.
Thanks to Jürgen and JMarc.
(cherry picked from commit d12798759aeb7bae77bec63098fd81f8cc9e554b)
---
src/Text3.cpp | 9 ++++++---
1 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/src/Text3.cpp b/src/Text3.cpp
index e75fad0..b5f9e33 100644
--- a/src/Text3.cpp
+++ b/src/Text3.cpp
@@ -3207,17 +3207,20 @@ bool Text::getStatus(Cursor & cur, FuncRequest const &
cmd,
if (!cur.buffer()->areChangesPresent())
break;
- for (DocIterator it = cur.selectionBegin(); it <
cur.selectionEnd(); it.forwardPar()) {
+ for (DocIterator it = cur.selectionBegin(); ;
it.forwardPar()) {
pos_type const beg = it.pos();
pos_type end;
- if (it.paragraph().id() ==
cur.selectionEnd().paragraph().id())
+ bool const in_last_par = (it.pit() ==
cur.selectionEnd().pit());
+ if (in_last_par)
end = cur.selectionEnd().pos();
else
- end = it.paragraph().size();
+ end = it.lastpos();
if (beg != end && it.paragraph().isChanged(beg,
end)) {
enable = true;
break;
}
+ if (in_last_par)
+ break;
}
}
break;