* fixed a couple of inconsistencies with respect to handling of cursor-

and paging-keys, especially extending the selection via shift was more or
  less broken


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30431 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Tappe
2009-04-26 16:19:27 +00:00
parent 107d2b333b
commit f7c48ade93
+125 -70
View File
@@ -1537,7 +1537,7 @@ BTextView::Select(int32 startOffset, int32 endOffset)
Highlight(start, end); Highlight(start, end);
} }
} }
fSelStart = fClickOffset = startOffset; fSelStart = startOffset;
fSelEnd = endOffset; fSelEnd = endOffset;
} }
} }
@@ -3251,7 +3251,7 @@ BTextView::_HandleArrowKey(uint32 inArrowKey)
bool shiftDown = modifiers & B_SHIFT_KEY; bool shiftDown = modifiers & B_SHIFT_KEY;
bool ctrlDown = modifiers & B_CONTROL_KEY; bool ctrlDown = modifiers & B_CONTROL_KEY;
int32 currentOffset = fClickOffset; int32 lastClickOffset = fClickOffset;
switch (inArrowKey) { switch (inArrowKey) {
case B_LEFT_ARROW: case B_LEFT_ARROW:
if (fSelStart != fSelEnd && !shiftDown) if (fSelStart != fSelEnd && !shiftDown)
@@ -3261,11 +3261,18 @@ BTextView::_HandleArrowKey(uint32 inArrowKey)
= ctrlDown = ctrlDown
? _PreviousWordBoundary(fClickOffset - 1) ? _PreviousWordBoundary(fClickOffset - 1)
: _PreviousInitialByte(fClickOffset); : _PreviousInitialByte(fClickOffset);
if (shiftDown && fClickOffset != currentOffset) { if (shiftDown && fClickOffset != lastClickOffset) {
if (fClickOffset >= fSelStart) if (fClickOffset < fSelStart) {
selEnd = fClickOffset; // extend selection to the left
else
selStart = fClickOffset; selStart = fClickOffset;
if (lastClickOffset > fSelStart) {
// caret has jumped across "anchor"
selEnd = fSelStart;
}
} else {
// shrink selection from the right
selEnd = fClickOffset;
}
} }
} }
break; break;
@@ -3278,27 +3285,43 @@ BTextView::_HandleArrowKey(uint32 inArrowKey)
= ctrlDown = ctrlDown
? _NextWordBoundary(fClickOffset) ? _NextWordBoundary(fClickOffset)
: _NextInitialByte(fClickOffset); : _NextInitialByte(fClickOffset);
if (shiftDown && fClickOffset != currentOffset) { if (shiftDown && fClickOffset != lastClickOffset) {
if (fClickOffset <= fSelEnd) if (fClickOffset > fSelEnd) {
selStart = fClickOffset; // extend selection to the right
else
selEnd = fClickOffset; selEnd = fClickOffset;
if (lastClickOffset < fSelEnd) {
// caret has jumped across "anchor"
selStart = fSelEnd;
}
} else {
// shrink selection from the left
selStart = fClickOffset;
}
} }
} }
break; break;
case B_UP_ARROW: case B_UP_ARROW:
{ {
float height; if (fSelStart != fSelEnd && !shiftDown)
BPoint point = PointAt(fClickOffset, &height); fClickOffset = fSelStart;
point.y -= height; else {
fClickOffset = OffsetAt(point); float height;
if (shiftDown) { BPoint point = PointAt(fClickOffset, &height);
if (fClickOffset != currentOffset) { point.y -= height;
if (fClickOffset >= fSelStart) fClickOffset = OffsetAt(point);
selEnd = fClickOffset; if (shiftDown && fClickOffset != lastClickOffset) {
else if (fClickOffset < fSelStart) {
// extend selection to the top
selStart = fClickOffset; selStart = fClickOffset;
if (lastClickOffset > fSelStart) {
// caret has jumped across "anchor"
selEnd = fSelStart;
}
} else {
// shrink selection from the bottom
selEnd = fClickOffset;
}
} }
} }
break; break;
@@ -3306,16 +3329,25 @@ BTextView::_HandleArrowKey(uint32 inArrowKey)
case B_DOWN_ARROW: case B_DOWN_ARROW:
{ {
float height; if (fSelStart != fSelEnd && !shiftDown)
BPoint point = PointAt(fClickOffset, &height); fClickOffset = fSelEnd;
point.y += height; else {
fClickOffset = OffsetAt(point); float height;
if (shiftDown) { BPoint point = PointAt(fClickOffset, &height);
if (fClickOffset != currentOffset) { point.y += height;
if (fClickOffset <= fSelEnd) fClickOffset = OffsetAt(point);
selStart = fClickOffset; if (shiftDown && fClickOffset != lastClickOffset) {
else if (fClickOffset > fSelEnd) {
// extend selection to the bottom
selEnd = fClickOffset; selEnd = fClickOffset;
if (lastClickOffset < fSelEnd) {
// caret has jumped across "anchor"
selStart = fSelEnd;
}
} else {
// shrink selection from the top
selStart = fClickOffset;
}
} }
} }
break; break;
@@ -3325,15 +3357,11 @@ BTextView::_HandleArrowKey(uint32 inArrowKey)
// invalidate the null style // invalidate the null style
fStyles->InvalidateNullStyle(); fStyles->InvalidateNullStyle();
currentOffset = fClickOffset;
if (shiftDown) if (shiftDown)
Select(selStart, selEnd); Select(selStart, selEnd);
else else
Select(fClickOffset, fClickOffset); Select(fClickOffset, fClickOffset);
fClickOffset = currentOffset;
// Select sets fClickOffset = fSelEnd
// scroll if needed // scroll if needed
ScrollToOffset(fClickOffset); ScrollToOffset(fClickOffset);
} }
@@ -3383,26 +3411,33 @@ BTextView::_HandlePageKey(uint32 inPageKey)
bool shiftDown = mods & B_SHIFT_KEY; bool shiftDown = mods & B_SHIFT_KEY;
bool ctrlDown = mods & B_CONTROL_KEY; bool ctrlDown = mods & B_CONTROL_KEY;
STELine* line = NULL; STELine* line = NULL;
int32 start = fSelStart, end = fSelEnd; int32 selStart = fSelStart;
int32 selEnd = fSelEnd;
int32 lastClickOffset = fClickOffset;
switch (inPageKey) { switch (inPageKey) {
case B_HOME: case B_HOME:
line = (*fLines)[CurrentLine()]; line = (*fLines)[LineAt(lastClickOffset)];
if (ctrlDown) if (ctrlDown)
fClickOffset = 0; fClickOffset = 0;
else else
fClickOffset = line->offset; fClickOffset = line->offset;
if (shiftDown) { if (!shiftDown)
if (fClickOffset <= fSelStart) { selStart = selEnd = fClickOffset;
start = fClickOffset; else if (fClickOffset != lastClickOffset) {
end = fSelEnd; if (fClickOffset < fSelStart) {
// extend selection to the left
selStart = fClickOffset;
if (lastClickOffset > fSelStart) {
// caret has jumped across "anchor"
selEnd = fSelStart;
}
} else { } else {
start = fSelStart; // shrink selection from the right
end = fClickOffset; selEnd = fClickOffset;
} }
} else }
start = end = fClickOffset;
break; break;
@@ -3413,11 +3448,12 @@ BTextView::_HandlePageKey(uint32 inPageKey)
// If we are on the last line, just go to the last // If we are on the last line, just go to the last
// character in the buffer, otherwise get the starting // character in the buffer, otherwise get the starting
// offset of the next line, and go to the previous character // offset of the next line, and go to the previous character
if (CurrentLine() + 1 < fLines->NumLines()) { int32 currentLine = LineAt(lastClickOffset);
line = (*fLines)[CurrentLine() + 1]; if (currentLine + 1 < fLines->NumLines()) {
line = (*fLines)[currentLine + 1];
fClickOffset = _PreviousInitialByte(line->offset); fClickOffset = _PreviousInitialByte(line->offset);
} else { } else {
// This check if needed to avoid moving the cursor // This check is needed to avoid moving the cursor
// when the cursor is on the last line, and that line // when the cursor is on the last line, and that line
// is empty // is empty
if (fClickOffset != fText->Length()) { if (fClickOffset != fText->Length()) {
@@ -3428,16 +3464,21 @@ BTextView::_HandlePageKey(uint32 inPageKey)
} }
} }
if (shiftDown) { if (!shiftDown)
if (fClickOffset >= fSelEnd) { selStart = selEnd = fClickOffset;
start = fSelStart; else if (fClickOffset != lastClickOffset) {
end = fClickOffset; if (fClickOffset > fSelEnd) {
// extend selection to the right
selEnd = fClickOffset;
if (lastClickOffset < fSelEnd) {
// caret has jumped across "anchor"
selStart = fSelEnd;
}
} else { } else {
start = fClickOffset; // shrink selection from the left
end = fSelEnd; selStart = fClickOffset;
} }
} else }
start = end = fClickOffset;
break; break;
@@ -3448,16 +3489,21 @@ BTextView::_HandlePageKey(uint32 inPageKey)
currentPos.y -= Bounds().Height(); currentPos.y -= Bounds().Height();
fClickOffset = OffsetAt(LineAt(currentPos)); fClickOffset = OffsetAt(LineAt(currentPos));
if (shiftDown) { if (!shiftDown)
if (fClickOffset <= fSelStart) { selStart = selEnd = fClickOffset;
start = fClickOffset; else if (fClickOffset != lastClickOffset) {
end = fSelEnd; if (fClickOffset < fSelStart) {
// extend selection to the top
selStart = fClickOffset;
if (lastClickOffset > fSelStart) {
// caret has jumped across "anchor"
selEnd = fSelStart;
}
} else { } else {
start = fSelStart; // shrink selection from the bottom
end = fClickOffset; selEnd = fClickOffset;
} }
} else }
start = end = fClickOffset;
break; break;
} }
@@ -3468,23 +3514,32 @@ BTextView::_HandlePageKey(uint32 inPageKey)
currentPos.y += Bounds().Height(); currentPos.y += Bounds().Height();
fClickOffset = OffsetAt(LineAt(currentPos)); fClickOffset = OffsetAt(LineAt(currentPos));
if (shiftDown) { if (!shiftDown)
if (fClickOffset >= fSelEnd) { selStart = selEnd = fClickOffset;
start = fSelStart; else if (fClickOffset != lastClickOffset) {
end = fClickOffset; if (fClickOffset > fSelEnd) {
// extend selection to the bottom
selEnd = fClickOffset;
if (lastClickOffset < fSelEnd) {
// caret has jumped across "anchor"
selStart = fSelEnd;
}
} else { } else {
start = fClickOffset; // shrink selection from the top
end = fSelEnd; selStart = fClickOffset;
} }
} else }
start = end = fClickOffset;
break; break;
} }
} }
if (shiftDown)
Select(selStart, selEnd);
else
Select(fClickOffset, fClickOffset);
ScrollToOffset(fClickOffset); ScrollToOffset(fClickOffset);
Select(start, end);
} }