Skip to content

Commit 44e77ae

Browse files
authored
Merge pull request #4510 from retailcoder/scp
SCP Fixes
2 parents e2d70a3 + ee52fb7 commit 44e77ae

29 files changed

+532
-402
lines changed

Rubberduck.Core/AutoComplete/Service/SelfClosingPair.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,6 @@ namespace Rubberduck.AutoComplete.Service
55
{
66
public class SelfClosingPair : IEquatable<SelfClosingPair>
77
{
8-
[Flags]
9-
public enum MatchType
10-
{
11-
NoMatch = 0,
12-
OpeningCharacterMatch = 1,
13-
ClosingCharacterMatch = 2,
14-
}
15-
168
public SelfClosingPair(char opening, char closing)
179
{
1810
OpeningChar = opening;

Rubberduck.Core/AutoComplete/Service/SelfClosingPairHandler.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ namespace Rubberduck.AutoComplete.Service
1010
{
1111
public class SelfClosingPairHandler : AutoCompleteHandlerBase
1212
{
13+
private const int MaximumLines = 25;
14+
1315
private readonly IReadOnlyList<SelfClosingPair> _selfClosingPairs;
1416
private readonly IDictionary<char, SelfClosingPair> _scpInputLookup;
1517
private readonly SelfClosingPairCompletionService _scpService;
@@ -41,6 +43,12 @@ public override bool Handle(AutoCompleteEventArgs e, AutoCompleteSettings settin
4143
}
4244

4345
var original = CodePaneHandler.GetCurrentLogicalLine(e.Module);
46+
if (original == null || original.Lines.Length == MaximumLines)
47+
{
48+
// selection spans more than a single logical line, or
49+
// logical line somehow spans more than the maximum number of physical lines in a logical line of code (25).
50+
return false;
51+
}
4452

4553
if (pair != null)
4654
{
@@ -74,6 +82,13 @@ public override bool Handle(AutoCompleteEventArgs e, AutoCompleteSettings settin
7482

7583
private bool HandleInternal(AutoCompleteEventArgs e, CodeString original, SelfClosingPair pair, out CodeString result)
7684
{
85+
if (!original.CaretPosition.IsSingleCharacter)
86+
{
87+
// todo: WrapSelection?
88+
result = null;
89+
return false;
90+
}
91+
7792
var isPresent = original.CaretLine.EndsWith($"{pair.OpeningChar}{pair.ClosingChar}");
7893

7994
if (!_scpService.Execute(pair, original, e.Character, out result))

Rubberduck.Core/AutoComplete/Service/SmartConcatenationHandler.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ public override bool Handle(AutoCompleteEventArgs e, AutoCompleteSettings settin
2525
}
2626

2727
var currentContent = CodePaneHandler.GetCurrentLogicalLine(e.Module);
28-
if (!currentContent.IsInsideStringLiteral)
28+
if ((!currentContent?.IsInsideStringLiteral ?? true)
29+
|| currentContent.Lines.Length >= settings.SmartConcat.ConcatMaxLines)
2930
{
31+
// selection spans more than a single logical line, or spans too many lines to be legal;
32+
// too many line continuations throws COMException if we attempt to modify.
3033
return false;
3134
}
3235

Rubberduck.Core/Properties/Settings.settings

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -269,26 +269,13 @@
269269
</Setting>
270270
<Setting Name="AutoCompleteSettings" Type="Rubberduck.Settings.AutoCompleteSettings" Scope="Application">
271271
<Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
272-
&lt;AutoCompleteSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" IsEnabled="false" CompleteBlockOnTab="true" CompleteBlockOnEnter="true" EnableSmartConcat="true"&gt;
273-
&lt;AutoCompletes&gt;
274-
&lt;AutoComplete Key="AutoCompleteClosingBrace" IsEnabled="true" /&gt;
275-
&lt;AutoComplete Key="AutoCompleteClosingBracket" IsEnabled="true" /&gt;
276-
&lt;AutoComplete Key="AutoCompleteClosingParenthese" IsEnabled="true" /&gt;
277-
&lt;AutoComplete Key="AutoCompleteClosingString" IsEnabled="true" /&gt;
278-
&lt;AutoComplete Key="AutoCompleteDoBlock" IsEnabled="true" /&gt;
279-
&lt;AutoComplete Key="AutoCompleteEnumBlock" IsEnabled="true" /&gt;
280-
&lt;AutoComplete Key="AutoCompleteForBlock" IsEnabled="true" /&gt;
281-
&lt;AutoComplete Key="AutoCompleteFunctionBlock" IsEnabled="true" /&gt;
282-
&lt;AutoComplete Key="AutoCompleteIfBlock" IsEnabled="true" /&gt;
283-
&lt;AutoComplete Key="AutoCompleteOnErrorResumeNextBlock" IsEnabled="true" /&gt;
284-
&lt;AutoComplete Key="AutoCompletePrecompilerIfBlock" IsEnabled="true" /&gt;
285-
&lt;AutoComplete Key="AutoCompletePropertyBlock" IsEnabled="true" /&gt;
286-
&lt;AutoComplete Key="AutoCompleteSelectBlock" IsEnabled="true" /&gt;
287-
&lt;AutoComplete Key="AutoCompleteSubBlock" IsEnabled="true" /&gt;
288-
&lt;AutoComplete Key="AutoCompleteTypeBlock" IsEnabled="true" /&gt;
289-
&lt;AutoComplete Key="AutoCompleteWhileBlock" IsEnabled="true" /&gt;
290-
&lt;AutoComplete Key="AutoCompleteWithBlock" IsEnabled="true" /&gt;
291-
&lt;/AutoCompletes&gt;
272+
&lt;AutoCompleteSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" IsEnabled="false"&gt;
273+
&lt;SmartConcat&gt;
274+
&lt;IsEnabled&gt;false&lt;/IsEnabled&gt;
275+
&lt;ConcatVbNewLineModifier&gt;None&lt;/ConcatVbNewLineModifier&gt;
276+
&lt;/SmartConcat&gt;
277+
&lt;SelfClosingPairs IsEnabled="false" /&gt;
278+
&lt;BlockCompletion IsEnabled="false" CompleteOnEnter="false" CompleteOnTab="false" /&gt;
292279
&lt;/AutoCompleteSettings&gt;</Value>
293280
</Setting>
294281
</Settings>

Rubberduck.Core/Settings/AutoCompleteSettings.cs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
using Rubberduck.AutoComplete;
2-
using System;
3-
using System.Collections.Generic;
1+
using System;
42
using System.Configuration;
5-
using System.Linq;
63
using System.Xml.Serialization;
74

85
namespace Rubberduck.Settings
@@ -27,6 +24,15 @@ public interface IAutoCompleteSettings
2724
[XmlType(AnonymousType = true)]
2825
public class AutoCompleteSettings : IAutoCompleteSettings, IEquatable<AutoCompleteSettings>
2926
{
27+
/// <summary>
28+
/// Less than that would be useless (wouldn't concat).
29+
/// </summary>
30+
public static readonly int ConcatMaxLinesMinValue = 2;
31+
/// <summary>
32+
/// /More than that would be illegal (wouldn't compile).
33+
/// </summary>
34+
public static readonly int ConcatMaxLinesMaxValue = 25;
35+
3036
public static AutoCompleteSettings AllEnabled =>
3137
new AutoCompleteSettings
3238
{
@@ -57,13 +63,35 @@ public AutoCompleteSettings()
5763

5864
public class SmartConcatSettings : IEquatable<SmartConcatSettings>
5965
{
66+
private int _concatMaxLines;
67+
68+
[XmlAttribute]
6069
public bool IsEnabled { get; set; }
6170
public ModifierKeySetting ConcatVbNewLineModifier { get; set; }
6271

72+
public int ConcatMaxLines
73+
{
74+
get => _concatMaxLines;
75+
set
76+
{
77+
if (value > ConcatMaxLinesMaxValue)
78+
{
79+
value = ConcatMaxLinesMaxValue;
80+
}
81+
else if (value < ConcatMaxLinesMinValue)
82+
{
83+
value = ConcatMaxLinesMinValue;
84+
}
85+
86+
_concatMaxLines = value;
87+
}
88+
}
89+
6390
public bool Equals(SmartConcatSettings other)
6491
=> other != null &&
6592
other.IsEnabled == IsEnabled &&
66-
other.ConcatVbNewLineModifier == ConcatVbNewLineModifier;
93+
other.ConcatVbNewLineModifier == ConcatVbNewLineModifier &&
94+
other.ConcatMaxLines == ConcatMaxLines;
6795
}
6896

6997
public class SelfClosingPairSettings : IEquatable<SelfClosingPairSettings>

Rubberduck.Core/UI/Settings/AutoCompleteSettings.xaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@
111111
IsChecked="{Binding ConcatVbNewLine}"
112112
Content="{Resx ResxName=Rubberduck.Resources.Settings.AutoCompletesPage, Key=ConcatVbNewLine}" />
113113

114+
<Label Margin="15,0,15,0" Content="{Resx ResxName=Rubberduck.Resources.Settings.AutoCompletesPage, Key=ConcatMaxLines}" />
115+
<controls:NumberPicker Margin="15,0,15,0"
116+
NumValue="{Binding ConcatMaxLines}"
117+
MinNumber="{Binding ConcatMaxLinesMinValue}"
118+
MaxNumber="{Binding ConcatMaxLinesMaxValue}"/>
119+
114120
<Label Margin="10"
115121
Content="{Resx ResxName=Rubberduck.Resources.Settings.AutoCompletesPage, Key=BlockCompletion}"
116122
FontWeight="Bold" />

Rubberduck.Core/UI/Settings/AutoCompleteSettingsViewModel.cs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using NLog;
22
using Rubberduck.Resources;
3+
using Rubberduck.Resources.Settings;
34
using Rubberduck.Settings;
45
using Rubberduck.SettingsProvider;
56
using Rubberduck.UI.Command;
@@ -29,7 +30,7 @@ public void UpdateConfig(Configuration config)
2930
config.UserSettings.AutoCompleteSettings.SmartConcat.IsEnabled = EnableSmartConcat;
3031
config.UserSettings.AutoCompleteSettings.SmartConcat.ConcatVbNewLineModifier =
3132
ConcatVbNewLine ? ModifierKeySetting.CtrlKey : ModifierKeySetting.None;
32-
33+
config.UserSettings.AutoCompleteSettings.SmartConcat.ConcatMaxLines = ConcatMaxLines;
3334
config.UserSettings.AutoCompleteSettings.BlockCompletion.IsEnabled = EnableBlockCompletion;
3435
config.UserSettings.AutoCompleteSettings.BlockCompletion.CompleteOnTab = CompleteBlockOnTab;
3536
config.UserSettings.AutoCompleteSettings.BlockCompletion.CompleteOnEnter = CompleteBlockOnEnter;
@@ -43,6 +44,7 @@ private void TransferSettingsToView(Rubberduck.Settings.AutoCompleteSettings toL
4344

4445
EnableSmartConcat = toLoad.SmartConcat.IsEnabled;
4546
ConcatVbNewLine = toLoad.SmartConcat.ConcatVbNewLineModifier == ModifierKeySetting.CtrlKey;
47+
ConcatMaxLines = toLoad.SmartConcat.ConcatMaxLines;
4648

4749
EnableBlockCompletion = toLoad.BlockCompletion.IsEnabled;
4850
CompleteBlockOnTab = toLoad.BlockCompletion.CompleteOnTab;
@@ -108,6 +110,23 @@ public bool ConcatVbNewLine
108110
}
109111
}
110112

113+
private int _concatMaxLines;
114+
public int ConcatMaxLines
115+
{
116+
get { return _concatMaxLines; }
117+
set
118+
{
119+
if (_concatMaxLines != value)
120+
{
121+
_concatMaxLines = value;
122+
OnPropertyChanged();
123+
}
124+
}
125+
}
126+
127+
public int ConcatMaxLinesMinValue => Rubberduck.Settings.AutoCompleteSettings.ConcatMaxLinesMinValue;
128+
public int ConcatMaxLinesMaxValue => Rubberduck.Settings.AutoCompleteSettings.ConcatMaxLinesMaxValue;
129+
111130
private bool _enableBlockCompletion;
112131

113132
public bool EnableBlockCompletion
@@ -165,8 +184,8 @@ private void ImportSettings()
165184
{
166185
using (var dialog = new OpenFileDialog
167186
{
168-
Filter = RubberduckUI.DialogMask_XmlFilesOnly,
169-
Title = RubberduckUI.DialogCaption_LoadInspectionSettings
187+
Filter = SettingsUI.DialogMask_XmlFilesOnly,
188+
Title = SettingsUI.DialogCaption_LoadInspectionSettings
170189
})
171190
{
172191
dialog.ShowDialog();
@@ -181,8 +200,8 @@ private void ExportSettings()
181200
{
182201
using (var dialog = new SaveFileDialog
183202
{
184-
Filter = RubberduckUI.DialogMask_XmlFilesOnly,
185-
Title = RubberduckUI.DialogCaption_SaveInspectionSettings
203+
Filter = SettingsUI.DialogMask_XmlFilesOnly,
204+
Title = SettingsUI.DialogCaption_SaveAutocompletionSettings
186205
})
187206
{
188207
dialog.ShowDialog();

Rubberduck.Core/UI/Settings/GeneralSettingsViewModel.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Rubberduck.UI.Command;
1111
using Rubberduck.VBEditor.VbeRuntime.Settings;
1212
using Rubberduck.Resources;
13+
using Rubberduck.Resources.Settings;
1314

1415
namespace Rubberduck.UI.Settings
1516
{
@@ -275,8 +276,8 @@ private void ImportSettings()
275276
{
276277
using (var dialog = new OpenFileDialog
277278
{
278-
Filter = RubberduckUI.DialogMask_XmlFilesOnly,
279-
Title = RubberduckUI.DialogCaption_LoadGeneralSettings
279+
Filter = SettingsUI.DialogMask_XmlFilesOnly,
280+
Title = SettingsUI.DialogCaption_LoadGeneralSettings
280281
})
281282
{
282283
dialog.ShowDialog();
@@ -295,8 +296,8 @@ private void ExportSettings()
295296
{
296297
using (var dialog = new SaveFileDialog
297298
{
298-
Filter = RubberduckUI.DialogMask_XmlFilesOnly,
299-
Title = RubberduckUI.DialogCaption_SaveGeneralSettings
299+
Filter = SettingsUI.DialogMask_XmlFilesOnly,
300+
Title = SettingsUI.DialogCaption_SaveGeneralSettings
300301
})
301302
{
302303
dialog.ShowDialog();

Rubberduck.Core/UI/Settings/IndenterSettingsViewModel.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Rubberduck.SmartIndenter;
77
using Rubberduck.UI.Command;
88
using Rubberduck.Resources;
9+
using Rubberduck.Resources.Settings;
910

1011
namespace Rubberduck.UI.Settings
1112
{
@@ -497,8 +498,8 @@ private void ImportSettings()
497498
{
498499
using (var dialog = new OpenFileDialog
499500
{
500-
Filter = RubberduckUI.DialogMask_XmlFilesOnly,
501-
Title = RubberduckUI.DialogCaption_LoadIndenterSettings
501+
Filter = SettingsUI.DialogMask_XmlFilesOnly,
502+
Title = SettingsUI.DialogCaption_LoadIndenterSettings
502503
})
503504
{
504505
dialog.ShowDialog();
@@ -513,8 +514,8 @@ private void ExportSettings()
513514
{
514515
using (var dialog = new SaveFileDialog
515516
{
516-
Filter = RubberduckUI.DialogMask_XmlFilesOnly,
517-
Title = RubberduckUI.DialogCaption_SaveIndenterSettings
517+
Filter = SettingsUI.DialogMask_XmlFilesOnly,
518+
Title = SettingsUI.DialogCaption_SaveIndenterSettings
518519
})
519520
{
520521
dialog.ShowDialog();

Rubberduck.Core/UI/Settings/InspectionSettingsViewModel.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
using Rubberduck.Resources.Inspections;
1111
using System.Globalization;
1212
using System;
13-
using Rubberduck.Resources;
13+
using Rubberduck.Resources.Settings;
1414

1515
namespace Rubberduck.UI.Settings
1616
{
@@ -195,8 +195,8 @@ private void ImportSettings()
195195
{
196196
using (var dialog = new OpenFileDialog
197197
{
198-
Filter = RubberduckUI.DialogMask_XmlFilesOnly,
199-
Title = RubberduckUI.DialogCaption_LoadInspectionSettings
198+
Filter = SettingsUI.DialogMask_XmlFilesOnly,
199+
Title = SettingsUI.DialogCaption_LoadInspectionSettings
200200
})
201201
{
202202
dialog.ShowDialog();
@@ -211,8 +211,8 @@ private void ExportSettings()
211211
{
212212
using (var dialog = new SaveFileDialog
213213
{
214-
Filter = RubberduckUI.DialogMask_XmlFilesOnly,
215-
Title = RubberduckUI.DialogCaption_SaveInspectionSettings
214+
Filter = SettingsUI.DialogMask_XmlFilesOnly,
215+
Title = SettingsUI.DialogCaption_SaveInspectionSettings
216216
})
217217
{
218218
dialog.ShowDialog();

0 commit comments

Comments
 (0)