From 78772ca58ce4c36d69e70b0738ad535e6d968305 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Thu, 9 Apr 2009 18:29:55 +0000 Subject: [PATCH] Should fix the problems with dirty selection left-overs when editing and also other situations. Basically, I made DeleteText() adjust the selection according to the deleted range. Some places where DeleteText() was called forgot to adopt the selection. Other places adopted the selection. Maybe some of those could be removed now, but some also change fClickOffset, so I just left them as they are. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30076 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/TextView.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/kits/interface/TextView.cpp b/src/kits/interface/TextView.cpp index 4c8a819990..054619388a 100644 --- a/src/kits/interface/TextView.cpp +++ b/src/kits/interface/TextView.cpp @@ -3037,6 +3037,28 @@ BTextView::DeleteText(int32 fromOffset, int32 toOffset) // remove any style runs that have been obliterated fStyles->RemoveStyleRange(fromOffset, toOffset); + + // adjust the selection accordingly, assumes fSelEnd >= fSelStart! + int32 range = toOffset - fromOffset; + if (fSelStart >= toOffset) { + // selection is behind the range that was removed + fSelStart -= range; + fSelEnd -= range; + } else if (fSelStart >= fromOffset && fSelEnd <= toOffset) { + // the selection is within the range that was removed + fSelStart = fSelEnd = fromOffset; + } else if (fSelStart >= fromOffset && fSelEnd > toOffset) { + // the selection starts within and ends after the range + // the remaining part is the part that was after the range + fSelStart = fromOffset; + fSelEnd = fromOffset + fSelEnd - toOffset; + } else if (fSelStart < fromOffset && fSelEnd < toOffset) { + // the selection starts before, but ends within the range + fSelEnd = fromOffset; + } else if (fSelStart < fromOffset && fSelEnd >= toOffset) { + // the selection starts before and ends after the range + fSelEnd -= range; + } } @@ -3341,7 +3363,6 @@ BTextView::_HandleDelete() Highlight(fSelStart, fSelEnd); DeleteText(fSelStart, fSelEnd); - fClickOffset = fSelEnd = fSelStart; _Refresh(fSelStart, fSelEnd, true, true);