From b3cf28f50036092d333157e7a52e08a23a24d502 Mon Sep 17 00:00:00 2001 From: unknown <81806010+marsej@users.noreply.github.com> Date: Sat, 11 Dec 2021 05:58:45 +0200 Subject: [PATCH 01/12] Added ToggleCommentAlt for who prefer multi-line // comments --- IDE/src/ui/SourceEditWidgetContent.bf | 141 ++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) diff --git a/IDE/src/ui/SourceEditWidgetContent.bf b/IDE/src/ui/SourceEditWidgetContent.bf index dbb19ef7..d632f9a7 100644 --- a/IDE/src/ui/SourceEditWidgetContent.bf +++ b/IDE/src/ui/SourceEditWidgetContent.bf @@ -2238,6 +2238,147 @@ namespace IDE.ui return false; } + public bool ToggleCommentAlt(bool? doComment = null) + { + if (CheckReadOnly()) + return false; + bool noStar = false; + if ((!HasSelection()) && (doComment != null)) + { + CursorToLineEnd(); + int cursorEndPos = CursorTextPos; + CursorToLineStart(false); + mSelection = .(CursorTextPos, cursorEndPos); + noStar = true; + } + + if ((HasSelection()) && (mSelection.Value.Length > 0)) + { + 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; + + var str = scope String(); + ExtractString(minPos, maxPos - minPos, str); + var trimmedStr = scope String(); + trimmedStr.Append(str); + int32 startLen = (int32)trimmedStr.Length; + trimmedStr.TrimStart(); + int32 afterTrimStart = (int32)trimmedStr.Length; + trimmedStr.TrimEnd(); + int32 afterTrimEnd = (int32)trimmedStr.Length; + trimmedStr.Append('\n'); + + int firstCharPos = minPos + (startLen - afterTrimStart); + int lastCharPos = maxPos - (afterTrimStart - afterTrimEnd); + if ((doComment != true) && (trimmedStr.Contains("//"))) + { + for (int i = firstCharPos; i < lastCharPos - 1; i++) + { + if (minPos == 0 || (minPos>0 && SafeGetChar(i - 1) == '\n' || SafeGetChar(i - 1) == '\t')) + if (SafeGetChar(i - 0) == '/' && SafeGetChar(i + 1) == '/') + { + mSelection = EditSelection(i - 0, i + 2); + DeleteSelection(); + lastCharPos -= 2; + while (i < maxPos && SafeGetChar(i) != '\n') + { + i++; + } + } + } + mSelection = EditSelection(minPos, lastCharPos); + } + int q = 0; + var nc = trimmedStr.Count('\n'); + if ((doComment != true) && (trimmedStr.StartsWith("/*"))) + { + if (trimmedStr.EndsWith("*/\n")) + { + mSelection = EditSelection(firstCharPos, firstCharPos + 2); + DeleteChar(); + mSelection = EditSelection(lastCharPos - 4, lastCharPos - 2); + DeleteChar(); + + if (doComment != null) + mSelection = EditSelection(firstCharPos, lastCharPos - 4); + } + } + else if (doComment != false && nc<=1 && minPos >=0 && (SafeGetChar(minPos-1) != ' ' && SafeGetChar(minPos-1) != '\t') && SafeGetChar(minPos-1) != '\n') + { //if selection is from beginning of the line then we want to use // comment, that's why the check for line count and ' ' and tab + CursorTextPos = firstCharPos; + if (noStar) { + CursorTextPos = minPos; + + InsertAtCursor("//"); //goes here if no selection + } + else + { + InsertAtCursor("/*"); + CursorTextPos = lastCharPos + 2; + InsertAtCursor("*/"); + } + if (!noStar && doComment != null) + mSelection = EditSelection(firstCharPos, lastCharPos + 4); + } + else if (doComment != false && nc>=1 && minPos >0 && (SafeGetChar(maxPos-1) != ' ' && SafeGetChar(maxPos-1) != '\t') && SafeGetChar(maxPos-1) != '\n') + { + CursorTextPos = firstCharPos; + if (noStar) { + CursorTextPos = minPos; + + InsertAtCursor("//"); //goes here if no selection + } + else + { + InsertAtCursor("/*"); + CursorTextPos = lastCharPos + 2; + InsertAtCursor("*/"); + } + if (!noStar && doComment != null) + mSelection = EditSelection(firstCharPos, lastCharPos + 4); + } + else if (doComment != false) + { + while (firstCharPos >= 0 && SafeGetChar(firstCharPos) != '\n') + { + firstCharPos--; + } + + for (int i = firstCharPos + 1; i < maxPos + q; i++) + { + CursorTextPos = i; // needed to add i < maxPos + q; for this to work with InsertAtCursor + InsertAtCursor("//"); q++; q++; + + while (SafeGetChar(i) != '\n' && i < maxPos + q) + { + i++; + } + } + mSelection = EditSelection(minPos, maxPos + q); + } + + if (undoBatchStart != null) + mData.mUndoManager.Add(undoBatchStart.mBatchEnd); + + CursorLineAndColumn = startLineAndCol; + + if (doComment == null) + mSelection = null; + + return true; + } + + return false; + } + public void DeleteAllRight() { int startPos; From 20261f5d0dd0bbd44ad218908b4f936129350467 Mon Sep 17 00:00:00 2001 From: unknown <81806010+marsej@users.noreply.github.com> Date: Sat, 11 Dec 2021 06:02:11 +0200 Subject: [PATCH 02/12] Added ToggleCommentAlt as Toggle comments alternate style under Settings/Editor --- IDE/src/Settings.bf | 2 ++ IDE/src/ui/SettingsDialog.bf | 2 +- IDE/src/ui/SourceEditWidgetContent.bf | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/IDE/src/Settings.bf b/IDE/src/Settings.bf index 6065643e..f31aed7b 100644 --- a/IDE/src/Settings.bf +++ b/IDE/src/Settings.bf @@ -650,6 +650,7 @@ namespace IDE sd.Add("EnableFileRecovery", mEnableFileRecovery); sd.Add("FormatOnSave", mFormatOnSave); sd.Add("SyncWithWorkspacePanel", mSyncWithWorkspacePanel); + sd.Add("ToggleCommentAlt", mToggleCommentAlt); } public void Deserialize(StructuredData sd) @@ -679,6 +680,7 @@ namespace IDE sd.GetEnum("EnableFileRecovery", ref mEnableFileRecovery); sd.Get("FormatOnSave", ref mFormatOnSave); sd.Get("SyncWithWorkspacePanel", ref mSyncWithWorkspacePanel); + sd.Get("ToggleCommentAlt", ref mToggleCommentAlt); } public void SetDefaults() diff --git a/IDE/src/ui/SettingsDialog.bf b/IDE/src/ui/SettingsDialog.bf index 38cf60b3..8c8026c0 100644 --- a/IDE/src/ui/SettingsDialog.bf +++ b/IDE/src/ui/SettingsDialog.bf @@ -126,7 +126,7 @@ namespace IDE.ui AddPropertiesItem(category, "Enable File Recovery", "mEnableFileRecovery"); AddPropertiesItem(category, "Format on Save", "mFormatOnSave"); AddPropertiesItem(category, "Sync with Workspace Panel", "mSyncWithWorkspacePanel"); - + AddPropertiesItem(category, "Toggle comment alternate style", "mToggleCommentAlt"); category.Open(true, true); } diff --git a/IDE/src/ui/SourceEditWidgetContent.bf b/IDE/src/ui/SourceEditWidgetContent.bf index d632f9a7..4f66ffbd 100644 --- a/IDE/src/ui/SourceEditWidgetContent.bf +++ b/IDE/src/ui/SourceEditWidgetContent.bf @@ -2162,6 +2162,8 @@ namespace IDE.ui public bool ToggleComment(bool? doComment = null) { + if (gApp.mSettings.mEditorSettings.mToggleCommentAlt) return ToggleCommentAlt(doComment); + if (CheckReadOnly()) return false; From 6e011678b473a3911958fff91f23770e9be7c0dd Mon Sep 17 00:00:00 2001 From: unknown <81806010+marsej@users.noreply.github.com> Date: Sat, 11 Dec 2021 06:15:53 +0200 Subject: [PATCH 03/12] fix whitespace --- IDE/src/ui/SourceEditWidgetContent.bf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/IDE/src/ui/SourceEditWidgetContent.bf b/IDE/src/ui/SourceEditWidgetContent.bf index 4f66ffbd..a3d94bd9 100644 --- a/IDE/src/ui/SourceEditWidgetContent.bf +++ b/IDE/src/ui/SourceEditWidgetContent.bf @@ -2295,7 +2295,7 @@ namespace IDE.ui i++; } } - } + } mSelection = EditSelection(minPos, lastCharPos); } int q = 0; @@ -2355,7 +2355,7 @@ namespace IDE.ui } for (int i = firstCharPos + 1; i < maxPos + q; i++) - { + { CursorTextPos = i; // needed to add i < maxPos + q; for this to work with InsertAtCursor InsertAtCursor("//"); q++; q++; @@ -2365,7 +2365,7 @@ namespace IDE.ui } } mSelection = EditSelection(minPos, maxPos + q); - } + } if (undoBatchStart != null) mData.mUndoManager.Add(undoBatchStart.mBatchEnd); From 14bf2addd99cd3ecacba2488738a9a6d810135a9 Mon Sep 17 00:00:00 2001 From: unknown <81806010+marsej@users.noreply.github.com> Date: Sat, 11 Dec 2021 06:20:46 +0200 Subject: [PATCH 04/12] add blank line back --- IDE/src/ui/SettingsDialog.bf | 1 + 1 file changed, 1 insertion(+) diff --git a/IDE/src/ui/SettingsDialog.bf b/IDE/src/ui/SettingsDialog.bf index 8c8026c0..7f602893 100644 --- a/IDE/src/ui/SettingsDialog.bf +++ b/IDE/src/ui/SettingsDialog.bf @@ -127,6 +127,7 @@ namespace IDE.ui AddPropertiesItem(category, "Format on Save", "mFormatOnSave"); AddPropertiesItem(category, "Sync with Workspace Panel", "mSyncWithWorkspacePanel"); AddPropertiesItem(category, "Toggle comment alternate style", "mToggleCommentAlt"); + category.Open(true, true); } From 8522ca42165b0174c358fe6b181a63dedd048fb7 Mon Sep 17 00:00:00 2001 From: unknown <81806010+marsej@users.noreply.github.com> Date: Sat, 11 Dec 2021 07:02:11 +0200 Subject: [PATCH 05/12] commenting blank now does nothing --- IDE/src/ui/SourceEditWidgetContent.bf | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/IDE/src/ui/SourceEditWidgetContent.bf b/IDE/src/ui/SourceEditWidgetContent.bf index a3d94bd9..bb06a5c2 100644 --- a/IDE/src/ui/SourceEditWidgetContent.bf +++ b/IDE/src/ui/SourceEditWidgetContent.bf @@ -2280,7 +2280,23 @@ namespace IDE.ui int firstCharPos = minPos + (startLen - afterTrimStart); int lastCharPos = maxPos - (afterTrimStart - afterTrimEnd); - if ((doComment != true) && (trimmedStr.Contains("//"))) + + int q = 0; + var nc = trimmedStr.Count('\n'); + + if(afterTrimEnd == 0) + { + if (undoBatchStart != null) + mData.mUndoManager.Add(undoBatchStart.mBatchEnd); + + CursorLineAndColumn = startLineAndCol; + + if (doComment == null) + mSelection = null; + + return false; // not sure if this should be false in blank/only whitespace selection case + } + else if ((doComment != true) && (trimmedStr.Contains("//"))) { for (int i = firstCharPos; i < lastCharPos - 1; i++) { @@ -2298,9 +2314,7 @@ namespace IDE.ui } mSelection = EditSelection(minPos, lastCharPos); } - int q = 0; - var nc = trimmedStr.Count('\n'); - if ((doComment != true) && (trimmedStr.StartsWith("/*"))) + else if ((doComment != true) && (trimmedStr.StartsWith("/*"))) { if (trimmedStr.EndsWith("*/\n")) { From 969e7af49185247b7e5cc45a851786bfb056c36c Mon Sep 17 00:00:00 2001 From: unknown <81806010+marsej@users.noreply.github.com> Date: Mon, 13 Dec 2021 03:55:27 +0200 Subject: [PATCH 06/12] fix missing mToggleCommentAlt --- IDE/src/Settings.bf | 1 + 1 file changed, 1 insertion(+) diff --git a/IDE/src/Settings.bf b/IDE/src/Settings.bf index f31aed7b..d0012c42 100644 --- a/IDE/src/Settings.bf +++ b/IDE/src/Settings.bf @@ -625,6 +625,7 @@ namespace IDE public FileRecoveryKind mEnableFileRecovery = .Yes; public bool mFormatOnSave = false; public bool mSyncWithWorkspacePanel = false; + public bool mToggleCommentAlt = false; public void Serialize(StructuredData sd) { From 76e94d1cdcadee8debc452789674e90c3e71076b Mon Sep 17 00:00:00 2001 From: unknown <81806010+marsej@users.noreply.github.com> Date: Sat, 18 Dec 2021 20:29:15 +0200 Subject: [PATCH 07/12] Add CommentLines CommentBlocks and replace ToggleComment --- IDE/src/ui/SourceEditWidgetContent.bf | 167 ++++++++++++++++++-------- 1 file changed, 120 insertions(+), 47 deletions(-) diff --git a/IDE/src/ui/SourceEditWidgetContent.bf b/IDE/src/ui/SourceEditWidgetContent.bf index bb06a5c2..7650453c 100644 --- a/IDE/src/ui/SourceEditWidgetContent.bf +++ b/IDE/src/ui/SourceEditWidgetContent.bf @@ -2160,9 +2160,9 @@ namespace IDE.ui return true; } - public bool ToggleComment(bool? doComment = null) + public bool CommentBlock() { - if (gApp.mSettings.mEditorSettings.mToggleCommentAlt) return ToggleCommentAlt(doComment); + bool? doComment = true; if (CheckReadOnly()) return false; @@ -2175,11 +2175,11 @@ namespace IDE.ui mSelection = .(CursorTextPos, cursorEndPos); } - if ((HasSelection()) && (mSelection.Value.Length > 1)) - { + if ((HasSelection()) && (mSelection.Value.Length > 1)) + { var startLineAndCol = CursorLineAndColumn; - UndoBatchStart undoBatchStart = new UndoBatchStart("embeddedToggleComment"); + UndoBatchStart undoBatchStart = new UndoBatchStart("embeddedCommentBlock"); mData.mUndoManager.Add(undoBatchStart); mData.mUndoManager.Add(new SetCursorAction(this)); @@ -2202,20 +2202,7 @@ namespace IDE.ui int firstCharPos = minPos + (startLen - afterTrimStart); int lastCharPos = maxPos - (afterTrimStart - afterTrimEnd); - if ((doComment != true) && (trimmedStr.StartsWith("/*"))) - { - if (trimmedStr.EndsWith("*/")) - { - mSelection = EditSelection(firstCharPos, firstCharPos + 2); - DeleteChar(); - mSelection = EditSelection(lastCharPos - 4, lastCharPos - 2); - DeleteChar(); - - if (doComment != null) - mSelection = EditSelection(firstCharPos, lastCharPos - 4); - } - } - else if (doComment != false) + if (doComment != false) { CursorTextPos = firstCharPos; InsertAtCursor("/*"); @@ -2234,17 +2221,109 @@ namespace IDE.ui if (doComment == null) mSelection = null; - return true; - } + return true; + } return false; } - - public bool ToggleCommentAlt(bool? doComment = null) + + public bool CommentLines() + { + bool? doComment = true; + if (CheckReadOnly()) + return false; + bool noStar = false; + + var startLineAndCol = CursorLineAndColumn; + if ((!HasSelection()) && (doComment != null)) + { + CursorToLineEnd(); + int cursorEndPos = CursorTextPos; + + mSelection = .(CursorTextPos, cursorEndPos); + noStar = true; + } + + + if (true || (HasSelection()) && (mSelection.Value.Length > 0)) + { + //int cursorEndPos = CursorTextPos; + + // set selection to begin from line start + int lineIdx; + int lineChar; + GetLineCharAtIdx(mSelection.GetValueOrDefault().MinPos,out lineIdx, out lineChar); + MoveCursorTo(lineIdx, 0); + mSelection = .(CursorTextPos, mSelection.GetValueOrDefault().MaxPos); + + UndoBatchStart undoBatchStart = new UndoBatchStart("embeddedCommentLines"); + mData.mUndoManager.Add(undoBatchStart); + + mData.mUndoManager.Add(new SetCursorAction(this)); + + int minPos = mSelection.GetValueOrDefault().MinPos; + int maxPos = mSelection.GetValueOrDefault().MaxPos; + mSelection = null; + + var str = scope String(); + ExtractString(minPos, maxPos - minPos, str); + var trimmedStr = scope String(); + trimmedStr.Append(str); + int32 startLen = (int32)trimmedStr.Length; + trimmedStr.TrimStart(); + int32 afterTrimStart = (int32)trimmedStr.Length; + trimmedStr.TrimEnd(); + //int32 afterTrimEnd = (int32)trimmedStr.Length; + trimmedStr.Append('\n'); + + int firstCharPos = minPos + (startLen - afterTrimStart); + //int lastCharPos = maxPos - (afterTrimStart - afterTrimEnd); + + int q = 0; + //var nc = trimmedStr.Count('\n'); + + if (doComment != false) + { + while (firstCharPos >= 0 && SafeGetChar(firstCharPos) != '\n') + { + firstCharPos--; + } + bool blank=true; + for (int i = firstCharPos + 1; i < maxPos + q; i++) + { + blank=false; + CursorTextPos = i; // needed to add i < maxPos + q; for this to work with InsertAtCursor + InsertAtCursor("//"); q++; q++; + + while (SafeGetChar(i) != '\n' && i < maxPos + q) + { + i++; + } + } + mSelection = EditSelection(minPos, maxPos + q); + } + + + if (undoBatchStart != null) + mData.mUndoManager.Add(undoBatchStart.mBatchEnd); + + CursorLineAndColumn = startLineAndCol; + + if (doComment == null) + mSelection = null; + + return true; + } + + //return false; + } + + public bool ToggleComment(bool? doComment = null) { if (CheckReadOnly()) return false; bool noStar = false; + var startLineAndCol = CursorLineAndColumn; if ((!HasSelection()) && (doComment != null)) { CursorToLineEnd(); @@ -2256,7 +2335,13 @@ namespace IDE.ui if ((HasSelection()) && (mSelection.Value.Length > 0)) { - var startLineAndCol = CursorLineAndColumn; + + int lineIdx; + int lineChar; + GetLineCharAtIdx(mSelection.GetValueOrDefault().MinPos,out lineIdx, out lineChar); + MoveCursorTo(lineIdx, 0); + mSelection = .(CursorTextPos, mSelection.GetValueOrDefault().MaxPos); + UndoBatchStart undoBatchStart = new UndoBatchStart("embeddedToggleComment"); mData.mUndoManager.Add(undoBatchStart); @@ -2296,11 +2381,11 @@ namespace IDE.ui return false; // not sure if this should be false in blank/only whitespace selection case } - else if ((doComment != true) && (trimmedStr.Contains("//"))) + else if ((doComment != true) && (trimmedStr.StartsWith("//"))) { - for (int i = firstCharPos; i < lastCharPos - 1; i++) + for (int i = firstCharPos; i <= lastCharPos; i++) { - if (minPos == 0 || (minPos>0 && SafeGetChar(i - 1) == '\n' || SafeGetChar(i - 1) == '\t')) + if ((minPos == 0 && i==0) || (minPos>=0 && SafeGetChar(i - 1) == '\n' || SafeGetChar(i - 1) == '\t')) if (SafeGetChar(i - 0) == '/' && SafeGetChar(i + 1) == '/') { mSelection = EditSelection(i - 0, i + 2); @@ -2312,7 +2397,11 @@ namespace IDE.ui } } } - mSelection = EditSelection(minPos, lastCharPos); + + CursorToLineEnd(); + int cursorEndPos = CursorTextPos; + mSelection = .(minPos, cursorEndPos); + } else if ((doComment != true) && (trimmedStr.StartsWith("/*"))) { @@ -2327,7 +2416,8 @@ namespace IDE.ui mSelection = EditSelection(firstCharPos, lastCharPos - 4); } } - else if (doComment != false && nc<=1 && minPos >=0 && (SafeGetChar(minPos-1) != ' ' && SafeGetChar(minPos-1) != '\t') && SafeGetChar(minPos-1) != '\n') + else if (doComment != false && minPos >=0 && ((nc<=1 && (SafeGetChar(minPos-1) != ' ' && SafeGetChar(minPos-1) != '\t') && SafeGetChar(minPos-1) != '\n') + || nc>=1 && (SafeGetChar(maxPos-1) != ' ' && SafeGetChar(maxPos-1) != '\t') && SafeGetChar(maxPos-1) != '\n')) { //if selection is from beginning of the line then we want to use // comment, that's why the check for line count and ' ' and tab CursorTextPos = firstCharPos; if (noStar) { @@ -2344,23 +2434,6 @@ namespace IDE.ui if (!noStar && doComment != null) mSelection = EditSelection(firstCharPos, lastCharPos + 4); } - else if (doComment != false && nc>=1 && minPos >0 && (SafeGetChar(maxPos-1) != ' ' && SafeGetChar(maxPos-1) != '\t') && SafeGetChar(maxPos-1) != '\n') - { - CursorTextPos = firstCharPos; - if (noStar) { - CursorTextPos = minPos; - - InsertAtCursor("//"); //goes here if no selection - } - else - { - InsertAtCursor("/*"); - CursorTextPos = lastCharPos + 2; - InsertAtCursor("*/"); - } - if (!noStar && doComment != null) - mSelection = EditSelection(firstCharPos, lastCharPos + 4); - } else if (doComment != false) { while (firstCharPos >= 0 && SafeGetChar(firstCharPos) != '\n') @@ -2394,7 +2467,7 @@ namespace IDE.ui return false; } - + public void DeleteAllRight() { int startPos; From 5a5a3b0f54fbdb97589addd73d3641a6df09f9c4 Mon Sep 17 00:00:00 2001 From: unknown <81806010+marsej@users.noreply.github.com> Date: Sat, 18 Dec 2021 20:36:46 +0200 Subject: [PATCH 08/12] Add the new commands to menu --- IDE/src/Commands.bf | 2 ++ IDE/src/IDEApp.bf | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/IDE/src/Commands.bf b/IDE/src/Commands.bf index f0b2de76..c7eeb2cf 100644 --- a/IDE/src/Commands.bf +++ b/IDE/src/Commands.bf @@ -194,6 +194,8 @@ namespace IDE Add("Close Document", new () => { gApp.[Friend]TryCloseCurrentDocument(); }); Add("Close Panel", new () => { gApp.[Friend]TryCloseCurrentPanel(); }); Add("Close Workspace", new => gApp.[Friend]Cmd_CloseWorkspaceAndSetupNew); + Add("Comment Block", new => gApp.[Friend]CommentBlock); + Add("Comment Lines", new => gApp.[Friend]CommentLines); Add("Comment Selection", new => gApp.[Friend]CommentSelection); Add("Compile File", new => gApp.Cmd_CompileFile); Add("Debug All Tests", new () => { gApp.[Friend]RunTests(true, true); }); diff --git a/IDE/src/IDEApp.bf b/IDE/src/IDEApp.bf index 0131b705..f6dbf6c4 100644 --- a/IDE/src/IDEApp.bf +++ b/IDE/src/IDEApp.bf @@ -2424,6 +2424,22 @@ namespace IDE sewc.DuplicateLine(); } + [IDECommand] + void CommentBlock() + { + var sewc = GetActiveSourceEditWidgetContent(); + if (sewc != null) + sewc.CommentBlock(); + } + + [IDECommand] + void CommentLines() + { + var sewc = GetActiveSourceEditWidgetContent(); + if (sewc != null) + sewc.CommentLines(); + } + [IDECommand] void CommentSelection() { @@ -5386,6 +5402,8 @@ namespace IDE advancedEditMenu.AddMenuItem(null); AddMenuItem(advancedEditMenu, "Make Uppercase", "Make Uppercase"); AddMenuItem(advancedEditMenu, "Make Lowercase", "Make Lowercase"); + AddMenuItem(advancedEditMenu, "Comment Block", "Comment Block"); + AddMenuItem(advancedEditMenu, "Comment Lines", "Comment Lines"); AddMenuItem(advancedEditMenu, "Comment Selection", "Comment Selection"); AddMenuItem(advancedEditMenu, "Uncomment Selection", "Uncomment Selection"); AddMenuItem(advancedEditMenu, "Reformat Document", "Reformat Document"); From 25e09590183104f455a5e88c9fe0dfad0e0760d4 Mon Sep 17 00:00:00 2001 From: unknown <81806010+marsej@users.noreply.github.com> Date: Sat, 18 Dec 2021 20:38:05 +0200 Subject: [PATCH 09/12] Add new key-defaults --- IDE/src/Settings.bf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/IDE/src/Settings.bf b/IDE/src/Settings.bf index d0012c42..d5e7536f 100644 --- a/IDE/src/Settings.bf +++ b/IDE/src/Settings.bf @@ -756,6 +756,8 @@ namespace IDE Add("Cancel Build", "Ctrl+Break"); Add("Close Document", "Ctrl+W"); Add("Compile File", "Ctrl+F7"); + Add("Comment Block", "Ctrl+K, Ctrl+B"); + Add("Comment Lines", "Ctrl+K, Ctrl+L"); Add("Comment Selection", "Ctrl+K, Ctrl+C"); Add("Duplicate Line", "Ctrl+D"); Add("Find Class", "Alt+Shift+L"); From f1652dd1aaa3c835e03b5a3859ef26d37b3e9a1b Mon Sep 17 00:00:00 2001 From: unknown <81806010+marsej@users.noreply.github.com> Date: Sat, 18 Dec 2021 20:45:02 +0200 Subject: [PATCH 10/12] Remove mToggleCommentAlt setting --- IDE/src/Settings.bf | 3 --- 1 file changed, 3 deletions(-) diff --git a/IDE/src/Settings.bf b/IDE/src/Settings.bf index d5e7536f..f3a2ca1d 100644 --- a/IDE/src/Settings.bf +++ b/IDE/src/Settings.bf @@ -625,7 +625,6 @@ namespace IDE public FileRecoveryKind mEnableFileRecovery = .Yes; public bool mFormatOnSave = false; public bool mSyncWithWorkspacePanel = false; - public bool mToggleCommentAlt = false; public void Serialize(StructuredData sd) { @@ -651,7 +650,6 @@ namespace IDE sd.Add("EnableFileRecovery", mEnableFileRecovery); sd.Add("FormatOnSave", mFormatOnSave); sd.Add("SyncWithWorkspacePanel", mSyncWithWorkspacePanel); - sd.Add("ToggleCommentAlt", mToggleCommentAlt); } public void Deserialize(StructuredData sd) @@ -681,7 +679,6 @@ namespace IDE sd.GetEnum("EnableFileRecovery", ref mEnableFileRecovery); sd.Get("FormatOnSave", ref mFormatOnSave); sd.Get("SyncWithWorkspacePanel", ref mSyncWithWorkspacePanel); - sd.Get("ToggleCommentAlt", ref mToggleCommentAlt); } public void SetDefaults() From 28ad51fbfbc6117b18d4f4ff2032ee1367a0a734 Mon Sep 17 00:00:00 2001 From: unknown <81806010+marsej@users.noreply.github.com> Date: Sat, 18 Dec 2021 20:51:04 +0200 Subject: [PATCH 11/12] fix some whitespaces --- IDE/src/ui/SourceEditWidgetContent.bf | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/IDE/src/ui/SourceEditWidgetContent.bf b/IDE/src/ui/SourceEditWidgetContent.bf index 7650453c..64862c77 100644 --- a/IDE/src/ui/SourceEditWidgetContent.bf +++ b/IDE/src/ui/SourceEditWidgetContent.bf @@ -2244,11 +2244,8 @@ namespace IDE.ui noStar = true; } - if (true || (HasSelection()) && (mSelection.Value.Length > 0)) { - //int cursorEndPos = CursorTextPos; - // set selection to begin from line start int lineIdx; int lineChar; @@ -2280,7 +2277,6 @@ namespace IDE.ui //int lastCharPos = maxPos - (afterTrimStart - afterTrimEnd); int q = 0; - //var nc = trimmedStr.Count('\n'); if (doComment != false) { @@ -2303,7 +2299,6 @@ namespace IDE.ui mSelection = EditSelection(minPos, maxPos + q); } - if (undoBatchStart != null) mData.mUndoManager.Add(undoBatchStart.mBatchEnd); @@ -2323,6 +2318,7 @@ namespace IDE.ui if (CheckReadOnly()) return false; bool noStar = false; + var startLineAndCol = CursorLineAndColumn; if ((!HasSelection()) && (doComment != null)) { @@ -2335,10 +2331,9 @@ namespace IDE.ui if ((HasSelection()) && (mSelection.Value.Length > 0)) { - int lineIdx; int lineChar; - GetLineCharAtIdx(mSelection.GetValueOrDefault().MinPos,out lineIdx, out lineChar); + GetLineCharAtIdx(mSelection.GetValueOrDefault().MinPos, out lineIdx, out lineChar); MoveCursorTo(lineIdx, 0); mSelection = .(CursorTextPos, mSelection.GetValueOrDefault().MaxPos); @@ -2385,7 +2380,7 @@ namespace IDE.ui { for (int i = firstCharPos; i <= lastCharPos; i++) { - if ((minPos == 0 && i==0) || (minPos>=0 && SafeGetChar(i - 1) == '\n' || SafeGetChar(i - 1) == '\t')) + if ((minPos == 0 && i == 0) || (minPos>=0 && SafeGetChar(i - 1) == '\n' || SafeGetChar(i - 1) == '\t')) if (SafeGetChar(i - 0) == '/' && SafeGetChar(i + 1) == '/') { mSelection = EditSelection(i - 0, i + 2); @@ -2416,8 +2411,8 @@ namespace IDE.ui mSelection = EditSelection(firstCharPos, lastCharPos - 4); } } - else if (doComment != false && minPos >=0 && ((nc<=1 && (SafeGetChar(minPos-1) != ' ' && SafeGetChar(minPos-1) != '\t') && SafeGetChar(minPos-1) != '\n') - || nc>=1 && (SafeGetChar(maxPos-1) != ' ' && SafeGetChar(maxPos-1) != '\t') && SafeGetChar(maxPos-1) != '\n')) + else if (doComment != false && minPos >=0 && ((nc <= 1 && (SafeGetChar(minPos-1) != ' ' && SafeGetChar(minPos-1) != '\t') && SafeGetChar(minPos-1) != '\n') + || nc >= 1 && (SafeGetChar(maxPos-1) != ' ' && SafeGetChar(maxPos-1) != '\t') && SafeGetChar(maxPos-1) != '\n')) { //if selection is from beginning of the line then we want to use // comment, that's why the check for line count and ' ' and tab CursorTextPos = firstCharPos; if (noStar) { From 77db22d0951ff3ced2fbc26be11fc400056d6ad9 Mon Sep 17 00:00:00 2001 From: unknown <81806010+marsej@users.noreply.github.com> Date: Sat, 18 Dec 2021 22:17:46 +0200 Subject: [PATCH 12/12] Remove mToggleCommentAlt from SettingsDialog --- IDE/src/ui/SettingsDialog.bf | 1 - 1 file changed, 1 deletion(-) diff --git a/IDE/src/ui/SettingsDialog.bf b/IDE/src/ui/SettingsDialog.bf index 7f602893..ca52440c 100644 --- a/IDE/src/ui/SettingsDialog.bf +++ b/IDE/src/ui/SettingsDialog.bf @@ -126,7 +126,6 @@ namespace IDE.ui AddPropertiesItem(category, "Enable File Recovery", "mEnableFileRecovery"); AddPropertiesItem(category, "Format on Save", "mFormatOnSave"); AddPropertiesItem(category, "Sync with Workspace Panel", "mSyncWithWorkspacePanel"); - AddPropertiesItem(category, "Toggle comment alternate style", "mToggleCommentAlt"); category.Open(true, true); }