Reworked Selection, as it was simply broken before. Still not 100% correct

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8449 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2004-07-22 09:40:40 +00:00
parent ce1f504a6d
commit a901231dac
+76 -56
View File
@@ -1304,7 +1304,7 @@ BTextView::GoToLine(int32 index)
{ {
CALLED(); CALLED();
CancelInputMethod(); CancelInputMethod();
fSelStart = fSelEnd = OffsetAt(index); fSelStart = fSelEnd = fClickOffset = OffsetAt(index);
} }
@@ -2788,7 +2788,7 @@ BTextView::HandleBackspace()
Highlight(fSelStart, fSelEnd); Highlight(fSelStart, fSelEnd);
DeleteText(fSelStart, fSelEnd); DeleteText(fSelStart, fSelEnd);
fSelEnd = fSelStart; fClickOffset = fSelEnd = fSelStart;
Refresh(fSelStart, fSelEnd, true, false); Refresh(fSelStart, fSelEnd, true, false);
} }
@@ -2807,47 +2807,55 @@ BTextView::HandleArrowKey(uint32 inArrowKey)
int32 selStart = fSelStart; int32 selStart = fSelStart;
int32 selEnd = fSelEnd; int32 selEnd = fSelEnd;
//int32 delta = 0;
int32 scrollToOffset = 0; int32 scrollToOffset = 0;
bool shiftDown = modifiers() & B_SHIFT_KEY; bool shiftDown = modifiers() & B_SHIFT_KEY;
switch (inArrowKey) { switch (inArrowKey) {
case B_LEFT_ARROW: case B_LEFT_ARROW:
if (fClickOffset > 0)
fClickOffset = PreviousInitialByte(fClickOffset);
if (shiftDown) { if (shiftDown) {
if (selStart > 0) if (fClickOffset > fSelStart)
selStart = PreviousInitialByte(selStart); selEnd = fClickOffset;
} else { else
if (selStart == selEnd) { selStart = fClickOffset;
if (selStart > 0) } else
selEnd = selStart = PreviousInitialByte(selStart); selStart = selEnd = fClickOffset;
} else
selEnd = selStart;
}
scrollToOffset = selStart; scrollToOffset = selStart;
break; break;
case B_RIGHT_ARROW: case B_RIGHT_ARROW:
if (fClickOffset < fText->Length())
fClickOffset = NextInitialByte(fClickOffset);
if (shiftDown) { if (shiftDown) {
if (selEnd < fText->Length()) if (fClickOffset < fSelEnd)
selEnd = NextInitialByte(selEnd); selStart = fClickOffset;
} else {
if (selStart == selEnd) {
if (selStart < fText->Length())
selStart = selEnd = NextInitialByte(selEnd);
}
else else
selStart = selEnd; selEnd = fClickOffset;
} } else
selStart = selEnd = fClickOffset;
scrollToOffset = selEnd; scrollToOffset = selEnd;
break; break;
case B_UP_ARROW: case B_UP_ARROW:
{ {
BPoint point = PointAt(selStart); float height;
point.y--; BPoint point = PointAt(fClickOffset, &height);
selStart = OffsetAt(point); point.y -= height;
if (!shiftDown) fClickOffset = OffsetAt(point);
selEnd = selStart; if (shiftDown) {
if (fClickOffset > fSelStart)
selEnd = fClickOffset;
else
selStart = fClickOffset;
} else
selStart = selEnd = fClickOffset;
scrollToOffset = selStart; scrollToOffset = selStart;
break; break;
} }
@@ -2855,11 +2863,17 @@ BTextView::HandleArrowKey(uint32 inArrowKey)
case B_DOWN_ARROW: case B_DOWN_ARROW:
{ {
float height; float height;
BPoint point = PointAt(selEnd, &height); BPoint point = PointAt(fClickOffset, &height);
point.y += height; point.y += height;
selEnd = OffsetAt(point); fClickOffset = OffsetAt(point);
if (!shiftDown) if (shiftDown) {
selStart = selEnd; if (fClickOffset < fSelEnd)
selStart = fClickOffset;
else
selEnd = fClickOffset;
} else
selStart = selEnd = fClickOffset;
scrollToOffset = selEnd; scrollToOffset = selEnd;
break; break;
} }
@@ -2900,7 +2914,7 @@ BTextView::HandleDelete()
DeleteText(fSelStart, fSelEnd); DeleteText(fSelStart, fSelEnd);
fSelEnd = fSelStart; fClickOffset = fSelEnd = fSelStart;
Refresh(fSelStart, fSelEnd, true, true); Refresh(fSelStart, fSelEnd, true, true);
} }
@@ -2910,26 +2924,28 @@ BTextView::HandlePageKey(uint32 inPageKey)
{ {
CALLED(); CALLED();
int32 modifiers = 0; int32 mods = 0;
BMessage *currentMessage = Window()->CurrentMessage(); /*BMessage *currentMessage = Window()->CurrentMessage();
if (currentMessage) if (currentMessage)
currentMessage->FindInt32("modifiers", &modifiers); currentMessage->FindInt32("modifiers", &mods);
*/
bool shiftDown = modifiers & B_SHIFT_KEY; mods = modifiers();
bool shiftDown = mods & B_SHIFT_KEY;
int32 newOffset;
STELinePtr line = NULL; STELinePtr line = NULL;
switch (inPageKey) { switch (inPageKey) {
case B_HOME: case B_HOME:
line = (*fLines)[CurrentLine()]; line = (*fLines)[CurrentLine()];
newOffset = line->offset; fClickOffset = line->offset;
ScrollToOffset(newOffset); ScrollToOffset(fClickOffset);
if (shiftDown) if (shiftDown) {
Select(newOffset, fSelStart); if (fClickOffset <= fSelStart)
else Select(fClickOffset, fSelEnd);
Select(newOffset, newOffset); else
Select(fSelStart, fClickOffset);
} else
Select(fClickOffset, fClickOffset);
break; break;
case B_END: case B_END:
@@ -2938,15 +2954,18 @@ BTextView::HandlePageKey(uint32 inPageKey)
// offset of the next line, and go to the previous charachter // offset of the next line, and go to the previous charachter
if (CurrentLine() + 1 < fLines->NumLines()) { if (CurrentLine() + 1 < fLines->NumLines()) {
line = (*fLines)[CurrentLine() + 1]; line = (*fLines)[CurrentLine() + 1];
newOffset = PreviousInitialByte(line->offset); fClickOffset = PreviousInitialByte(line->offset);
} else } else
newOffset = fText->Length(); fClickOffset = fText->Length();
ScrollToOffset(newOffset); ScrollToOffset(fClickOffset);
if (shiftDown) if (shiftDown) {
Select(fSelEnd, newOffset); if (fClickOffset >= fSelEnd)
else Select(fSelStart, fClickOffset);
Select(newOffset, newOffset); else
Select(fClickOffset, fSelEnd);
} else
Select(fClickOffset, fClickOffset);
break; break;
case B_PAGE_UP: case B_PAGE_UP:
@@ -3002,7 +3021,7 @@ BTextView::HandleAlphaKey(const char *bytes, int32 numBytes)
else*/ else*/
InsertText(bytes, numBytes, fSelStart, NULL); InsertText(bytes, numBytes, fSelStart, NULL);
fSelEnd = fSelStart = fSelStart + numBytes; fClickOffset = fSelEnd = fSelStart = fSelStart + numBytes;
Refresh(fSelStart, fSelEnd, refresh, true); Refresh(fSelStart, fSelEnd, refresh, true);
} }
@@ -3054,7 +3073,7 @@ BTextView::Refresh(int32 fromOffset, int32 toOffset, bool erase,
toLine = min_c(toLine, toVisible); toLine = min_c(toLine, toVisible);
int32 drawOffset = fromOffset; int32 drawOffset = fromOffset;
if ( LineHeight(fromLine) != saveLineHeight || if (LineHeight(fromLine) != saveLineHeight ||
newHeight < saveHeight || fromLine < saveFromLine ) newHeight < saveHeight || fromLine < saveFromLine )
drawOffset = (*fLines)[fromLine]->offset; drawOffset = (*fLines)[fromLine]->offset;
@@ -4090,7 +4109,7 @@ BTextView::HandleInputMethodChanged(BMessage *message)
if (fInline->IsActive()) { if (fInline->IsActive()) {
int32 oldOffset = fInline->Offset(); int32 oldOffset = fInline->Offset();
DeleteText(oldOffset, oldOffset + fInline->Length()); DeleteText(oldOffset, oldOffset + fInline->Length());
Select(oldOffset, oldOffset); fSelStart = fSelEnd = oldOffset;
} }
int32 stringLen = strlen(string); int32 stringLen = strlen(string);
@@ -4100,8 +4119,9 @@ BTextView::HandleInputMethodChanged(BMessage *message)
// Insert the new text // Insert the new text
InsertText(string, stringLen, fSelStart, NULL); InsertText(string, stringLen, fSelStart, NULL);
Select(fSelStart + stringLen, fSelStart + stringLen); fSelStart += stringLen;
fClickOffset = fSelEnd = fSelStart;
Refresh(0, fLines->NumLines(), true, false); Refresh(0, fLines->NumLines(), true, false);
// If we find the "be:confirmed" boolean (and the boolean is true), // If we find the "be:confirmed" boolean (and the boolean is true),