Skip to content

Commit

Permalink
Avoid adding extra braces or brackets in auto-completion when there a…
Browse files Browse the repository at this point in the history
…lready has same brace or bracket.
  • Loading branch information
zufuliu committed Oct 3, 2018
1 parent f3b2417 commit 63cb420
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
6 changes: 3 additions & 3 deletions scintilla/src/EditView.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2430,12 +2430,12 @@ Sci::Position EditView::FormatRange(bool draw, const Sci_RangeToFormat *pfr, Sur
}

const Sci::Line linePrintStart =
model.pdoc->SciLineFromPosition(static_cast<Sci::Position>(pfr->chrg.cpMin));
model.pdoc->SciLineFromPosition(pfr->chrg.cpMin);
Sci::Line linePrintLast = linePrintStart + (pfr->rc.bottom - pfr->rc.top) / vsPrint.lineHeight - 1;
if (linePrintLast < linePrintStart)
linePrintLast = linePrintStart;
const Sci::Line linePrintMax =
model.pdoc->SciLineFromPosition(static_cast<Sci::Position>(pfr->chrg.cpMax));
model.pdoc->SciLineFromPosition(pfr->chrg.cpMax);
if (linePrintLast > linePrintMax)
linePrintLast = linePrintMax;
//Platform::DebugPrintf("Formatting lines=[%0d,%0d,%0d] top=%0d bottom=%0d line=%0d %0d\n",
Expand All @@ -2453,7 +2453,7 @@ Sci::Position EditView::FormatRange(bool draw, const Sci_RangeToFormat *pfr, Sur

Sci::Line lineDoc = linePrintStart;

Sci::Position nPrintPos = static_cast<Sci::Position>(pfr->chrg.cpMin);
Sci::Position nPrintPos = pfr->chrg.cpMin;
int visibleLine = 0;
int widthPrint = pfr->rc.right - pfr->rc.left - vsPrint.fixedColumnWidth;
if (printParameters.wrapState == eWrapNone)
Expand Down
6 changes: 3 additions & 3 deletions scintilla/src/Editor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4032,8 +4032,8 @@ Sci::Position Editor::FindText(
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->chrg.cpMin,
ft->chrg.cpMax,
ft->lpstrText,
static_cast<int>(wParam),
&lengthFound);
Expand Down Expand Up @@ -6094,7 +6094,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
if (lParam == 0)
return 0;
Sci_TextRange *tr = static_cast<Sci_TextRange *>(PtrFromSPtr(lParam));
Sci::Position cpMax = static_cast<Sci::Position>(tr->chrg.cpMax);
Sci::Position cpMax = tr->chrg.cpMax;
if (cpMax == -1)
cpMax = pdoc->Length();
PLATFORM_ASSERT(cpMax <= pdoc->Length());
Expand Down
21 changes: 12 additions & 9 deletions src/Notepad2.c
Original file line number Diff line number Diff line change
Expand Up @@ -5095,17 +5095,20 @@ LRESULT MsgNotify(HWND hwnd, WPARAM wParam, LPARAM lParam) {

case SCN_AUTOCSELECTION:
case SCN_USERLISTSELECTION: {
Sci_Position iCurPos = SciCall_GetCurrentPos();
SendMessage(hwndEdit, SCI_BEGINUNDOACTION, 0, 0);
SendMessage(hwndEdit, SCI_SETSEL, scn->position, iCurPos);
SendMessage(hwndEdit, SCI_REPLACESEL, 0, (LPARAM)scn->text);
LPCSTR text = scn->text;
// function/array/template/generic
if ((iCurPos = lstrlenA(StrPBrkA(scn->text, "([{<"))) != 0) {
//if ((iCurPos = lstrlenA(StrChrA(scn->text, '(')))) {
iCurPos = 1 - iCurPos;
LPSTR braces = StrPBrkA(text, "([{<");
const Sci_Position iCurPos = SciCall_GetCurrentPos();
const int ch = SciCall_GetCharAt(iCurPos);
if (braces != NULL && *braces == ch) {
*braces = L'\0'; // unsafe
}
iCurPos += scn->position + lstrlenA(scn->text);
SendMessage(hwndEdit, SCI_SETSEL, iCurPos, iCurPos);
const Sci_Position iNewPos = scn->position + ((braces == NULL) ? lstrlenA(text) : (braces - text + 1));

SendMessage(hwndEdit, SCI_BEGINUNDOACTION, 0, 0);
SendMessage(hwndEdit, SCI_SETSEL, scn->position, iCurPos);
SendMessage(hwndEdit, SCI_REPLACESEL, 0, (LPARAM)text);
SendMessage(hwndEdit, SCI_SETSEL, iNewPos, iNewPos);
SendMessage(hwndEdit, SCI_ENDUNDOACTION, 0, 0);
SendMessage(hwndEdit, SCI_AUTOCCANCEL, 0, 0);
}
Expand Down

0 comments on commit 63cb420

Please sign in to comment.