Fixed, Script Editor: in some cases "[EP]" (Entry Position) markers were processed incorrectly when inserting a snippet.

Updated SharpCompress library to 0.11.5.
Updated ScintillaNET library to 3.6.3.
This commit is contained in:
MaxED 2016-03-14 13:41:26 +00:00 committed by spherallic
parent a82102a611
commit f489abba63
5 changed files with 39 additions and 42 deletions

Binary file not shown.

Binary file not shown.

View file

@ -551,10 +551,10 @@
</ItemGroup>
<ItemGroup>
<Reference Include="JetBrains.Profiler.Core.Api, Version=1.3.1661.20096, Culture=neutral, PublicKeyToken=1010a0d8d6380325" Condition=" '$(Configuration)|$(Platform)' == 'Debug + Profiler|x86' Or '$(Configuration)|$(Platform)' == 'Release + Profiler|x86' " />
<Reference Include="ScintillaNET.3.5, Version=3.5.6.0, Culture=neutral, processorArchitecture=x86">
<Reference Include="ScintillaNET.3.5, Version=3.5.8.0, Culture=neutral, processorArchitecture=x86">
<Private>False</Private>
</Reference>
<Reference Include="SharpCompress.3.5, Version=0.11.2.0, Culture=neutral, processorArchitecture=x86">
<Reference Include="SharpCompress.3.5, Version=0.11.5.0, Culture=neutral, processorArchitecture=x86">
<Private>False</Private>
</Reference>
<Reference Include="SlimDX, Version=2.0.13.43, Culture=neutral, PublicKeyToken=b1b0c32fd1ffe4f9, processorArchitecture=x86" />

View file

@ -48,9 +48,7 @@ namespace CodeImp.DoomBuilder.Config
{
#region ================== Constants
private const string WORD_CHARS = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; //mxd
#endregion
#endregion
#region ================== Variables
@ -62,8 +60,8 @@ namespace CodeImp.DoomBuilder.Config
// Editor settings
private readonly string description;
private readonly int codepage;
private readonly string wordchars; //mxd. Characters to be threated as part of a word by Scintilla
private readonly string[] extensions;
private readonly string extrawordchars; //mxd. Extra characters to be threated as part of a word by Scintilla
private readonly string[] extensions;
private readonly bool casesensitive;
private readonly int insertcase;
private readonly Lexer lexer;
@ -115,8 +113,8 @@ namespace CodeImp.DoomBuilder.Config
public string ArrayClose { get { return arrayclose; } } //mxd
public string ArgumentDelimiter { get { return argumentdelimiter; } }
public string Terminator { get { return terminator; } }
public string WordCharacters { get { return wordchars; } } //mxd
public ScriptType ScriptType { get { return scripttype; } } //mxd
public string ExtraWordCharacters { get { return extrawordchars; } } //mxd
public ScriptType ScriptType { get { return scripttype; } } //mxd
// Collections
public ICollection<string> Keywords { get { return keywordkeyssorted; } }
@ -163,8 +161,8 @@ namespace CodeImp.DoomBuilder.Config
terminator = "";
description = "Plain text";
scripttype = ScriptType.UNKNOWN; //mxd
wordchars = WORD_CHARS; //mxd
extensions = new[] { "txt" };
extrawordchars = ""; //mxd
extensions = new[] { "txt" };
}
// Constructor
@ -201,7 +199,7 @@ namespace CodeImp.DoomBuilder.Config
argumentdelimiter = cfg.ReadSetting("argumentdelimiter", "");
terminator = cfg.ReadSetting("terminator", "");
scripttype = (ScriptType)cfg.ReadSetting("scripttype", (int)ScriptType.UNKNOWN); //mxd
wordchars = WORD_CHARS + cfg.ReadSetting("extrawordchars", ""); //mxd
extrawordchars = cfg.ReadSetting("extrawordchars", ""); //mxd
//mxd. Make braces array
if (!string.IsNullOrEmpty(functionopen)) braces.Add(functionopen[0]);

View file

