* 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:
+121
-66
@@ -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:
|
||||||
{
|
{
|
||||||
|
if (fSelStart != fSelEnd && !shiftDown)
|
||||||
|
fClickOffset = fSelStart;
|
||||||
|
else {
|
||||||
float height;
|
float height;
|
||||||
BPoint point = PointAt(fClickOffset, &height);
|
BPoint point = PointAt(fClickOffset, &height);
|
||||||
point.y -= height;
|
point.y -= height;
|
||||||
fClickOffset = OffsetAt(point);
|
fClickOffset = OffsetAt(point);
|
||||||
if (shiftDown) {
|
if (shiftDown && fClickOffset != lastClickOffset) {
|
||||||
if (fClickOffset != currentOffset) {
|
if (fClickOffset < fSelStart) {
|
||||||
if (fClickOffset >= fSelStart)
|
// extend selection to the top
|
||||||
selEnd = fClickOffset;
|
|
||||||
else
|
|
||||||
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:
|
||||||
{
|
{
|
||||||
|
if (fSelStart != fSelEnd && !shiftDown)
|
||||||
|
fClickOffset = fSelEnd;
|
||||||
|
else {
|
||||||
float height;
|
float height;
|
||||||
BPoint point = PointAt(fClickOffset, &height);
|
BPoint point = PointAt(fClickOffset, &height);
|
||||||
point.y += height;
|
point.y += height;
|
||||||
fClickOffset = OffsetAt(point);
|
fClickOffset = OffsetAt(point);
|
||||||
if (shiftDown) {
|
if (shiftDown && fClickOffset != lastClickOffset) {
|
||||||
if (fClickOffset != currentOffset) {
|
if (fClickOffset > fSelEnd) {
|
||||||
if (fClickOffset <= fSelEnd)
|
// extend selection to the bottom
|
||||||
selStart = fClickOffset;
|
|
||||||
else
|
|
||||||
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) {
|
||||||
} else {
|
// extend selection to the left
|
||||||
start = fSelStart;
|
selStart = fClickOffset;
|
||||||
end = fClickOffset;
|
if (lastClickOffset > fSelStart) {
|
||||||
|
// caret has jumped across "anchor"
|
||||||
|
selEnd = fSelStart;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// shrink selection from the right
|
||||||
|
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) {
|
||||||
} else {
|
// extend selection to the right
|
||||||
start = fClickOffset;
|
selEnd = fClickOffset;
|
||||||
end = fSelEnd;
|
if (lastClickOffset < fSelEnd) {
|
||||||
|
// caret has jumped across "anchor"
|
||||||
|
selStart = fSelEnd;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// shrink selection from the left
|
||||||
|
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) {
|
||||||
} else {
|
// extend selection to the top
|
||||||
start = fSelStart;
|
selStart = fClickOffset;
|
||||||
end = fClickOffset;
|
if (lastClickOffset > fSelStart) {
|
||||||
|
// caret has jumped across "anchor"
|
||||||
|
selEnd = fSelStart;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// shrink selection from the bottom
|
||||||
|
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) {
|
||||||
} else {
|
// extend selection to the bottom
|
||||||
start = fClickOffset;
|
selEnd = fClickOffset;
|
||||||
end = fSelEnd;
|
if (lastClickOffset < fSelEnd) {
|
||||||
|
// caret has jumped across "anchor"
|
||||||
|
selStart = fSelEnd;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// shrink selection from the top
|
||||||
|
selStart = fClickOffset;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else
|
|
||||||
start = end = fClickOffset;
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (shiftDown)
|
||||||
|
Select(selStart, selEnd);
|
||||||
|
else
|
||||||
|
Select(fClickOffset, fClickOffset);
|
||||||
|
|
||||||
ScrollToOffset(fClickOffset);
|
ScrollToOffset(fClickOffset);
|
||||||
Select(start, end);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user