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:
@@ -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,6 +1084,11 @@ 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 (fClickCount == 2)
|
||||||
|
_SelectWordAt(point, true);
|
||||||
|
else if (fClickCount == 3)
|
||||||
|
_SelectLineAt(point, true);
|
||||||
|
else {
|
||||||
if (point.line > fSelectionBase.line) {
|
if (point.line > fSelectionBase.line) {
|
||||||
fSelectionStart = fSelectionBase;
|
fSelectionStart = fSelectionBase;
|
||||||
fSelectionEnd = point;
|
fSelectionEnd = point;
|
||||||
@@ -1093,6 +1102,7 @@ SourceView::TextView::MouseMoved(BPoint where, uint32 transit,
|
|||||||
fSelectionEnd = fSelectionBase;
|
fSelectionEnd = fSelectionBase;
|
||||||
fSelectionStart = point;
|
fSelectionStart = point;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_EXITED_VIEW:
|
case B_EXITED_VIEW:
|
||||||
@@ -1336,10 +1346,9 @@ 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;
|
||||||
@@ -1354,23 +1363,59 @@ SourceView::TextView::_SelectWordAt(const SelectionPoint& point)
|
|||||||
--start;
|
--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.line = point.line;
|
||||||
fSelectionStart.offset = start;
|
fSelectionStart.offset = start;
|
||||||
fSelectionEnd.line = point.line;
|
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;
|
fSelectionEnd.offset = end;
|
||||||
|
}
|
||||||
BRegion region;
|
BRegion region;
|
||||||
_GetSelectionRegion(region);
|
_GetSelectionRegion(region);
|
||||||
Invalidate(®ion);
|
Invalidate(®ion);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SourceView::TextView::_SelectLineAt(const SelectionPoint& point)
|
SourceView::TextView::_SelectLineAt(const SelectionPoint& point, bool extend)
|
||||||
{
|
{
|
||||||
|
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.line = fSelectionEnd.line = point.line;
|
||||||
fSelectionStart.offset = 0;
|
fSelectionStart.offset = 0;
|
||||||
fSelectionEnd.offset = fSourceCode->LineLengthAt(point.line);
|
fSelectionEnd.offset = fSourceCode->LineLengthAt(point.line);
|
||||||
|
}
|
||||||
BRegion region;
|
BRegion region;
|
||||||
_GetSelectionRegion(region);
|
_GetSelectionRegion(region);
|
||||||
Invalidate(®ion);
|
Invalidate(®ion);
|
||||||
|
|||||||
Reference in New Issue
Block a user