diff options
author | Neil <nyamatongwe@gmail.com> | 2022-10-20 09:08:28 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2022-10-20 09:08:28 +1100 |
commit | bb1cd6ce1a5f0a8ea1a31d37c0500c6a4edb1372 (patch) | |
tree | 06a8202bd09a744844a60a1a1e71f7d2db69d655 /src/ScintillaBase.cxx | |
parent | b8ba34f03cb1808aa47dce0fe06e81d372a9702c (diff) | |
download | scintilla-mirror-bb1cd6ce1a5f0a8ea1a31d37c0500c6a4edb1372.tar.gz |
Change ScintillaBase::AutoCompleteInsert to take a string_view and add
Document::InsertString overload taking a string_view.
These changes simplify callers.
Diffstat (limited to 'src/ScintillaBase.cxx')
-rw-r--r-- | src/ScintillaBase.cxx | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/ScintillaBase.cxx b/src/ScintillaBase.cxx index e72f1b1d6..d47d289dd 100644 --- a/src/ScintillaBase.cxx +++ b/src/ScintillaBase.cxx @@ -211,11 +211,11 @@ void ScintillaBase::ListNotify(ListBoxEvent *plbe) { } } -void ScintillaBase::AutoCompleteInsert(Sci::Position startPos, Sci::Position removeLen, const char *text, Sci::Position textLen) { +void ScintillaBase::AutoCompleteInsert(Sci::Position startPos, Sci::Position removeLen, std::string_view text) { UndoGroup ug(pdoc); if (multiAutoCMode == MultiAutoComplete::Once) { pdoc->DeleteChars(startPos, removeLen); - const Sci::Position lengthInserted = pdoc->InsertString(startPos, text, textLen); + const Sci::Position lengthInserted = pdoc->InsertString(startPos, text); SetEmptySelection(startPos + lengthInserted); } else { // MultiAutoComplete::Each @@ -228,7 +228,7 @@ void ScintillaBase::AutoCompleteInsert(Sci::Position startPos, Sci::Position rem positionInsert -= removeLen; pdoc->DeleteChars(positionInsert, removeLen); } - const Sci::Position lengthInserted = pdoc->InsertString(positionInsert, text, textLen); + const Sci::Position lengthInserted = pdoc->InsertString(positionInsert, text); if (lengthInserted > 0) { sel.Range(r).caret.SetPosition(positionInsert + lengthInserted); sel.Range(r).anchor.SetPosition(positionInsert + lengthInserted); @@ -245,14 +245,14 @@ void ScintillaBase::AutoCompleteStart(Sci::Position lenEntered, const char *list if (ac.chooseSingle && (listType == 0)) { if (list && !strchr(list, ac.GetSeparator())) { - const char *typeSep = strchr(list, ac.GetTypesep()); - const Sci::Position lenInsert = typeSep ? - (typeSep-list) : strlen(list); + // list contains just one item so choose it + const std::string_view item(list); + const std::string_view choice = item.substr(0, item.find_first_of(ac.GetTypesep())); if (ac.ignoreCase) { // May need to convert the case before invocation, so remove lenEntered characters - AutoCompleteInsert(sel.MainCaret() - lenEntered, lenEntered, list, lenInsert); + AutoCompleteInsert(sel.MainCaret() - lenEntered, lenEntered, choice); } else { - AutoCompleteInsert(sel.MainCaret(), 0, list + lenEntered, lenInsert - lenEntered); + AutoCompleteInsert(sel.MainCaret(), 0, choice.substr(lenEntered)); } ac.Cancel(); return; @@ -430,7 +430,7 @@ void ScintillaBase::AutoCompleteCompleted(char ch, CompletionMethods completionM endPos = pdoc->ExtendWordSelect(endPos, 1, true); if (endPos < firstPos) return; - AutoCompleteInsert(firstPos, endPos - firstPos, selected.c_str(), selected.length()); + AutoCompleteInsert(firstPos, endPos - firstPos, selected); SetLastXChosen(); scn.nmhdr.code = Notification::AutoCCompleted; |