public void OnNotification(ScNotification notification) { if (isPanelVisible) { if (notification.Header.Code == (uint)SciMsg.SCN_UPDATEUI) { if (syncViewWithCaretPosition && lastCaretPosition != scintillaGateway.GetCurrentPos().Value) { lastCaretPosition = scintillaGateway.GetCurrentPos().Value; ScrollToElementAtLineNo(scintillaGateway.GetCurrentLineNumber()); } } else if (notification.Header.Code == (uint)NppMsg.NPPN_BUFFERACTIVATED) { RenderMarkdown(); } else if (notification.Header.Code == (uint)SciMsg.SCN_MODIFIED) { bool isInsert = (notification.ModificationType & (uint)SciMsg.SC_MOD_INSERTTEXT) != 0; bool isDelete = (notification.ModificationType & (uint)SciMsg.SC_MOD_DELETETEXT) != 0; // Any modifications made ? if (isInsert || isDelete) { lastTickCount = Environment.TickCount; RenderMarkdown(); } } } }
internal static Tuple <string, Position, Position> extractHexFromCurrentPosition(IScintillaGateway scintillaGateway) { Position position = scintillaGateway.GetCurrentPos(); int ch = scintillaGateway.GetCharAt(position); if (!isValidHex((char)ch)) { MessageBox.Show("invalid hex character under cursor"); return(null); } // scan backward Position positionOfHex = findBeginningOfFragment(scintillaGateway, position, isValidHex); // get hex from known start position until last valid character return(getFragmentStartingFrom(scintillaGateway, positionOfHex.Value, isValidHex)); }
internal static Tuple <string, Position, Position> extractBase64FromCurrentPosition(IScintillaGateway scintillaGateway) { int max = scintillaGateway.GetLength(); Position position = scintillaGateway.GetCurrentPos(); int ch = scintillaGateway.GetCharAt(position); if (!isValidBase64Character((char)ch)) { MessageBox.Show("invalid base64 character under cursor"); return(null); } // scan backward Position positionOfBase64 = findBeginningOfFragment(scintillaGateway, position, isValidBase64Character); // get base64 from known start position until last valid character return(getFragmentStartingFrom(scintillaGateway, positionOfBase64.Value, isValidBase64Character)); }
public void Insert(string output) { var pos = scintilla.GetCurrentPos(); scintilla.InsertText(pos, output); }
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(); } } } }
static public string TextBeforeCursor(this IScintillaGateway document, int maxLength) { int currentPos = document.GetCurrentPos(); return(document.TextBeforePosition(currentPos, maxLength)); }
public void OnNotification(ScNotification notification) { if (isPanelVisible) { if (notification.Header.Code == (uint)SciMsg.SCN_UPDATEUI) { if (!(ValidateMkdnExtension() || ValidateHtmlExtension())) { return; } var firstVisible = scintillaGateway.GetFirstVisibleLine(); var buffer = scintillaGateway.LinesOnScreen() / 2; var lastLine = scintillaGateway.GetLineCount(); if (syncViewWithCaretPosition && lastCaretPosition != scintillaGateway.GetCurrentPos().Value) { lastCaretPosition = scintillaGateway.GetCurrentPos().Value; if ((scintillaGateway.GetCurrentLineNumber() - buffer) < 0) { ScrollToElementAtLineNo(0); } else { ScrollToElementAtLineNo(scintillaGateway.GetCurrentLineNumber() - buffer); } } else if (syncViewWithScrollPosition && lastCaretPosition != scintillaGateway.GetFirstVisibleLine()) { lastCaretPosition = scintillaGateway.GetFirstVisibleLine(); var middleLine = lastCaretPosition + buffer; if (scintillaGateway.GetFirstVisibleLine() == 0) { ScrollToElementAtLineNo(0); } else if ((lastCaretPosition + scintillaGateway.LinesOnScreen()) >= lastLine) { ScrollToElementAtLineNo(lastLine); } else { ScrollToElementAtLineNo(middleLine - buffer); } } } else if (notification.Header.Code == (uint)NppMsg.NPPN_BUFFERACTIVATED) { UpdateEditorInformation(); RenderMarkdown(); } else if (notification.Header.Code == (uint)SciMsg.SCN_MODIFIED) { // bool isInsert = (notification.ModificationType & (uint)SciMsg.SC_MOD_INSERTTEXT) != 0; // bool isDelete = (notification.ModificationType & (uint)SciMsg.SC_MOD_DELETETEXT) != 0; // // Any modifications made ? // if (isInsert || isDelete) // { if (ValidateMkdnExtension() || ValidateHtmlExtension()) { lastTickCount = Environment.TickCount; RenderMarkdown(); } // } } else if (notification.Header.Code == (uint)NppMsg.NPPN_FILESAVED) { RenderMarkdown(); } } }