1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-23 18:18:00 +02:00

Added more editor keys and commands

This commit is contained in:
Brian Fiete 2020-06-13 15:55:08 -07:00
parent a3d8bd492d
commit d463832168
5 changed files with 217 additions and 87 deletions

View file

@ -191,9 +191,11 @@ namespace IDE
Add("Close All Windows", new () => { gApp.[Friend]TryCloseAllDocuments(); });
Add("Close Window", new () => { gApp.[Friend]TryCloseCurrentDocument(); });
Add("Close Workspace", new => gApp.[Friend]Cmd_CloseWorkspaceAndSetupNew);
Add("Comment Selection", new => gApp.[Friend]CommentSelection);
Add("Compile File", new => gApp.Cmd_CompileFile);
Add("Debug All Tests", new () => { gApp.[Friend]RunTests(true, true); });
Add("Debug Normal Tests", new () => { gApp.[Friend]RunTests(false, true); });
Add("Duplicate Line", new () => { gApp.[Friend]DuplicateLine(); });
Add("Exit", new => gApp.[Friend]Cmd_Exit);
Add("Find All References", new => gApp.Cmd_FindAllReferences);
Add("Find Class", new => gApp.Cmd_FindClass);
@ -276,6 +278,7 @@ namespace IDE
Add("Tab Last", new => gApp.[Friend]TabLast);
Add("Tab Next", new => gApp.[Friend]TabNext);
Add("Tab Prev", new => gApp.[Friend]TabPrev);
Add("Uncomment Selection", new => gApp.[Friend]UncommentSelection);
Add("View New", new => gApp.Cmd_ViewNew);
Add("View Split", new => gApp.[Friend]ViewSplit);
Add("View White Space", new => gApp.Cmd_ViewWhiteSpace);

View file

@ -2291,6 +2291,30 @@ namespace IDE
//FinishShowingNewWorkspace();
}
[IDECommand]
void DuplicateLine()
{
var sewc = GetActiveSourceEditWidgetContent();
if (sewc != null)
sewc.DuplicateLine();
}
[IDECommand]
void CommentSelection()
{
var sewc = GetActiveSourceEditWidgetContent();
if (sewc != null)
sewc.ToggleComment(true);
}
[IDECommand]
void UncommentSelection()
{
var sewc = GetActiveSourceEditWidgetContent();
if (sewc != null)
sewc.ToggleComment(false);
}
public Result<void, StructuredData.Error> StructuredLoad(StructuredData data, StringView filePath)
{
if (mWorkspace.IsSingleFileWorkspace)

View file

@ -448,6 +448,8 @@ namespace IDE
Add("Cancel Build", "Ctrl+Break");
Add("Close Window", "Ctrl+W");
Add("Compile File", "Ctrl+F7");
Add("Comment Selection", "Ctrl+K, Ctrl+C");
Add("Duplicate Line", "Ctrl+D");
Add("Find Class", "Alt+Shift+L");
Add("Find in Document", "Ctrl+F");
Add("Find in Files", "Ctrl+Shift+F");
@ -512,6 +514,7 @@ namespace IDE
Add("Tab Last", "Ctrl+Alt+End");
Add("Tab Next", "Ctrl+Alt+PageDown");
Add("Tab Prev", "Ctrl+Alt+PageUp");
Add("Uncomment Selection", "Ctrl+K, Ctrl+U");
Add("Zoom In", "Ctrl+Equals");
Add("Zoom Out", "Ctrl+Minus");
Add("Zoom Reset", "Ctrl+0");

View file

@ -1984,18 +1984,20 @@ namespace IDE.ui
return true;
}
public bool ToggleComment()
public bool ToggleComment(bool? doComment = null)
{
if (CheckReadOnly())
return false;
if ((HasSelection()) && (mSelection.Value.Length > 1))
{
var startLineAndCol = CursorLineAndColumn ;
var startLineAndCol = CursorLineAndColumn;
UndoBatchStart undoBatchStart = new UndoBatchStart("embeddedToggleComment");
mData.mUndoManager.Add(undoBatchStart);
mData.mUndoManager.Add(new SetCursorAction(this));
int minPos = mSelection.GetValueOrDefault().MinPos;
int maxPos = mSelection.GetValueOrDefault().MaxPos;
mSelection = null;
@ -2014,7 +2016,7 @@ namespace IDE.ui
int firstCharPos = minPos + (startLen - afterTrimStart);
int lastCharPos = maxPos - (afterTrimStart - afterTrimEnd);
if (trimmedStr.StartsWith("/*"))
if ((doComment != true) && (trimmedStr.StartsWith("/*")))
{
if (trimmedStr.EndsWith("*/"))
{
@ -2022,28 +2024,57 @@ namespace IDE.ui
DeleteChar();
mSelection = EditSelection(lastCharPos - 4, lastCharPos - 2);
DeleteChar();
if (doComment != null)
mSelection = EditSelection(firstCharPos, lastCharPos - 4);
}
}
else
else if (doComment != false)
{
CursorTextPos = firstCharPos;
InsertAtCursor("/*");
CursorTextPos = lastCharPos + 2;
InsertAtCursor("*/");
if (doComment != null)
mSelection = EditSelection(firstCharPos, lastCharPos + 4);
}
if (undoBatchStart != null)
mData.mUndoManager.Add(undoBatchStart.mBatchEnd);
CursorLineAndColumn = startLineAndCol;
mSelection = null;
if (doComment == null)
mSelection = null;
return true;
}
return false;
}
public void DuplicateLine()
{
UndoBatchStart undoBatchStart = new UndoBatchStart("embeddedToggleComment");
mData.mUndoManager.Add(undoBatchStart);
mData.mUndoManager.Add(new SetCursorAction(this));
var prevCursorLineAndColumn = CursorLineAndColumn;
int lineNum = CursorLineAndColumn.mLine;
GetLinePosition(lineNum, var lineStart, var lineEnd);
var str = scope String();
GetLineText(lineNum, str);
mSelection = null;
str.Append("\n");
CursorLineAndColumn = LineAndColumn(lineNum, 0);
InsertAtCursor(str);
CursorLineAndColumn = LineAndColumn(prevCursorLineAndColumn.mLine + 1, prevCursorLineAndColumn.mColumn);
mData.mUndoManager.Add(undoBatchStart.mBatchEnd);
}
public override void ContentChanged()
{
base.ContentChanged();
@ -2064,24 +2095,7 @@ namespace IDE.ui
scope AutoBeefPerf("SEWC.KeyChar");
var keyChar;
if (keyChar == '\x7F') // Ctrl+Backspace
{
int line;
int lineChar;
GetCursorLineChar(out line, out lineChar);
int startIdx = CursorTextPos;
SelectLeft(line, lineChar, true, false);
mSelection = EditSelection(CursorTextPos, startIdx);
var action = new DeleteSelectionAction(this);
action.mMoveCursor = true;
mData.mUndoManager.Add(action);
action.mCursorTextPos = (.)startIdx;
PhysDeleteSelection(true);
return;
}
if (mIgnoreKeyChar)
{