📄 edit.cs
字号:
}
public class InvertCaseAction : ISdPlugin
{
public ISdMessageHandler MessageHandler {
get {
return null;
}
}
void Convert(TextAreaControl textarea, Point from, Point to)
{
StringBuilder what = new StringBuilder(textarea.Buffer.Delete(from, to));
for (int i = 0; i < what.Length; ++i) {
if (Char.IsUpper(what[i]))
what[i] = Char.ToLower(what[i]);
else
what[i] = Char.ToUpper(what[i]);
}
textarea.Buffer.Insert(from, what.ToString());
textarea.UndoStack.UndoLast(2);
textarea.UpdateLines(from.Y, to.Y);
}
public void Execute(ISdPluginExecutor executor)
{
ContentWindow window = executor.Main.ActiveContentWindow;
if (window != null && window.HasTextArea) {
TextAreaControl textarea = window.TextArea;
textarea.Buffer.BeginUpdate();
if (textarea.Selection.HasSomethingSelected) {
Convert(textarea, textarea.Selection.RealStart, textarea.Selection.RealEnd);
} else
if (textarea.Caret.CaretPos.X < textarea.Buffer[textarea.Caret.CaretPos.Y].Text.Length) // cursor at line end ?
Convert(textarea, textarea.Caret.CaretPos, new Point(textarea.Caret.CaretPos.X + 1, textarea.Caret.CaretPos.Y));
textarea.Buffer.EndUpdate();
}
}
}
public class CapitalizeAction : ISdPlugin
{
public ISdMessageHandler MessageHandler {
get {
return null;
}
}
void Convert(TextAreaControl textarea, Point from, Point to)
{
StringBuilder what = new StringBuilder(textarea.Buffer.Delete(from, to).ToLower());
for (int i = 0; i < what.Length; ++i) {
if (!Char.IsLetter(what[i]) && i < what.Length - 1)
what[i + 1] = Char.ToUpper(what[i + 1]);
}
textarea.Buffer.Insert(from, what.ToString());
textarea.UndoStack.UndoLast(2);
textarea.UpdateLines(from.Y, to.Y);
}
public void Execute(ISdPluginExecutor executor)
{
ContentWindow window = executor.Main.ActiveContentWindow;
if (window != null && window.HasTextArea) {
TextAreaControl textarea = window.TextArea;
textarea.Buffer.BeginUpdate();
if (textarea.Selection.HasSomethingSelected) {
Convert(textarea, textarea.Selection.RealStart, textarea.Selection.RealEnd);
} else
if (textarea.Caret.CaretPos.X < textarea.Buffer[textarea.Caret.CaretPos.Y].Text.Length) // cursor at line end ?
Convert(textarea, textarea.Caret.CaretPos, new Point(textarea.Caret.CaretPos.X + 1, textarea.Caret.CaretPos.Y));
textarea.Buffer.EndUpdate();
}
}
}
public class ConvertTabsToSpaces : ISdPlugin
{
public ISdMessageHandler MessageHandler {
get {
return null;
}
}
void Convert(TextAreaControl textarea, int y1, int y2)
{
int redocounter = 0; // must count how many Delete operations occur
Point p1 = new Point();
Point p2 = new Point();
string spaces = "";
for (int i = 0; i < textarea.Buffer.Options.TabIndent; ++i)
spaces += ' ';
for (int i = y1; i < y2; ++i) {
p1.Y = p2.Y = i;
for (int j = 0; j < textarea.Buffer[i].Text.Length; ++j) {
if (textarea.Buffer[i].Text[j] == '\t') {
p1.X = j;
p2.X = j + 1;
textarea.Buffer.Delete(p1, p2);
textarea.Buffer.Insert(p1, spaces);
redocounter += 2;
j += textarea.Buffer.Options.TabIndent - 1; // skip inserted characters
}
}
}
textarea.Caret.CheckCaretPos(); // current cursor position may be invalid
textarea.Buffer.UndoStack.UndoLast(redocounter); // redo the whole operation (not the single deletes)
textarea.UpdateLines(y1, y2);
}
public void Execute(ISdPluginExecutor executor)
{
if (executor.Main.ActiveContentWindow == null || !executor.Main.ActiveContentWindow.HasTextArea)
return;
TextAreaControl textarea = executor.Main.ActiveContentWindow.TextArea;
textarea.Buffer.BeginUpdate();
if (textarea.Selection.HasSomethingSelected) {
int y = textarea.Selection.RealEnd.Y + 1;
if (textarea.Selection.RealEnd.X == 0)
--y;
Convert(textarea, textarea.Selection.RealStart.Y, y);
} else
Convert(textarea, 0, textarea.Buffer.Length);
textarea.Buffer.EndUpdate();
}
}
public class ConvertSpacesToTabs : ISdPlugin
{
public ISdMessageHandler MessageHandler {
get {
return null;
}
}
void Convert(TextAreaControl textarea, int y1, int y2)
{
int redocounter = 0; // must count how many Delete operations occur
Point p1 = new Point();
Point p2 = new Point();
int indent = textarea.Buffer.Options.TabIndent;
for (int i = y1; i < y2; ++i) {
p1.Y = p2.Y = i;
int spacecounter = 0;
for (int j = 0; j < textarea.Buffer[i].Text.Length; ++j) {
if (textarea.Buffer[i].Text[j] == ' ')
++spacecounter;
else
spacecounter = 0;
if (spacecounter >= indent) {
p1.X = 1 + j - spacecounter;
p2.X = j + 1;
textarea.Buffer.Delete(p1, p2);
textarea.Buffer.Insert(p1, "\t");
redocounter+=2;
spacecounter = 0;
j -= indent - 1;
}
}
}
textarea.Caret.CheckCaretPos(); // current cursor position may be invalid
textarea.Buffer.UndoStack.UndoLast(redocounter); // redo the whole operation (not the single deletes)
textarea.UpdateLines(y1, y2);
}
public void Execute(ISdPluginExecutor executor)
{
if (executor.Main.ActiveContentWindow == null || !executor.Main.ActiveContentWindow.HasTextArea)
return;
TextAreaControl textarea = executor.Main.ActiveContentWindow.TextArea;
textarea.Buffer.BeginUpdate();
if (textarea.Selection.HasSomethingSelected) {
int y = textarea.Selection.RealEnd.Y + 1;
if (textarea.Selection.RealEnd.X == 0)
--y;
Convert(textarea, textarea.Selection.RealStart.Y, y);
} else
Convert(textarea, 0, textarea.Buffer.Length);
textarea.Buffer.EndUpdate();
}
}
public class ConvertLeadingTabsToSpaces : ISdPlugin
{
public ISdMessageHandler MessageHandler {
get {
return null;
}
}
void Convert(TextAreaControl textarea, int y1, int y2)
{
int redocounter = 0; // must count how many Delete operations occur
Point p1 = new Point();
Point p2 = new Point();
string spaces = "";
for (int i = 0; i < textarea.Buffer.Options.TabIndent; ++i)
spaces += ' ';
for (int i = y1; i < y2; ++i) {
p1.Y = p2.Y = i;
for (int j = 0; j < textarea.Buffer[i].Text.Length; ++j) {
if (textarea.Buffer[i].Text[j] == '\t') {
p1.X = j;
p2.X = j + 1;
textarea.Buffer.Delete(p1, p2);
textarea.Buffer.Insert(p1, spaces);
redocounter += 2;
j += textarea.Buffer.Options.TabIndent - 1; // skip inserted characters
} else
break;
}
}
textarea.Caret.CheckCaretPos(); // current cursor position may be invalid
if (redocounter > 0)
textarea.Buffer.UndoStack.UndoLast(redocounter); // redo the whole operation (not the single deletes)
textarea.UpdateLines(y1, y2);
}
public void Execute(ISdPluginExecutor executor)
{
if (executor.Main.ActiveContentWindow == null || !executor.Main.ActiveContentWindow.HasTextArea)
return;
TextAreaControl textarea = executor.Main.ActiveContentWindow.TextArea;
textarea.Buffer.BeginUpdate();
if (textarea.Selection.HasSomethingSelected) {
int y = textarea.Selection.RealEnd.Y + 1;
if (textarea.Selection.RealEnd.X == 0)
--y;
Convert(textarea, textarea.Selection.RealStart.Y, y);
} else
Convert(textarea, 0, textarea.Buffer.Length);
textarea.Buffer.EndUpdate();
}
}
public class ConvertLeadingSpacesToTabs : ISdPlugin
{
public ISdMessageHandler MessageHandler {
get {
return null;
}
}
void Convert(TextAreaControl textarea, int y1, int y2)
{
int redocounter = 0; // must count how many Delete operations occur
Point p1 = new Point();
Point p2 = new Point();
int indent = textarea.Buffer.Options.TabIndent;
for (int i = y1; i < y2; ++i) {
p1.Y = p2.Y = i;
int spacecounter = 0;
for (int j = 0; j < textarea.Buffer[i].Text.Length; ++j) {
if (textarea.Buffer[i].Text[j] == ' ')
++spacecounter;
else
break;
if (spacecounter >= indent) {
p1.X = 1 + j - spacecounter;
p2.X = j + 1;
textarea.Buffer.Delete(p1, p2);
textarea.Buffer.Insert(p1, "\t");
redocounter+=2;
spacecounter = 0;
j -= indent - 1;
}
}
}
textarea.Caret.CheckCaretPos(); // current cursor position may be invalid
if (redocounter > 0)
textarea.Buffer.UndoStack.UndoLast(redocounter); // redo the whole operation (not the single deletes)
textarea.UpdateLines(y1, y2);
}
public void Execute(ISdPluginExecutor executor)
{
if (executor.Main.ActiveContentWindow == null || !executor.Main.ActiveContentWindow.HasTextArea)
return;
TextAreaControl textarea = executor.Main.ActiveContentWindow.TextArea;
textarea.Buffer.BeginUpdate();
if (textarea.Selection.HasSomethingSelected) {
int y = textarea.Selection.RealEnd.Y + 1;
if (textarea.Selection.RealEnd.X == 0)
--y;
Convert(textarea, textarea.Selection.RealStart.Y, y);
} else
Convert(textarea, 0, textarea.Buffer.Length);
textarea.Buffer.EndUpdate();
}
}
/// <summary>
/// This is a sample editaction plugin, it indents the selected area.
/// </summary>
public class IndentSelection : ISdPlugin
{
public ISdMessageHandler MessageHandler {
get {
return null;
}
}
public void Execute(ISdPluginExecutor executor)
{
if (executor.Main.ActiveContentWindow == null || !executor.Main.ActiveContentWindow.HasTextArea)
return;
TextAreaControl textarea = executor.Main.ActiveContentWindow.TextArea;
if (textarea.Buffer.ReadOnly)
return;
if (textarea.Selection.HasSomethingSelected) {
int y1 = textarea.Selection.RealStart.Y;
int y2 = textarea.Selection.RealEnd.Y;
Indent.IndentLines(textarea.Buffer, y1, y2, textarea.Options.IndentStyle);
} else {
Indent.IndentLines(textarea.Buffer, 0, textarea.Buffer.Length - 1, textarea.Options.IndentStyle);
}
textarea.Refresh();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -