/// <summary> Tested ? Working ? </summary> /// <param name="sender"> </param> /// <param name="e"> </param> private void selectedScintilla_AutoCompleteAccepted(object sender, AutoCSelectionEventArgs e) { if (!hit) { //ahk.MsgBox(e.Text.ToString()); hit = true; var currentPos = selectedScintilla.CurrentPosition; var wordStartPos = selectedScintilla.WordStartPosition(currentPos, true); string SoFarText = selectedScintilla.GetWordFromPosition(wordStartPos); // word typed so far var lenEntered = currentPos - wordStartPos; selectedScintilla.DeleteRange(wordStartPos, lenEntered); string NewPaste = SoFarText; //if (SoFarText == "List_String") { NewPaste = "List<string> list = new List<string>();\n"; } //if (SoFarText == "SQLiteGen") { ahk.MsgBox("Started Tool"); } selectedScintilla.InsertText(selectedScintilla.CurrentPosition, NewPaste); //selectedScintilla.CurrentPosition() //selectedScintilla.CurrentPosition(selectedScintilla.CurrentPosition + NewPaste.Length); //int currentline = scintilla1.CurrentLine; selectedScintilla.GotoPosition(selectedScintilla.CurrentPosition + NewPaste.Length); //ahk.MsgBox("Pasted: " + SoFarText); } }
//stolen from https://github.com/jacobslusser/ScintillaNET/wiki/Character-Autocompletion#finishing-touch private void InsertMatchedChars(CharAddedEventArgs e) { var caretPos = _codeArea.CurrentPosition; var docStart = caretPos == 1; var docEnd = caretPos == _codeArea.Text.Length; var charPrev = docStart ? _codeArea.GetCharAt(caretPos) : _codeArea.GetCharAt(caretPos - 2); var charNext = _codeArea.GetCharAt(caretPos); var isCharPrevBlank = charPrev == ' ' || charPrev == '\t' || charPrev == '\n' || charPrev == '\r'; var isCharNextBlank = charNext == ' ' || charNext == '\t' || charNext == '\n' || charNext == '\r' || docEnd; var isEnclosed = (charPrev == '(' && charNext == ')') || (charPrev == '{' && charNext == '}') || (charPrev == '[' && charNext == ']'); var isSpaceEnclosed = (charPrev == '(' && isCharNextBlank) || (isCharPrevBlank && charNext == ')') || (charPrev == '{' && isCharNextBlank) || (isCharPrevBlank && charNext == '}') || (charPrev == '[' && isCharNextBlank) || (isCharPrevBlank && charNext == ']'); var isCharOrString = (isCharPrevBlank && isCharNextBlank) || isEnclosed || isSpaceEnclosed; var charNextIsCharOrString = charNext == '"' || charNext == '\''; switch (e.Char) { case '(': if (charNextIsCharOrString) { return; } _codeArea.InsertText(caretPos, ")"); break; case '{': if (charNextIsCharOrString) { return; } _codeArea.InsertText(caretPos, "}"); break; case '[': if (charNextIsCharOrString) { return; } _codeArea.InsertText(caretPos, "]"); break; case '"': // 0x22 = " if (charPrev == 0x22 && charNext == 0x22) { _codeArea.DeleteRange(caretPos, 1); _codeArea.GotoPosition(caretPos); return; } if (isCharOrString) { _codeArea.InsertText(caretPos, "\""); } break; case '\'': // 0x27 = ' if (charPrev == 0x27 && charNext == 0x27) { _codeArea.DeleteRange(caretPos, 1); _codeArea.GotoPosition(caretPos); return; } if (isCharOrString) { _codeArea.InsertText(caretPos, "'"); } break; } }