* Fix some calculation errors in FileSourceCode spotted by Ingo.

* if we click in the selection without dragging, clear the selection.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31602 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Rene Gollent
2009-07-16 03:42:44 +00:00
parent ef6d576ca7
commit c0f60e6610
2 changed files with 15 additions and 5 deletions
+2 -5
View File
@@ -88,15 +88,12 @@ SourceFile::Init(const char* path)
fFileContent[fileSize] = '\0';
// count lines
fLineCount = 0;
fLineCount = 1;
for (size_t i = 0; i < fileSize; i++) {
if (fFileContent[i] == '\n')
fLineCount++;
}
if (fFileContent[fileSize - 1] != '\n')
fLineCount++;
// allocate line offset array
fLineOffsets = new(std::nothrow) int32[fLineCount + 1];
if (fLineOffsets == NULL)
@@ -111,7 +108,7 @@ SourceFile::Init(const char* path)
fLineOffsets[lineIndex++] = i + 1;
}
}
fLineOffsets[fLineCount] = fileSize - 1;
fLineOffsets[fLineCount] = fileSize + 1;
return B_OK;
}
@@ -261,6 +261,7 @@ private:
SelectionPoint fSelectionStart;
SelectionPoint fSelectionEnd;
SelectionPoint fSelectionBase;
SelectionPoint fLastClickPoint;
bigtime_t fLastClickTime;
int16 fClickCount;
rgb_color fTextColor;
@@ -856,6 +857,7 @@ SourceView::TextView::TextView(SourceView* sourceView, FontInfo* fontInfo)
fSelectionStart(-1, -1),
fSelectionEnd(-1, -1),
fSelectionBase(-1, -1),
fLastClickPoint(-1, -1),
fLastClickTime(0),
fClickCount(0),
fSelectionMode(false),
@@ -1009,6 +1011,7 @@ SourceView::TextView::MouseDown(BPoint where)
_GetSelectionRegion(region);
bigtime_t clickTime = system_time();
SelectionPoint point = _SelectionPointAt(where);
fLastClickPoint = point;
bigtime_t clickSpeed = 0;
get_click_speed(&clickSpeed);
if (clickTime - fLastClickTime < clickSpeed
@@ -1104,6 +1107,16 @@ void
SourceView::TextView::MouseUp(BPoint where)
{
fSelectionMode = false;
if (fTrackState == kTracking && fClickCount < 2) {
// if we clicked without dragging or double/triple clicking,
// clear the current selection (if any)
SelectionPoint point = _SelectionPointAt(where);
if (fLastClickPoint == point) {
fSelectionBase = fSelectionStart = fSelectionEnd;
Invalidate();
}
}
fTrackState = kNotTracking;
}