Implement double click / triple click drag selection as in Pe.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32047 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Rene Gollent
2009-08-01 01:40:11 +00:00
parent ae8e567a34
commit 6e58de0288
@@ -259,8 +259,10 @@ private:
void _GetSelectionRegion(BRegion& region) const;
void _GetSelectionText(BString& text) const;
void _CopySelectionToClipboard() const;
void _SelectWordAt(const SelectionPoint& point);
void _SelectLineAt(const SelectionPoint& point);
void _SelectWordAt(const SelectionPoint& point,
bool extend = false);
void _SelectLineAt(const SelectionPoint& point,
bool extend = false);
void _HandleAutoScroll();
void _ScrollHorizontal(int32 charCount);
void _ScrollByLines(int32 lineCount);
@@ -1051,10 +1053,12 @@ SourceView::TextView::MouseDown(BPoint where)
fLastClickTime = clickTime;
}
if (fClickCount == 2)
if (fClickCount == 2) {
_SelectWordAt(point);
else if (fClickCount == 3) {
fSelectionMode = true;
} else if (fClickCount == 3) {
_SelectLineAt(point);
fSelectionMode = true;
} else if (!region.Contains(where)) {
fSelectionBase = fSelectionStart = fSelectionEnd = point;
fSelectionMode = true;
@@ -1080,18 +1084,24 @@ SourceView::TextView::MouseMoved(BPoint where, uint32 transit,
switch (transit) {
case B_INSIDE_VIEW:
case B_OUTSIDE_VIEW:
if (point.line > fSelectionBase.line) {
fSelectionStart = fSelectionBase;
fSelectionEnd = point;
} else if (point.line < fSelectionBase.line) {
fSelectionEnd = fSelectionBase;
fSelectionStart = point;
} else if (point.offset > fSelectionBase.offset) {
fSelectionStart = fSelectionBase;
fSelectionEnd = point;
} else {
fSelectionEnd = fSelectionBase;
fSelectionStart = point;
if (fClickCount == 2)
_SelectWordAt(point, true);
else if (fClickCount == 3)
_SelectLineAt(point, true);
else {
if (point.line > fSelectionBase.line) {
fSelectionStart = fSelectionBase;
fSelectionEnd = point;
} else if (point.line < fSelectionBase.line) {
fSelectionEnd = fSelectionBase;
fSelectionStart = point;
} else if (point.offset > fSelectionBase.offset) {
fSelectionStart = fSelectionBase;
fSelectionEnd = point;
} else {
fSelectionEnd = fSelectionBase;
fSelectionStart = point;
}
}
break;
@@ -1336,41 +1346,76 @@ SourceView::TextView::_CopySelectionToClipboard(void) const
void
SourceView::TextView::_SelectWordAt(const SelectionPoint& point)
SourceView::TextView::_SelectWordAt(const SelectionPoint& point, bool extend)
{
const char* line = fSourceCode->LineAt(point.line);
if (isalpha(line[point.offset]) || isdigit(line[point.offset])) {
int32 length = fSourceCode->LineLengthAt(point.line);
int32 start = point.offset - 1;
int32 end = point.offset + 1;
while ((end) < length) {
if (!isalpha(line[end]) && !isdigit(line[end]))
break;
++end;
}
while ((start - 1) >= 0) {
if (!isalpha(line[start - 1]) && !isdigit(line[start - 1]))
break;
--start;
}
int32 length = fSourceCode->LineLengthAt(point.line);
int32 start = point.offset - 1;
int32 end = point.offset + 1;
while ((end) < length) {
if (!isalpha(line[end]) && !isdigit(line[end]))
break;
++end;
}
while ((start - 1) >= 0) {
if (!isalpha(line[start - 1]) && !isdigit(line[start - 1]))
break;
--start;
}
fSelectionStart.line = point.line;
fSelectionStart.offset = start;
if (extend) {
if (point.line >= fSelectionBase.line
|| (point.line == fSelectionBase.line
&& point.offset > fSelectionBase.offset)) {
fSelectionStart.line = fSelectionBase.line;
fSelectionStart.offset = fSelectionBase.offset;
fSelectionEnd.line = point.line;
fSelectionEnd.offset = end;
} else if (point.line < fSelectionBase.line) {
fSelectionStart.line = point.line;
fSelectionStart.offset = start;
fSelectionEnd.line = fSelectionBase.line;
fSelectionEnd.offset = fSelectionBase.offset;
} else if (point.line == fSelectionBase.line) {
// if we hit here, our offset is before the actual start.
fSelectionStart.line = point.line;
fSelectionStart.offset = start;
fSelectionEnd.line = point.line;
fSelectionEnd.offset = fSelectionBase.offset;
}
} else {
fSelectionBase.line = fSelectionStart.line = point.line;
fSelectionBase.offset = fSelectionStart.offset = start;
fSelectionEnd.line = point.line;
fSelectionEnd.offset = end;
BRegion region;
_GetSelectionRegion(region);
Invalidate(&region);
}
BRegion region;
_GetSelectionRegion(region);
Invalidate(&region);
}
void
SourceView::TextView::_SelectLineAt(const SelectionPoint& point)
SourceView::TextView::_SelectLineAt(const SelectionPoint& point, bool extend)
{
fSelectionStart.line = fSelectionEnd.line = point.line;
fSelectionStart.offset = 0;
fSelectionEnd.offset = fSourceCode->LineLengthAt(point.line);
if (extend) {
if (point.line >= fSelectionBase.line) {
fSelectionStart.line = fSelectionBase.line;
fSelectionStart.offset = 0;
fSelectionEnd.line = point.line;
fSelectionEnd.offset = fSourceCode->LineLengthAt(point.line);
} else {
fSelectionStart.line = point.line;
fSelectionStart.offset = 0;
fSelectionEnd.line = fSelectionBase.line;
fSelectionEnd.offset = fSourceCode->LineLengthAt(
fSelectionBase.line);
}
} else {
fSelectionStart.line = fSelectionEnd.line = point.line;
fSelectionStart.offset = 0;
fSelectionEnd.offset = fSourceCode->LineLengthAt(point.line);
}
BRegion region;
_GetSelectionRegion(region);
Invalidate(&region);