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 _GetSelectionRegion(BRegion& region) const;
void _GetSelectionText(BString& text) const; void _GetSelectionText(BString& text) const;
void _CopySelectionToClipboard() const; void _CopySelectionToClipboard() const;
void _SelectWordAt(const SelectionPoint& point); void _SelectWordAt(const SelectionPoint& point,
void _SelectLineAt(const SelectionPoint& point); bool extend = false);
void _SelectLineAt(const SelectionPoint& point,
bool extend = false);
void _HandleAutoScroll(); void _HandleAutoScroll();
void _ScrollHorizontal(int32 charCount); void _ScrollHorizontal(int32 charCount);
void _ScrollByLines(int32 lineCount); void _ScrollByLines(int32 lineCount);
@@ -1051,10 +1053,12 @@ SourceView::TextView::MouseDown(BPoint where)
fLastClickTime = clickTime; fLastClickTime = clickTime;
} }
if (fClickCount == 2) if (fClickCount == 2) {
_SelectWordAt(point); _SelectWordAt(point);
else if (fClickCount == 3) { fSelectionMode = true;
} else if (fClickCount == 3) {
_SelectLineAt(point); _SelectLineAt(point);
fSelectionMode = true;
} else if (!region.Contains(where)) { } else if (!region.Contains(where)) {
fSelectionBase = fSelectionStart = fSelectionEnd = point; fSelectionBase = fSelectionStart = fSelectionEnd = point;
fSelectionMode = true; fSelectionMode = true;
@@ -1080,18 +1084,24 @@ SourceView::TextView::MouseMoved(BPoint where, uint32 transit,
switch (transit) { switch (transit) {
case B_INSIDE_VIEW: case B_INSIDE_VIEW:
case B_OUTSIDE_VIEW: case B_OUTSIDE_VIEW:
if (point.line > fSelectionBase.line) { if (fClickCount == 2)
fSelectionStart = fSelectionBase; _SelectWordAt(point, true);
fSelectionEnd = point; else if (fClickCount == 3)
} else if (point.line < fSelectionBase.line) { _SelectLineAt(point, true);
fSelectionEnd = fSelectionBase; else {
fSelectionStart = point; if (point.line > fSelectionBase.line) {
} else if (point.offset > fSelectionBase.offset) { fSelectionStart = fSelectionBase;
fSelectionStart = fSelectionBase; fSelectionEnd = point;
fSelectionEnd = point; } else if (point.line < fSelectionBase.line) {
} else { fSelectionEnd = fSelectionBase;
fSelectionEnd = fSelectionBase; fSelectionStart = point;
fSelectionStart = point; } else if (point.offset > fSelectionBase.offset) {
fSelectionStart = fSelectionBase;
fSelectionEnd = point;
} else {
fSelectionEnd = fSelectionBase;
fSelectionStart = point;
}
} }
break; break;
@@ -1336,41 +1346,76 @@ SourceView::TextView::_CopySelectionToClipboard(void) const
void void
SourceView::TextView::_SelectWordAt(const SelectionPoint& point) SourceView::TextView::_SelectWordAt(const SelectionPoint& point, bool extend)
{ {
const char* line = fSourceCode->LineAt(point.line); const char* line = fSourceCode->LineAt(point.line);
if (isalpha(line[point.offset]) || isdigit(line[point.offset])) { int32 length = fSourceCode->LineLengthAt(point.line);
int32 length = fSourceCode->LineLengthAt(point.line); int32 start = point.offset - 1;
int32 start = point.offset - 1; int32 end = point.offset + 1;
int32 end = point.offset + 1; while ((end) < length) {
while ((end) < length) { if (!isalpha(line[end]) && !isdigit(line[end]))
if (!isalpha(line[end]) && !isdigit(line[end])) break;
break; ++end;
++end; }
} while ((start - 1) >= 0) {
while ((start - 1) >= 0) { if (!isalpha(line[start - 1]) && !isdigit(line[start - 1]))
if (!isalpha(line[start - 1]) && !isdigit(line[start - 1])) break;
break; --start;
--start; }
}
fSelectionStart.line = point.line; if (extend) {
fSelectionStart.offset = start; 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.line = point.line;
fSelectionEnd.offset = end; fSelectionEnd.offset = end;
BRegion region;
_GetSelectionRegion(region);
Invalidate(&region);
} }
BRegion region;
_GetSelectionRegion(region);
Invalidate(&region);
} }
void void
SourceView::TextView::_SelectLineAt(const SelectionPoint& point) SourceView::TextView::_SelectLineAt(const SelectionPoint& point, bool extend)
{ {
fSelectionStart.line = fSelectionEnd.line = point.line; if (extend) {
fSelectionStart.offset = 0; if (point.line >= fSelectionBase.line) {
fSelectionEnd.offset = fSourceCode->LineLengthAt(point.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; BRegion region;
_GetSelectionRegion(region); _GetSelectionRegion(region);
Invalidate(&region); Invalidate(&region);