public void Format() { scintilla.BeginUndoAction(); int textLength = scintilla.GetTextLength(); string text = scintilla.GetText(textLength); text = FormatText(text); scintilla.DeleteRange(new Position(0), textLength); scintilla.InsertText(new Position(0), text); scintilla.EndUndoAction(); }
public void Execute() { scintilla.BeginUndoAction(); var selections = GetSelections(); var sumChanges = InsertGuids(selections); scintilla.EndUndoAction(); var first = selections.First(); var totalDelta = new Position(sumChanges + first.Item2); scintilla.GotoPos(first.Item1 + totalDelta); }
static internal void doInsertHtmlCloseTag(char newChar) { LangType docType = LangType.L_TEXT; Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_GETCURRENTLANGTYPE, 0, ref docType); bool isDocTypeHTML = (docType == LangType.L_HTML || docType == LangType.L_XML || docType == LangType.L_PHP); if (!doCloseTag || !isDocTypeHTML) { return; } if (newChar != '>') { return; } int bufCapacity = 512; var pos = editor.GetCurrentPos(); int currentPos = pos; int beginPos = currentPos - (bufCapacity - 1); int startPos = (beginPos > 0) ? beginPos : 0; int size = currentPos - startPos; if (size < 3) { return; } using (TextRange tr = new TextRange(startPos, currentPos, bufCapacity)) { editor.GetTextRange(tr); string buf = tr.lpstrText; if (buf[size - 2] == '/') { return; } int pCur = size - 2; while ((pCur > 0) && (buf[pCur] != '<') && (buf[pCur] != '>')) { pCur--; } if (buf[pCur] == '<') { pCur++; var insertString = new StringBuilder("</"); while (regex.IsMatch(buf[pCur].ToString())) { insertString.Append(buf[pCur]); pCur++; } insertString.Append('>'); if (insertString.Length > 3) { editor.BeginUndoAction(); editor.ReplaceSel(insertString.ToString()); editor.SetSel(pos, pos); editor.EndUndoAction(); } } } }