Skip to content

Commit

Permalink
Merge pull request #100 from cfognom/master
Browse files Browse the repository at this point in the history
Opens up Duplicate commands to all editors.
Fixes rare bug with duplicate on second last line.
  • Loading branch information
justcla authored Apr 29, 2023
2 parents 02779ad + 3f2fc7d commit b360b74
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
7 changes: 4 additions & 3 deletions HotCommands/Commands/DuplicateSelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,14 @@ public static int HandleCommand(IWpfTextView textView, IClassifier classifier,
{
SnapshotSpan selectionSpan = selection.Extent.SnapshotSpan;
bool isDuplicateLinesForThisSelection = isDuplicateLines || selectionSpan.Length == 0; // When selection length is zero we treat it as duplicate lines command (or should we not?).

SnapshotSpan duplicationSpan;
bool isMissingNewLine;
bool isMissingNewLine; // Should only be true when duplicating the last line in the document.
if (isDuplicateLinesForThisSelection)
{
duplicationSpan = GetContainingLines(selectionSpan);
isMissingNewLine = duplicationSpan.End == edit.Snapshot.Length;
isMissingNewLine = duplicationSpan.End == edit.Snapshot.Length
&& edit.Snapshot.GetLineFromLineNumber(edit.Snapshot.LineCount - 1).Length > 0;
}
else
{
Expand Down
28 changes: 23 additions & 5 deletions HotCommands/HotCommandsCommandFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,39 @@ public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, Int
// Command handling registration
if (pguidCmdGroup == Constants.HotCommandsGuid && cCmds == 1)
{
const uint supportedAndEnabledStatus = (uint)(OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED);

var contentType = textView.TextBuffer.ContentType;

uint commandStatus = default;
switch (prgCmds[0].cmdID)
{
case Constants.ToggleCommentCmdId:
case Constants.ExpandSelectionCmdId:
case Constants.FormatCodeCmdId:
// 'Any' content commands
case Constants.DuplicateLinesUpCmdId:
case Constants.DuplicateLinesDownCmdId:
case Constants.DuplicateSelectionCmdId:
case Constants.DuplicateSelectionReverseCmdId:
commandStatus = supportedAndEnabledStatus;
break;

// 'Code' content commands
case Constants.ToggleCommentCmdId:
commandStatus = contentType.IsOfType("Code") ? supportedAndEnabledStatus : default;
break;

// 'CSharp' content commands
case Constants.ExpandSelectionCmdId:
case Constants.FormatCodeCmdId:
case Constants.MoveMemberUpCmdId:
case Constants.MoveMemberDownCmdId:
case Constants.GoToPreviousMemberCmdId:
case Constants.GoToNextMemberCmdId:
prgCmds[0].cmdf |= (uint)OLECMDF.OLECMDF_ENABLED;
return VSConstants.S_OK;
commandStatus = contentType.IsOfType("CSharp") ? supportedAndEnabledStatus : default;
break;
}

prgCmds[0].cmdf |= commandStatus;
return VSConstants.S_OK;
}

if (Next != null)
Expand Down
2 changes: 1 addition & 1 deletion HotCommands/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="e8175b11-0e09-42b5-9c3c-ba7bfb53a311" Version="4.3.2" Language="en-US" Publisher="Justin Clareburt" />
<Identity Id="e8175b11-0e09-42b5-9c3c-ba7bfb53a311" Version="4.3.3" Language="en-US" Publisher="Justin Clareburt" />
<DisplayName>Hot Commands</DisplayName>
<Description xml:space="preserve">A collection of commands and shortcuts for enhanced productivity in Visual Studio IDE. VS2022+</Description>
<MoreInfo>https://marketplace.visualstudio.com/items?itemName=JustinClareburtMSFT.HotCommandsforVisualStudio</MoreInfo>
Expand Down

0 comments on commit b360b74

Please sign in to comment.