diff --git a/src/apps/debugger/files/SourceFile.cpp b/src/apps/debugger/files/SourceFile.cpp index b5ff5f1957..479c0141b2 100644 --- a/src/apps/debugger/files/SourceFile.cpp +++ b/src/apps/debugger/files/SourceFile.cpp @@ -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; } diff --git a/src/apps/debugger/gui/team_window/SourceView.cpp b/src/apps/debugger/gui/team_window/SourceView.cpp index 79f9c16cc5..81ef39702c 100644 --- a/src/apps/debugger/gui/team_window/SourceView.cpp +++ b/src/apps/debugger/gui/team_window/SourceView.cpp @@ -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; }