Skip to content
This repository was archived by the owner on Sep 11, 2023. It is now read-only.

Commit 6a209d0

Browse files
committed
multiline commenting undoes the whole action on ctrl+z
1 parent f3aeb8b commit 6a209d0

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

UI/Components/EditorElement/EditorElement.xaml.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,9 @@ public void ToggleComment(bool comment)
783783
var lineList = new List<DocumentLine>();
784784
var document = editor.TextArea.Document;
785785

786+
// Start undo transaction so undoing this doesn't result in undoing every single comment manually
787+
document.UndoStack.StartUndoGroup();
788+
786789
// If there's no selection, add to lineList the line the caret is standing on
787790
if (!selectionSegments.Any())
788791
{
@@ -823,18 +826,21 @@ public void ToggleComment(bool comment)
823826
{
824827
if (!comment && lineText[0] == '/' && lineText[1] == '/')
825828
{
826-
editor.Document.Remove(line.Offset + leadingWhiteSpaces, 3);
829+
editor.Document.Remove(line.Offset + leadingWhiteSpaces, 2);
827830
}
828831
else if (comment && lineText[0] != '/' && lineText[1] != '/')
829832
{
830-
editor.Document.Insert(line.Offset + leadingWhiteSpaces, "// ");
833+
editor.Document.Insert(line.Offset + leadingWhiteSpaces, "//");
831834
}
832835
}
833836
else if (comment)
834837
{
835-
editor.Document.Insert(line.Offset + leadingWhiteSpaces, "// ");
838+
editor.Document.Insert(line.Offset + leadingWhiteSpaces, "//");
836839
}
837840
}
841+
842+
// End the undo transaction
843+
document.UndoStack.EndUndoGroup();
838844
}
839845

840846
public void ChangeCase(bool toUpper = true)

0 commit comments

Comments
 (0)