Python ScintillaNET 中的自动缩进
Python auto-indentation in ScintillaNET
我正在使用 ScintillaNET 开发 Winforms 应用程序。我意识到 ScintillaNET 本身没有自动缩进功能。你必须自己创建一个。我在网上搜索并找到了使用大括号自动缩进的解决方案:Auto-indenting with curly brackets。
我决定在 ScintillaNET 中为 python 制作一个自动缩进功能。由于 Python 的语法不使用大括号,而是 :
,因此引用的代码不适用。因此,我尝试使用 InsertChecked
功能来检查换行前的自动缩进触发器。基本上,如果用户键入 :
然后添加新行 \n
,则表示定义了 condition/class 或定义。
为确保我们不会误解用户的意图,假设在 Python 中,您执行 string[1:2]
以获得子字符串,则此功能将不适用。我们可以通过执行以下操作来确保。
if (caretPosition != 0 && caretPosition != ScintillaControl.Text.Length) //if not at the end or start
{
}
但到目前为止,我只有一个功能 auto indents after : but does not increment that indent by 4 per last line
。很奇怪,因为应该可以得到最后一行的长度,然后加4(缩进)。很难解释,我在下面提供了一张GIF图片:
所以,有人可以更好地实现我想弄清楚的东西吗?还是采用最后一行长度然后在触发字符出现后添加自动缩进的函数?这是我的代码:
private void textarea_InsertCheck(object sender, InsertCheckEventArgs e)
{
if ((e.Text.EndsWith("\r") || e.Text.EndsWith("\n")))
{
var curLine = TextArea.LineFromPosition(e.Position);
var curLineText = TextArea.Lines[curLine].Text;
var indent = Regex.Match(curLineText, @"");
if (Regex.IsMatch(curLineText, @":"))
e.Text += '\t';
}
}
帮我解决这个问题。
好吧,我看到没有人有实现这个的想法,但谢天谢地,我一直在做一些研究,发现这个旧线程对搜索引擎不可见,它解释了我正在寻找的内容:https://github.com/jacobslusser/ScintillaNET/issues/137
哇哦。
我正在使用 ScintillaNET 开发 Winforms 应用程序。我意识到 ScintillaNET 本身没有自动缩进功能。你必须自己创建一个。我在网上搜索并找到了使用大括号自动缩进的解决方案:Auto-indenting with curly brackets。
我决定在 ScintillaNET 中为 python 制作一个自动缩进功能。由于 Python 的语法不使用大括号,而是 :
,因此引用的代码不适用。因此,我尝试使用 InsertChecked
功能来检查换行前的自动缩进触发器。基本上,如果用户键入 :
然后添加新行 \n
,则表示定义了 condition/class 或定义。
为确保我们不会误解用户的意图,假设在 Python 中,您执行 string[1:2]
以获得子字符串,则此功能将不适用。我们可以通过执行以下操作来确保。
if (caretPosition != 0 && caretPosition != ScintillaControl.Text.Length) //if not at the end or start
{
}
但到目前为止,我只有一个功能 auto indents after : but does not increment that indent by 4 per last line
。很奇怪,因为应该可以得到最后一行的长度,然后加4(缩进)。很难解释,我在下面提供了一张GIF图片:
所以,有人可以更好地实现我想弄清楚的东西吗?还是采用最后一行长度然后在触发字符出现后添加自动缩进的函数?这是我的代码:
private void textarea_InsertCheck(object sender, InsertCheckEventArgs e)
{
if ((e.Text.EndsWith("\r") || e.Text.EndsWith("\n")))
{
var curLine = TextArea.LineFromPosition(e.Position);
var curLineText = TextArea.Lines[curLine].Text;
var indent = Regex.Match(curLineText, @"");
if (Regex.IsMatch(curLineText, @":"))
e.Text += '\t';
}
}
帮我解决这个问题。
好吧,我看到没有人有实现这个的想法,但谢天谢地,我一直在做一些研究,发现这个旧线程对搜索引擎不可见,它解释了我正在寻找的内容:https://github.com/jacobslusser/ScintillaNET/issues/137
哇哦。