mirror of
https://github.com/Stone-Red-Code/YesNt-Interpreter.git
synced 2026-09-10 07:56:08 +02:00
- Add some editor key combinations
- Improve saving performance
This commit is contained in:
@@ -114,10 +114,7 @@ namespace YesNt.CodeEditor
|
|||||||
}
|
}
|
||||||
|
|
||||||
Lines.Clear();
|
Lines.Clear();
|
||||||
foreach (string line in File.ReadAllLines(path))
|
Lines.AddRange(File.ReadAllLines(path));
|
||||||
{
|
|
||||||
Lines.Add(line.Replace("\n", ""));
|
|
||||||
}
|
|
||||||
CurrentPath = path;
|
CurrentPath = path;
|
||||||
inputHandler.WriteStatus("File Loaded!");
|
inputHandler.WriteStatus("File Loaded!");
|
||||||
return true;
|
return true;
|
||||||
@@ -125,14 +122,6 @@ namespace YesNt.CodeEditor
|
|||||||
|
|
||||||
public bool Save(string input, bool loadIfExists)
|
public bool Save(string input, bool loadIfExists)
|
||||||
{
|
{
|
||||||
string text = "";
|
|
||||||
|
|
||||||
foreach (string line in Lines)
|
|
||||||
{
|
|
||||||
text += line + "\n";
|
|
||||||
}
|
|
||||||
text = text.TrimEnd('\n');
|
|
||||||
|
|
||||||
string path;
|
string path;
|
||||||
if (input.Split(' ').Length == 2)
|
if (input.Split(' ').Length == 2)
|
||||||
{
|
{
|
||||||
@@ -171,9 +160,14 @@ namespace YesNt.CodeEditor
|
|||||||
path = Path.ChangeExtension(path, "ynt");
|
path = Path.ChangeExtension(path, "ynt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (Lines.Count > 0 && string.IsNullOrWhiteSpace(Lines[Lines.Count - 1]))
|
||||||
|
{
|
||||||
|
Lines.RemoveAt(Lines.Count - 1);
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
File.WriteAllText(path, text);
|
File.WriteAllLines(path, Lines);
|
||||||
inputHandler.WriteStatus("File Saved!");
|
inputHandler.WriteStatus("File Saved!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,21 @@ namespace YesNt.CodeEditor
|
|||||||
textEditor.EditMode = Mode.Command;
|
textEditor.EditMode = Mode.Command;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case ConsoleKey.B:
|
||||||
|
int position = textEditor.Lines.Count;
|
||||||
|
textEditor.CursorPosition.Y = position - 1;
|
||||||
|
textEditor.LineOffset = Math.Max(position - Console.WindowHeight + 3, 0);
|
||||||
|
|
||||||
|
textEditor.Display(true);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ConsoleKey.T:
|
||||||
|
textEditor.CursorPosition.Y = 0;
|
||||||
|
textEditor.LineOffset = 0;
|
||||||
|
|
||||||
|
textEditor.Display(true);
|
||||||
|
break;
|
||||||
|
|
||||||
case ConsoleKey.S:
|
case ConsoleKey.S:
|
||||||
textEditor.CursorPosition.X = 0;
|
textEditor.CursorPosition.X = 0;
|
||||||
break;
|
break;
|
||||||
@@ -172,6 +187,8 @@ namespace YesNt.CodeEditor
|
|||||||
string command = input.Split(' ')[0].Trim();
|
string command = input.Split(' ')[0].Trim();
|
||||||
string path;
|
string path;
|
||||||
|
|
||||||
|
Console.CursorVisible = false;
|
||||||
|
|
||||||
switch (command)
|
switch (command)
|
||||||
{
|
{
|
||||||
case "edit":
|
case "edit":
|
||||||
|
|||||||
Reference in New Issue
Block a user