예제 #1
0
        /// <summary>
        /// Gets the word at cursor.
        /// </summary>
        /// <param name="point">The point - start and end position of the word.</param>
        /// <returns></returns>
        static public string GetWordAtCursor(out Point point)
        {
            IntPtr sci = Plugin.GetCurrentScintilla();

            int currentPos = (int)Win32.SendMessage(sci, SciMsg.SCI_GETCURRENTPOS, 0, 0);
            int fullLength = (int)Win32.SendMessage(sci, SciMsg.SCI_GETLENGTH, 0, 0);

            string leftText  = Npp.TextBeforeCaret(512);
            string rightText = Npp.TextAfterCaret(512);

            var delimiters = "\t\n\r .,:;'\"[]{}()".ToCharArray();

            string wordLeftPart = "";
            int    startPos     = currentPos;

            if (leftText != null)
            {
                startPos     = leftText.LastIndexOfAny(delimiters);
                wordLeftPart = (startPos != -1) ? leftText.Substring(startPos + 1) : "";
                int relativeStartPos = leftText.Length - startPos;
                startPos = (startPos != -1) ? (currentPos - relativeStartPos) + 1 : 0;
            }

            string wordRightPart = "";
            int    endPos        = currentPos;

            if (rightText != null)
            {
                endPos        = rightText.IndexOfAny(delimiters);
                wordRightPart = (endPos != -1) ? rightText.Substring(0, endPos) : "";
                endPos        = (endPos != -1) ? currentPos + endPos : fullLength;
            }

            point = new Point(startPos, endPos);
            return(wordLeftPart + wordRightPart);
        }
예제 #2
0
 /// <summary>
 /// Gets all lines of the current document.
 /// </summary>
 /// <returns></returns>
 static public string[] GetAllLines()
 {
     return(Npp.GetAllText().Split(new string[] { Environment.NewLine }, StringSplitOptions.None));
 }