Last active
June 27, 2021 17:14
-
-
Save trienow/a6682a44dc1fda6c3bd1ae0a6e6d626b to your computer and use it in GitHub Desktop.
DEPRECATED: A small C# class handling selections for the "Automation Scripts"-Plugin for Notepad++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class NppSelection | |
| { | |
| readonly IntPtr sci; | |
| public NppSelection(IntPtr currentScintilla) { sci = currentScintilla; } | |
| public int Anchor | |
| { | |
| get { return (int)Win32.SendMessage(sci, SciMsg.SCI_GETANCHOR, 0, 0); } | |
| set { Win32.SendMessage(sci, SciMsg.SCI_SETANCHOR, value, 0); } | |
| } | |
| public int Length { get { return (int)Win32.SendMessage(sci, SciMsg.SCI_GETSELTEXT, 0, 0); } } | |
| public int Pos | |
| { | |
| get { return (int)Win32.SendMessage(sci, SciMsg.SCI_GETCURRENTPOS, 0, 0); } | |
| set { Win32.SendMessage(sci, SciMsg.SCI_SETCURRENTPOS, value, 0); } | |
| } | |
| public string Text | |
| { | |
| get | |
| { | |
| int selLength = Length; | |
| IntPtr ptr = Marshal.AllocHGlobal(selLength); | |
| Win32.SendMessage(sci, SciMsg.SCI_GETSELTEXT, 0, ptr); | |
| string selText = Marshal.PtrToStringAnsi(ptr); | |
| Marshal.FreeHGlobal(ptr); | |
| return selText; | |
| } | |
| set { Win32.SendMessage(sci, SciMsg.SCI_REPLACESEL, 0, value); } | |
| } | |
| public void SetSelection(int anchor, int caret) { Win32.SendMessage(sci, SciMsg.SCI_SETSEL, anchor, caret); } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NppScripts now comes with a handy interface.
Use
Npp.Document.GetSelText()andNpp.Document.ReplaceSel(string)instead.