aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/EditView.cxx28
-rw-r--r--src/EditView.h2
-rw-r--r--src/Editor.cxx85
-rw-r--r--src/Editor.h3
4 files changed, 91 insertions, 27 deletions
diff --git a/src/EditView.cxx b/src/EditView.cxx
index d4ab63948..2ba450ab3 100644
--- a/src/EditView.cxx
+++ b/src/EditView.cxx
@@ -2668,7 +2668,7 @@ static ColourRGBA InvertedLight(ColourRGBA orig) noexcept {
return ColourRGBA(std::min(r, 0xffu), std::min(g, 0xffu), std::min(b, 0xffu));
}
-Sci::Position EditView::FormatRange(bool draw, const RangeToFormat *pfr, Surface *surface, Surface *surfaceMeasure,
+Sci::Position EditView::FormatRange(bool draw, CharacterRangeFull chrg, Rectangle rc, Surface *surface, Surface *surfaceMeasure,
const EditModel &model, const ViewStyle &vs) {
// Can't use measurements cached for screen
posCache->Clear();
@@ -2733,15 +2733,15 @@ Sci::Position EditView::FormatRange(bool draw, const RangeToFormat *pfr, Surface
vsPrint.Refresh(*surfaceMeasure, model.pdoc->tabInChars); // Recalculate fixedColumnWidth
}
- const Sci::Line linePrintStart = model.pdoc->SciLineFromPosition(pfr->chrg.cpMin);
- Sci::Line linePrintLast = linePrintStart + (pfr->rc.bottom - pfr->rc.top) / vsPrint.lineHeight - 1;
+ const Sci::Line linePrintStart = model.pdoc->SciLineFromPosition(chrg.cpMin);
+ Sci::Line linePrintLast = linePrintStart + (rc.bottom - rc.top) / vsPrint.lineHeight - 1;
if (linePrintLast < linePrintStart)
linePrintLast = linePrintStart;
- const Sci::Line linePrintMax = model.pdoc->SciLineFromPosition(pfr->chrg.cpMax);
+ const Sci::Line linePrintMax = model.pdoc->SciLineFromPosition(chrg.cpMax);
if (linePrintLast > linePrintMax)
linePrintLast = linePrintMax;
//Platform::DebugPrintf("Formatting lines=[%0d,%0d,%0d] top=%0d bottom=%0d line=%0d %0d\n",
- // linePrintStart, linePrintLast, linePrintMax, pfr->rc.top, pfr->rc.bottom, vsPrint.lineHeight,
+ // linePrintStart, linePrintLast, linePrintMax, rc.top, rc.bottom, vsPrint.lineHeight,
// surfaceMeasure->Height(vsPrint.styles[StyleLineNumber].font));
Sci::Position endPosPrint = model.pdoc->Length();
if (linePrintLast < model.pdoc->LinesTotal())
@@ -2750,18 +2750,18 @@ Sci::Position EditView::FormatRange(bool draw, const RangeToFormat *pfr, Surface
// Ensure we are styled to where we are formatting.
model.pdoc->EnsureStyledTo(endPosPrint);
- const int xStart = vsPrint.fixedColumnWidth + pfr->rc.left;
- int ypos = pfr->rc.top;
+ const int xStart = vsPrint.fixedColumnWidth + rc.left;
+ int ypos = rc.top;
Sci::Line lineDoc = linePrintStart;
- Sci::Position nPrintPos = pfr->chrg.cpMin;
+ Sci::Position nPrintPos = chrg.cpMin;
int visibleLine = 0;
- int widthPrint = pfr->rc.right - pfr->rc.left - vsPrint.fixedColumnWidth;
+ int widthPrint = rc.right - rc.left - vsPrint.fixedColumnWidth;
if (printParameters.wrapState == Wrap::None)
widthPrint = LineLayout::wrapWidthInfinite;
- while (lineDoc <= linePrintLast && ypos < pfr->rc.bottom) {
+ while (lineDoc <= linePrintLast && ypos < rc.bottom) {
// When printing, the hdc and hdcTarget may be the same, so
// changing the state of surfaceMeasure may change the underlying
@@ -2777,9 +2777,9 @@ Sci::Position EditView::FormatRange(bool draw, const RangeToFormat *pfr, Surface
ll.containsCaret = false;
PRectangle rcLine = PRectangle::FromInts(
- pfr->rc.left,
+ rc.left,
ypos,
- pfr->rc.right - 1,
+ rc.right - 1,
ypos + vsPrint.lineHeight);
// When document line is wrapped over multiple display lines, find where
@@ -2800,7 +2800,7 @@ Sci::Position EditView::FormatRange(bool draw, const RangeToFormat *pfr, Surface
}
if (draw && lineNumberWidth &&
- (ypos + vsPrint.lineHeight <= pfr->rc.bottom) &&
+ (ypos + vsPrint.lineHeight <= rc.bottom) &&
(visibleLine >= 0)) {
const std::string number = std::to_string(lineDoc + 1) + lineNumberPrintSpace;
PRectangle rcNumber = rcLine;
@@ -2819,7 +2819,7 @@ Sci::Position EditView::FormatRange(bool draw, const RangeToFormat *pfr, Surface
surface->FlushCachedState();
for (int iwl = 0; iwl < ll.lines; iwl++) {
- if (ypos + vsPrint.lineHeight <= pfr->rc.bottom) {
+ if (ypos + vsPrint.lineHeight <= rc.bottom) {
if (visibleLine >= 0) {
if (draw) {
rcLine.top = static_cast<XYPOSITION>(ypos);
diff --git a/src/EditView.h b/src/EditView.h
index 199a174b9..d65bf0736 100644
--- a/src/EditView.h
+++ b/src/EditView.h
@@ -160,7 +160,7 @@ public:
const ViewStyle &vsDraw);
void FillLineRemainder(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll,
Sci::Line line, PRectangle rcArea, int subLine) const;
- Sci::Position FormatRange(bool draw, const Scintilla::RangeToFormat *pfr, Surface *surface, Surface *surfaceMeasure,
+ Sci::Position FormatRange(bool draw, CharacterRangeFull chrg, Rectangle rc, Surface *surface, Surface *surfaceMeasure,
const EditModel &model, const ViewStyle &vs);
};
diff --git a/src/Editor.cxx b/src/Editor.cxx
index 6ec2dea3e..f99914ebd 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -1834,18 +1834,30 @@ void Editor::Paint(Surface *surfaceWindow, PRectangle rcArea) {
// This is mostly copied from the Paint method but with some things omitted
// such as the margin markers, line numbers, selection and caret
// Should be merged back into a combined Draw method.
-Sci::Position Editor::FormatRange(bool draw, const RangeToFormat *pfr) {
- if (!pfr)
- return 0;
-
- AutoSurface surface(pfr->hdc, this, Technology::Default);
- if (!surface)
- return 0;
- AutoSurface surfaceMeasure(pfr->hdcTarget, this, Technology::Default);
- if (!surfaceMeasure) {
+Sci::Position Editor::FormatRange(Scintilla::Message iMessage, Scintilla::uptr_t wParam, Scintilla::sptr_t lParam) {
+ if (!lParam)
return 0;
+ const bool draw = wParam != 0;
+ void *ptr = PtrFromSPtr(lParam);
+ if (iMessage == Message::FormatRange) {
+ RangeToFormat *pfr = static_cast<RangeToFormat *>(ptr);
+ CharacterRangeFull chrg{ pfr->chrg.cpMin,pfr->chrg.cpMax };
+ AutoSurface surface(pfr->hdc, this, Technology::Default);
+ AutoSurface surfaceMeasure(pfr->hdcTarget, this, Technology::Default);
+ if (!surface || !surfaceMeasure) {
+ return 0;
+ }
+ return view.FormatRange(draw, chrg, pfr->rc, surface, surfaceMeasure, *this, vs);
+ } else {
+ // FormatRangeFull
+ RangeToFormatFull *pfr = static_cast<RangeToFormatFull *>(ptr);
+ AutoSurface surface(pfr->hdc, this, Technology::Default);
+ AutoSurface surfaceMeasure(pfr->hdcTarget, this, Technology::Default);
+ if (!surface || !surfaceMeasure) {
+ return 0;
+ }
+ return view.FormatRange(draw, pfr->chrg, pfr->rc, surface, surfaceMeasure, *this, vs);
}
- return view.FormatRange(draw, pfr, surface, surfaceMeasure, *this, vs);
}
long Editor::TextWidth(uptr_t style, const char *text) {
@@ -4121,6 +4133,37 @@ Sci::Position Editor::FindText(
}
/**
+ * Search of a text in the document, in the given range.
+ * @return The position of the found text, -1 if not found.
+ */
+Sci::Position Editor::FindTextFull(
+ uptr_t wParam, ///< Search modes : @c FindOption::MatchCase, @c FindOption::WholeWord,
+ ///< @c FindOption::WordStart, @c FindOption::RegExp or @c FindOption::Posix.
+ sptr_t lParam) { ///< @c Sci_TextToFindFull structure: The text to search for in the given range.
+
+ TextToFindFull *ft = static_cast<TextToFindFull *>(PtrFromSPtr(lParam));
+ Sci::Position lengthFound = strlen(ft->lpstrText);
+ if (!pdoc->HasCaseFolder())
+ pdoc->SetCaseFolder(CaseFolderForEncoding());
+ try {
+ const Sci::Position pos = pdoc->FindText(
+ static_cast<Sci::Position>(ft->chrg.cpMin),
+ static_cast<Sci::Position>(ft->chrg.cpMax),
+ ft->lpstrText,
+ static_cast<FindOption>(wParam),
+ &lengthFound);
+ if (pos != -1) {
+ ft->chrgText.cpMin = static_cast<Sci_PositionCR>(pos);
+ ft->chrgText.cpMax = static_cast<Sci_PositionCR>(pos + lengthFound);
+ }
+ return pos;
+ } catch (RegexError &) {
+ errorStatus = Status::RegEx;
+ return -1;
+ }
+}
+
+/**
* Relocatable search support : Searches relative to current selection
* point and sets the selection to the found text range with
* each search.
@@ -6244,6 +6287,9 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) {
case Message::FindText:
return FindText(wParam, lParam);
+ case Message::FindTextFull:
+ return FindTextFull(wParam, lParam);
+
case Message::GetTextRange: {
if (lParam == 0)
return 0;
@@ -6259,13 +6305,30 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) {
return len; // Not including NUL
}
+ case Message::GetTextRangeFull: {
+ if (lParam == 0)
+ return 0;
+ TextRangeFull *tr = static_cast<TextRangeFull *>(PtrFromSPtr(lParam));
+ Sci::Position cpMax = tr->chrg.cpMax;
+ if (cpMax == -1)
+ cpMax = pdoc->Length();
+ PLATFORM_ASSERT(cpMax <= pdoc->Length());
+ const Sci::Position len = cpMax - tr->chrg.cpMin; // No -1 as cpMin and cpMax are referring to inter character positions
+ PLATFORM_ASSERT(len >= 0);
+ pdoc->GetCharRange(tr->lpstrText, tr->chrg.cpMin, len);
+ // Spec says copied text is terminated with a NUL
+ tr->lpstrText[len] = '\0';
+ return len; // Not including NUL
+ }
+
case Message::HideSelection:
view.hideSelection = wParam != 0;
Redraw();
break;
case Message::FormatRange:
- return FormatRange(wParam != 0, static_cast<RangeToFormat *>(PtrFromSPtr(lParam)));
+ case Message::FormatRangeFull:
+ return FormatRange(iMessage, wParam, lParam);
case Message::GetMarginLeft:
return vs.leftMarginWidth;
diff --git a/src/Editor.h b/src/Editor.h
index 095131c76..a6364be4d 100644
--- a/src/Editor.h
+++ b/src/Editor.h
@@ -406,7 +406,7 @@ protected: // ScintillaBase subclass needs access to much of Editor
void PaintSelMargin(Surface *surfaceWindow, const PRectangle &rc);
void RefreshPixMaps(Surface *surfaceWindow);
void Paint(Surface *surfaceWindow, PRectangle rcArea);
- Sci::Position FormatRange(bool draw, const Scintilla::RangeToFormat *pfr);
+ Sci::Position FormatRange(Scintilla::Message iMessage, Scintilla::uptr_t wParam, Scintilla::sptr_t lParam);
long TextWidth(Scintilla::uptr_t style, const char *text);
virtual void SetVerticalScrollPos() = 0;
@@ -503,6 +503,7 @@ protected: // ScintillaBase subclass needs access to much of Editor
virtual std::unique_ptr<CaseFolder> CaseFolderForEncoding();
Sci::Position FindText(Scintilla::uptr_t wParam, Scintilla::sptr_t lParam);
+ Sci::Position FindTextFull(Scintilla::uptr_t wParam, Scintilla::sptr_t lParam);
void SearchAnchor();
Sci::Position SearchText(Scintilla::Message iMessage, Scintilla::uptr_t wParam, Scintilla::sptr_t lParam);
Sci::Position SearchInTarget(const char *text, Sci::Position length);