Esempio n. 1
0
        public void InsertSnippet()
        {
            var editor = new ScintillaGateway(PluginBase.GetCurrentScintilla());

            editor.AddText(SnippetBody.Length, SnippetBody);

            using (TextToFind textToFind = new TextToFind(editor.GetCurrentPos().Value - SnippetBody.Length, editor.GetCurrentPos().Value, Placeholder))
            {
                Position placeholderPosition = editor.FindText(0, textToFind);
                editor.SetSelection(placeholderPosition.Value + Placeholder.Length, placeholderPosition.Value);
            }
        }
Esempio n. 2
0
        public void InsertSnippet()
        {
            ScintillaGateway editor = new ScintillaGateway(PluginBase.GetCurrentScintilla());

            editor.BeginUndoAction();

            Position end    = editor.GetLineEndPosition(editor.LineFromPosition(editor.GetSelectionEnd()));
            Position start  = editor.PositionFromLine(editor.LineFromPosition(editor.GetSelectionStart()));
            int      indent = KeepIndent ? editor.GetLineIndentation(editor.LineFromPosition(start)) : 0;

            string insertText = IndentSnippetBody(SnippetBodyBefore, indent)
                                + IndentSelectedStrings(editor, start, end)
                                + IndentSnippetBody(SnippetBodyAfter, indent);

            editor.DeleteRange(start, end.Value - start.Value + 1);
            editor.InsertText(start, insertText);
            using (TextToFind textToFind = new TextToFind(start.Value, start.Value + insertText.Length, Placeholder))
            {
                Position placeholderPosition = editor.FindText(0, textToFind);
                editor.SetSelection(placeholderPosition.Value + Placeholder.Length, placeholderPosition.Value);
            }
            editor.EndUndoAction();
        }
Esempio n. 3
0
        private static bool SearchNextSectionOrPerform(string sectionName, int offset)
        {
            var editor = new ScintillaGateway(PluginBase.GetCurrentScintilla());

            using (TextToFind textToFind = new TextToFind(offset, editor.GetTextLength() - 1, sectionName))
            {
                Position sectionPosition = editor.FindText(0, textToFind);
                if (sectionPosition.Value >= 0)
                {
                    if (editor.GetLine(editor.LineFromPosition(sectionPosition)).StartsWith("*"))
                    {
                        CurrentSearchOffset = sectionPosition.Value + sectionName.Length;
                        return(SearchNextSectionOrPerform(sectionName, CurrentSearchOffset));
                    }
                    ScrollToLine(editor.LineFromPosition(sectionPosition));
                    CurrentSearchOffset = sectionPosition.Value + sectionName.Length;
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }