private bool isNextEnd(int index) { int prevInex = index; if (prevInex < CodeDocument.Length && ( CodeDocument.GetCharAt(prevInex) == ' ' || CodeDocument.GetCharAt(prevInex) == '\t' ) ) { prevInex++; } if (prevInex >= CodeDocument.Length || CodeDocument.GetCharAt(prevInex) != 'e') { return(false); } prevInex++; if (prevInex >= CodeDocument.Length || CodeDocument.GetCharAt(prevInex) != 'n') { return(false); } prevInex++; if (CodeDocument.GetCharAt(prevInex) != 'd') { return(false); } return(true); }
private bool isPrevBegin(int index) { int prevInex = index; if (prevInex > 0) { prevInex--; } if (prevInex > 0 && CodeDocument.GetCharAt(prevInex) == '\n') { prevInex--; } if (prevInex > 0 && CodeDocument.GetCharAt(prevInex) == '\r') { prevInex--; } if (prevInex == 0 || CodeDocument.GetCharAt(prevInex) != 'n') { return(false); } prevInex--; if (prevInex == 0 || CodeDocument.GetCharAt(prevInex) != 'i') { return(false); } prevInex--; if (prevInex == 0 || CodeDocument.GetCharAt(prevInex) != 'g') { return(false); } prevInex--; if (prevInex == 0 || CodeDocument.GetCharAt(prevInex) != 'e') { return(false); } prevInex--; if (CodeDocument.GetCharAt(prevInex) != 'b') { return(false); } return(true); }
private void applyAutoInput() { int index = CodeDocument.CaretIndex; int line = CodeDocument.GetLineAt(index); if (line == 0) { return; } int prevLine = line - 1; int lineHeadIndex = CodeDocument.GetLineStartIndex(line); int prevLineHeadIndex = CodeDocument.GetLineStartIndex(prevLine); int prevTabs = 0; for (int i = prevLineHeadIndex; i < lineHeadIndex; i++) { char ch = CodeDocument.GetCharAt(i); if (ch == '\t') { prevTabs++; } else { break; } } int indentLength = 0; for (int i = lineHeadIndex; i < CodeDocument.Length; i++) { char ch = CodeDocument.GetCharAt(i); if (ch == '\t') { indentLength++; } else if (ch == ' ') { indentLength++; } else { break; } } bool prevBegin = isPrevBegin(lineHeadIndex); bool nextEnd = isNextEnd(lineHeadIndex); if (prevBegin) { if (nextEnd) // caret is sandwiched beteen begin and end { // BEFORE // begin[enter] end // AFTER // begin // [caret] // end CodeDocument.Replace(lineHeadIndex, indentLength, 0, new String('\t', prevTabs + 1) + "\r\n" + new String('\t', prevTabs)); CodeDocument.CaretIndex = CodeDocument.CaretIndex + prevTabs + 1 + 1 - indentLength; return; } else { // add indent prevTabs++; } } CodeDocument.Replace(lineHeadIndex, indentLength, 0, new String('\t', prevTabs)); CodeDocument.CaretIndex = CodeDocument.CaretIndex + prevTabs - indentLength; }