diff options
author | nyamatongwe <unknown> | 2013-04-01 16:27:36 +1100 |
---|---|---|
committer | nyamatongwe <unknown> | 2013-04-01 16:27:36 +1100 |
commit | e0f738cec43a5c60ee1c4dcd3eedd2f0805e18ab (patch) | |
tree | e5dd393ef4010ce06810907ba9826aa9f6ea0f1d /src | |
parent | 9526777f646030e4b5a1818c423d7c8c97e59d85 (diff) | |
download | scintilla-mirror-e0f738cec43a5c60ee1c4dcd3eedd2f0805e18ab.tar.gz |
Extract effect of choosing an autocompletion entry so it can be reused for both
user choice and single element list automatic insertion.
Diffstat (limited to 'src')
-rw-r--r-- | src/ScintillaBase.cxx | 29 | ||||
-rw-r--r-- | src/ScintillaBase.h | 1 |
2 files changed, 12 insertions, 18 deletions
diff --git a/src/ScintillaBase.cxx b/src/ScintillaBase.cxx index 35aa1c49e..1cf146c06 100644 --- a/src/ScintillaBase.cxx +++ b/src/ScintillaBase.cxx @@ -193,6 +193,13 @@ void ScintillaBase::AutoCompleteDoubleClick(void *p) { sci->AutoCompleteCompleted(); } +void ScintillaBase::AutoCompleteInsert(Position startPos, int removeLen, const char *text, int textLen) { + UndoGroup ug(pdoc); + pdoc->DeleteChars(startPos, removeLen); + pdoc->InsertString(startPos, text, textLen); + SetEmptySelection(startPos + textLen); +} + void ScintillaBase::AutoCompleteStart(int lenEntered, const char *list) { //Platform::DebugPrintf("AutoComplete %s\n", list); ct.CallTipCancel(); @@ -202,17 +209,11 @@ void ScintillaBase::AutoCompleteStart(int lenEntered, const char *list) { const char *typeSep = strchr(list, ac.GetTypesep()); int lenInsert = typeSep ? static_cast<int>(typeSep-list) : static_cast<int>(strlen(list)); - UndoGroup ug(pdoc); if (ac.ignoreCase) { - SetEmptySelection(sel.MainCaret() - lenEntered); - pdoc->DeleteChars(sel.MainCaret(), lenEntered); - SetEmptySelection(sel.MainCaret()); - pdoc->InsertString(sel.MainCaret(), list, lenInsert); - SetEmptySelection(sel.MainCaret() + lenInsert); + // May need to convert the case before invocation, so remove lenEntered characters + AutoCompleteInsert(sel.MainCaret() - lenEntered, lenEntered, list, lenInsert); } else { - SetEmptySelection(sel.MainCaret()); - pdoc->InsertString(sel.MainCaret(), list + lenEntered, lenInsert - lenEntered); - SetEmptySelection(sel.MainCaret() + lenInsert - lenEntered); + AutoCompleteInsert(sel.MainCaret(), 0, list + lenEntered, lenInsert - lenEntered); } ac.Cancel(); return; @@ -357,15 +358,7 @@ void ScintillaBase::AutoCompleteCompleted() { endPos = pdoc->ExtendWordSelect(endPos, 1, true); if (endPos < firstPos) return; - UndoGroup ug(pdoc); - if (endPos != firstPos) { - pdoc->DeleteChars(firstPos, endPos - firstPos); - } - SetEmptySelection(ac.posStart); - if (item != -1) { - pdoc->InsertCString(firstPos, selected.c_str()); - SetEmptySelection(firstPos + static_cast<int>(selected.length())); - } + AutoCompleteInsert(firstPos, endPos - firstPos, selected.c_str(), static_cast<int>(selected.length())); SetLastXChosen(); } diff --git a/src/ScintillaBase.h b/src/ScintillaBase.h index e143f027d..bbd7f8fdf 100644 --- a/src/ScintillaBase.h +++ b/src/ScintillaBase.h @@ -64,6 +64,7 @@ protected: virtual void CancelModes(); virtual int KeyCommand(unsigned int iMessage); + void AutoCompleteInsert(Position startPos, int removeLen, const char *text, int textLen); void AutoCompleteStart(int lenEntered, const char *list); void AutoCompleteCancel(); void AutoCompleteMove(int delta); |