@ -69,6 +69,8 @@ namespace CodeImp.DoomBuilder.Controls
private const string LEXERS_RESOURCE = "Lexers.cfg";
private const int MAX_BACKTRACK_LENGTH = 200;
private const int HIGHLIGHT_INDICATOR = 8; //mxd. Indicators 0-7 could be in use by a lexer so we'll use indicator 8 to highlight words.
private const string ENTRY_POSITION_MARKER = "[EP]"; //mxd
private const string LINE_BREAK_MARKER = "[LB]"; //mxd
#endregion
@ -352,8 +354,9 @@ namespace CodeImp.DoomBuilder.Controls
if(!lexercfg.SettingExists(lexername)) throw new InvalidOperationException("Unknown lexer " + scriptconfig.Lexer + " specified in script configuration!");
scriptedit.Lexer = scriptconfig.Lexer;
//mxd. Set word chars
scriptedit.SetWordChars(scriptconfig.WordCharacters);
//mxd. Set extra word chars?
if(!string.IsNullOrEmpty(scriptconfig.ExtraWordCharacters))
scriptedit.WordChars += scriptconfig.ExtraWordCharacters;
// Set the default style and settings
scriptedit.Styles[Style.Default].Font = General.Settings.ScriptFontName;
@ -679,16 +682,33 @@ namespace CodeImp.DoomBuilder.Controls
public void InsertSnippet(string[] lines)
{
// Insert the snippet
List<string> processedlines = new List<string>(lines.Length);
int curline = scriptedit.LineFromPosition(scriptedit.SelectionStart);
int indent = scriptedit.Lines[scriptedit.CurrentLine].Indentation;
string tabs = Environment.NewLine + GetIndentationString(indent);
string spaces = new String(' ', General.Settings.ScriptTabWidth);
string[] linebreak = { LINE_BREAK_MARKER };
int entrypos = -1;
int entryline = -1;
string[] processedlines = ProcessLineBreaks(lines);
// Process line breaks
foreach(string line in lines)
{
if(line.IndexOf(linebreak[0], StringComparison.Ordinal) != -1)
{
if(General.Settings.ScriptAllmanStyle)
processedlines.AddRange(line.Split(linebreak, StringSplitOptions.RemoveEmptyEntries));
else
processedlines.Add(line.Replace(linebreak[0], " "));
}
else
{
processedlines.Add(line);
}
}
// Process special chars, try to find entry position marker
for(int i = 0; i < lines.Length; i++)
for(int i = 0; i < processedlines.Count; i++)
{
if(!scriptedit.UseTabs) processedlines[i] = processedlines[i].Replace("\t", spaces);
@ -706,7 +726,7 @@ namespace CodeImp.DoomBuilder.Controls
}
// Replace the text
string text = string.Join(tabs, processedlines);
string text = string.Join(tabs, processedlines.ToArray());
scriptedit.SelectionStart = scriptedit.WordStartPosition(scriptedit.CurrentPosition, true);
scriptedit.SelectionEnd = scriptedit.WordEndPosition(scriptedit.CurrentPosition, true);
scriptedit.ReplaceSelection(text);
@ -714,7 +734,10 @@ namespace CodeImp.DoomBuilder.Controls
// Move the cursor if we had the [EP] marker
if(entrypos != -1)
{
scriptedit.SetEmptySelection(scriptedit.Lines[entryline].EndPosition - entrypos - 2);
// Count from the end of the line, because I don't see a reliable way to count indentation chars...
int pos = scriptedit.Lines[entryline].EndPosition - entrypos;
if(scriptedit.Lines[entryline].Text.EndsWith(Environment.NewLine)) pos -= 2;
scriptedit.SetEmptySelection(pos);
}
}
@ -957,30 +980,6 @@ namespace CodeImp.DoomBuilder.Controls
scriptedit.Markers[(int)index].Symbol = MarkerSymbol.RgbaImage;
}
//mxd. This converts [LB] markers to line breaks if necessary
private static string[] ProcessLineBreaks(string[] lines)
{
List<string> result = new List<string>(lines.Length);
string[] separator = new[] { "[LB]" };
foreach(string line in lines)
{
if(line.IndexOf(separator[0], StringComparison.Ordinal) != -1)
{
if(General.Settings.ScriptAllmanStyle)
result.AddRange(line.Split(separator, StringSplitOptions.RemoveEmptyEntries));
else
result.Add(line.Replace(separator[0], " "));
}
else
{
result.Add(line);
}
}
return result.ToArray();
}
//mxd. Autocompletion handling (https://github.com/jacobslusser/ScintillaNET/wiki/Basic-Autocompletion)
private bool ShowAutoCompletionList()
{