本文整理汇总了C#中ScintillaNet.ScintillaControl.LineIndentPosition方法的典型用法代码示例。如果您正苦于以下问题:C# ScintillaControl.LineIndentPosition方法的具体用法?C# ScintillaControl.LineIndentPosition怎么用?C# ScintillaControl.LineIndentPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ScintillaNet.ScintillaControl
的用法示例。
在下文中一共展示了ScintillaControl.LineIndentPosition方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetOrSetPointOfInsertion
/// <summary>
/// Looks for the best next position to insert new code, inserting new lines if needed
/// </summary>
/// <param name="startPos">The position inside the Scintilla document to start looking for the insertion position</param>
/// <param name="endPos">The end position inside the Scintilla document</param>
/// <param name="baseLine">The line inside the document to use as the base for the indentation level and detect if the desired point
/// matches the end line</param>
/// <param name="sci">The ScintillaControl where our document resides</param>
/// <returns>The insertion point position</returns>
private static int GetOrSetPointOfInsertion(int startPos, int endPos, int baseLine, ScintillaControl sci)
{
char[] characterClass = { ' ', '\r', '\n', '\t' };
int nCount = 0;
int extraLine = 1;
int initialLn = sci.LineFromPosition(startPos);
int baseIndent = sci.GetLineIndentation(baseLine);
bool found = false;
while (startPos <= endPos)
{
char c = (char)sci.CharAt(startPos);
if (Array.IndexOf(characterClass, c) == -1)
{
int endLn = sci.LineFromPosition(startPos);
if (endLn == baseLine || endLn == initialLn)
{
sci.InsertText(startPos, sci.NewLineMarker);
// Do we want to set the line indentation no matter what? {\r\t\t\t\r} -> {\r\t\r}
// Better results in most cases, but maybe highly unwanted in others?
sci.SetLineIndentation(++endLn, baseIndent + sci.Indent);
startPos = sci.LineIndentPosition(endLn);
}
if (c == '}')
{
sci.InsertText(startPos, sci.NewLineMarker);
sci.SetLineIndentation(endLn + 1, baseIndent);
// In relation with previous comment... we'll reinden this one: {\r} -> {\r\t\r}
if (sci.GetLineIndentation(endLn) <= baseIndent)
{
sci.SetLineIndentation(endLn, baseIndent + sci.Indent);
startPos = sci.LineIndentPosition(endLn);
}
}
found = true;
break;
}
else if (sci.EOLMode == 1 && c == '\r' && (++nCount) > extraLine)
{
found = true;
break;
}
else if (c == '\n' && (++nCount) > extraLine)
{
if (sci.EOLMode != 2)
{
startPos--;
}
found = true;
break;
}
startPos++;
}
if (!found) startPos--;
return startPos;
}
示例2: OnChar
//.........这里部分代码省略.........
subIndent = true;
checkStart = "</" + tmpTag.Name;
indent = sci.GetLineIndentation(sci.LineFromPosition(tmpTag.Position));
}
else
{
indent = sci.GetLineIndentation(sci.LineFromPosition(tmpTag.Position));
}
}
}
else if (ctag.Name != null)
{
// Indentation. Some IDEs use the tag position, VS uses the tag start line indentation.
indent = sci.GetLineIndentation(sci.LineFromPosition(ctag.Position));
checkStart = "</" + ctag.Name;
if (ctag.Name.ToLower() == "script" || ctag.Name.ToLower() == "style")
subIndent = false;
}
try
{
sci.BeginUndoAction();
if (checkStart != null)
{
text = sci.GetLine(line).TrimStart();
if (text.StartsWith(checkStart))
{
sci.SetLineIndentation(line, indent);
sci.InsertText(sci.PositionFromLine(line), LineEndDetector.GetNewLineMarker(sci.EOLMode));
}
}
// Indent the code
if (subIndent) indent += sci.Indent;
sci.SetLineIndentation(line, indent);
position = sci.LineIndentPosition(line);
sci.SetSel(position, position);
}
finally { sci.EndUndoAction(); }
return;
}
else if (!text.EndsWith(">"))
{
ctag = GetXMLContextTag(sci, sci.CurrentPos);
if (ctag.Tag == null || ctag.Name == null) return;
// We're inside a tag. Visual Studio indents with regards to the first line, other IDEs indent using the indentation of the last line with text.
int indent;
string tag = (ctag.Tag.IndexOf('\r') > 0 || ctag.Tag.IndexOf('\n') > 0) ? ctag.Tag.Substring(0, ctag.Tag.IndexOfAny(new[] {'\r', '\n'})).TrimEnd() : ctag.Tag.TrimEnd();
if (tag.EndsWith("\""))
{
int i;
int l = tag.Length;
for (i = ctag.Name.Length + 1; i < l; i++)
{
if (!char.IsWhiteSpace(tag[i]))
break;
}
indent = sci.Column(ctag.Position) + sci.MBSafePosition(i);
}
else
{
indent = sci.GetLineIndentation(sci.LineFromPosition(ctag.Position)) + sci.Indent;
}
sci.SetLineIndentation(line, indent);
position = sci.LineIndentPosition(line);
sci.SetSel(position, position);
return;
示例3: OnChar
/// <summary>
/// Handles the incoming character
/// </summary>
public static void OnChar(ScintillaControl sci, Int32 value)
{
if (cType == XMLType.Invalid || (sci.ConfigurationLanguage != "xml" && sci.ConfigurationLanguage != "html"))
return;
XMLContextTag ctag;
Int32 position = sci.CurrentPos;
if (sci.BaseStyleAt(position) == 6 && value != '"')
return; // in XML attribute
Char c = ' ';
DataEvent de;
switch (value)
{
case 10:
// Shift+Enter to insert <BR/>
Int32 line = sci.LineFromPosition(position);
if (Control.ModifierKeys == Keys.Shift)
{
ctag = GetXMLContextTag(sci, position);
if (ctag.Tag == null || ctag.Tag.EndsWith(">"))
{
int start = sci.PositionFromLine(line)-((sci.EOLMode == 0)? 2:1);
sci.SetSel(start, position);
sci.ReplaceSel((PluginSettings.UpperCaseHtmlTags) ? "<BR/>" : "<br/>");
sci.SetSel(start+5, start+5);
return;
}
}
if (PluginSettings.SmartIndenter)
{
// Get last non-empty line
String text = "";
Int32 line2 = line - 1;
while (line2 >= 0 && text.Length == 0)
{
text = sci.GetLine(line2).TrimEnd();
line2--;
}
if ((text.EndsWith(">") && !text.EndsWith("?>") && !text.EndsWith("%>") && !closingTag.IsMatch(text)) || text.EndsWith("<!--") || text.EndsWith("<![CDATA["))
{
// Get the previous tag
do
{
position--;
c = (Char)sci.CharAt(position);
}
while (position > 0 && c != '>');
ctag = GetXMLContextTag(sci, c == '>' ? position + 1 : position);
if ((Char)sci.CharAt(position-1) == '/') return;
// Insert blank line if we pressed Enter between a tag & it's closing tag
Int32 indent = sci.GetLineIndentation(line2 + 1);
String checkStart = null;
bool subIndent = true;
if (text.EndsWith("<!--")) { checkStart = "-->"; subIndent = false; }
else if (text.EndsWith("<![CDATA[")) { checkStart = "]]>"; subIndent = false; }
else if (ctag.Closed) subIndent = false;
else if (ctag.Name != null)
{
checkStart = "</" + ctag.Name;
if (ctag.Name.ToLower() == "script" || ctag.Name.ToLower() == "style")
subIndent = false;
if (ctag.Tag.IndexOf('\r') > 0 || ctag.Tag.IndexOf('\n') > 0)
subIndent = false;
}
if (checkStart != null)
{
text = sci.GetLine(line).TrimStart();
if (text.StartsWith(checkStart))
{
sci.SetLineIndentation(line, indent);
sci.InsertText(sci.PositionFromLine(line), LineEndDetector.GetNewLineMarker(sci.EOLMode));
}
}
// Indent the code
if (subIndent) indent += sci.Indent;
sci.SetLineIndentation(line, indent);
position = sci.LineIndentPosition(line);
sci.SetSel(position, position);
return;
}
}
break;
case '<':
case '/':
if (value == '/')
{
if ((position < 2) || ((Char)sci.CharAt(position-2) != '<')) return;
ctag = new XMLContextTag();
ctag.Closing = true;
}
else
{
ctag = GetXMLContextTag(sci, position);
if (ctag.Tag != null) return;
}
// Allow another plugin to handle this
//.........这里部分代码省略.........
示例4: ToggleBlockOnCurrentLine
private void ToggleBlockOnCurrentLine(ScintillaControl sci)
{
Int32 selStart = sci.SelectionStart;
Int32 indentPos = sci.LineIndentPosition(sci.CurrentLine);
Int32 lineEndPos = sci.LineEndPosition(sci.CurrentLine);
bool afterBlockStart = sci.CurrentPos > indentPos;
bool afterBlockEnd = sci.CurrentPos >= lineEndPos;
sci.SelectionStart = indentPos;
sci.SelectionEnd = lineEndPos;
bool ? added = CommentSelection();
if (added == null) return;
int factor = (bool)added ? 1 : -1;
String commentEnd = ScintillaManager.GetCommentEnd(sci.ConfigurationLanguage);
String commentStart = ScintillaManager.GetCommentStart(sci.ConfigurationLanguage);
// preserve cursor pos
if (afterBlockStart) selStart += commentStart.Length * factor;
if (afterBlockEnd) selStart += commentEnd.Length * factor;
sci.SetSel(selStart, selStart);
}
示例5: OnChar
static public void OnChar(ScintillaControl sci, int value)
{
if (cType == XMLType.Invalid)
return;
XMLContextTag ctag;
int position = sci.CurrentPos;
char c = ' ';
switch (value)
{
case 10:
int line = sci.LineFromPosition(position);
// Shift+Enter to insert <BR/>
if (Control.ModifierKeys == Keys.Shift)
{
ctag = GetXMLContextTag(sci, position);
if (ctag.Tag == null || ctag.Tag.EndsWith(">"))
{
int start = sci.PositionFromLine(line)-((sci.EOLMode == 0)? 2:1);
sci.SetSel(start, position);
sci.ReplaceSel((lowerCaseHtmlTags)?"<br/>":"<BR/>");
sci.SetSel(start+5, start+5);
return;
}
}
if (autoIndent)
{
// get last non-empty line
string text = "";
int line2 = line-1;
while (line2 >= 0 && text.Length == 0)
{
text = sci.GetLine(line2).TrimEnd();
line2--;
}
if ((text.EndsWith(">") && !text.EndsWith("?>") && !text.EndsWith("%>") && !re_closingTag.IsMatch(text))
|| text.EndsWith("<!--") || text.EndsWith("<![CDATA["))
{
// get the previous tag
do {
position--;
c = (char)sci.CharAt(position);
}
while (position > 0 && c != '>');
ctag = GetXMLContextTag(sci, position);
if ((char)sci.CharAt(position-1) == '/')
return;
// insert blank line if we pressed Enter between a tag & it's closing tag
int indent = sci.GetLineIndentation(line2+1);
string checkStart = null;
if (text.EndsWith("<!--")) checkStart = "-->";
else if (text.EndsWith("<![CDATA[")) checkStart = "]]>";
else if (ctag.Name != null) checkStart = "</"+ctag.Name;
if (checkStart != null)
{
text = sci.GetLine(line).TrimStart();
if (text.StartsWith(checkStart))
{
sci.SetLineIndentation(line, indent);
sci.InsertText(sci.PositionFromLine(line), mainForm.GetNewLineMarker(sci.EOLMode));
}
}
// indent
sci.SetLineIndentation(line, indent+sci.Indent);
position = sci.LineIndentPosition(line);
sci.SetSel(position, position);
return;
}
}
break;
case '<':
case '/':
if (value == '/')
{
if ((position < 2) || ((char)sci.CharAt(position-2) != '<'))
return;
}
else
{
ctag = GetXMLContextTag(sci, position);
if (ctag.Tag != null)
return;
}
// new tag
if (enableHtmlCompletion && cType == XMLType.Known)
{
ArrayList items = new ArrayList();
string previous = null;
foreach(HTMLTag tag in knownTags)
if (tag.Name != previous) {
items.Add( new HtmlTagItem(tag.Name, tag.Tag) );
previous = tag.Name;
}
CompletionList.Show(items, true);
//.........这里部分代码省略.........
示例6: GenerateExtractVariable
public static void GenerateExtractVariable(ScintillaControl sci, string newName)
{
string expression = sci.SelText.Trim(new char[] { '=', ' ', '\t', '\n', '\r', ';', '.' });
expression = expression.TrimEnd(new char[] { '(', '[', '{', '<' });
expression = expression.TrimStart(new char[] { ')', ']', '}', '>' });
var cFile = ASContext.Context.CurrentModel;
ASFileParser parser = new ASFileParser();
parser.ParseSrc(cFile, sci.Text);
MemberModel current = cFile.Context.CurrentMember;
string characterClass = ScintillaControl.Configuration.GetLanguage(sci.ConfigurationLanguage).characterclass.Characters;
int funcBodyStart = GetBodyStart(current.LineFrom, current.LineTo, sci);
sci.SetSel(funcBodyStart, sci.LineEndPosition(current.LineTo));
string currentMethodBody = sci.SelText;
var insertPosition = funcBodyStart + currentMethodBody.IndexOfOrdinal(expression);
var line = sci.LineFromPosition(insertPosition);
insertPosition = sci.LineIndentPosition(line);
int lastPos = -1;
sci.Colourise(0, -1);
while (true)
{
lastPos = currentMethodBody.IndexOfOrdinal(expression, lastPos + 1);
if (lastPos > -1)
{
char prevOrNextChar;
if (lastPos > 0)
{
prevOrNextChar = currentMethodBody[lastPos - 1];
if (characterClass.IndexOf(prevOrNextChar) > -1)
{
continue;
}
}
if (lastPos + expression.Length < currentMethodBody.Length)
{
prevOrNextChar = currentMethodBody[lastPos + expression.Length];
if (characterClass.IndexOf(prevOrNextChar) > -1)
{
continue;
}
}
var pos = funcBodyStart + lastPos;
int style = sci.BaseStyleAt(pos);
if (ASComplete.IsCommentStyle(style)) continue;
sci.SetSel(pos, pos + expression.Length);
sci.ReplaceSel(newName);
currentMethodBody = currentMethodBody.Substring(0, lastPos) + newName + currentMethodBody.Substring(lastPos + expression.Length);
lastPos += newName.Length;
}
else
{
break;
}
}
sci.CurrentPos = insertPosition;
sci.SetSel(sci.CurrentPos, sci.CurrentPos);
MemberModel m = new MemberModel(newName, "", FlagType.LocalVar, 0);
m.Value = expression;
string snippet = TemplateUtils.GetTemplate("Variable");
snippet = TemplateUtils.ReplaceTemplateVariable(snippet, "Modifiers", null);
snippet = TemplateUtils.ToDeclarationString(m, snippet);
snippet += NewLine + "$(Boundary)";
SnippetHelper.InsertSnippetText(sci, sci.CurrentPos, snippet);
}