Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tab with spaces when using Python 3 #11010

Merged
merged 1 commit into from
Aug 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Libraries/PythonNodeModelsWpf/ScriptEditorWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ private void OnEngineChanged(object sender, System.Windows.Controls.SelectionCha
{
UpdateScript(editText.Text);
}

editText.Options.ConvertTabsToSpaces = nodeModel.Engine != PythonEngineVersion.IronPython2;
zeusongit marked this conversation as resolved.
Show resolved Hide resolved
}

private void OnScriptEditorWindowClosed(object sender, EventArgs e)
Expand Down
60 changes: 60 additions & 0 deletions test/DynamoCoreWpfTests/PythonNodeCustomizationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Dynamo.Controls;
using Dynamo.Graph.Workspaces;
using Dynamo.Utilities;
Expand Down Expand Up @@ -123,6 +124,16 @@ public void ChangingDropdownEngineSavesCodeBeforeRunning()
DispatcherUtil.DoEvents();
}

private static ICSharpCode.AvalonEdit.TextEditor FindCodeEditor(ScriptEditorWindow view)
{
DispatcherUtil.DoEvents();
var windowGrid = view.Content as Grid;
var codeEditor = windowGrid
.ChildrenOfType<ICSharpCode.AvalonEdit.TextEditor>()
.First();
return codeEditor;
}

private static ComboBox FindEditorDropDown(ScriptEditorWindow view)
{
DispatcherUtil.DoEvents();
Expand Down Expand Up @@ -303,5 +314,54 @@ public void WorkspaceWithMultiplePythonEnginesUpdatesCorrectlyViaContextHandler(
Assert.AreEqual(new List<string> { "2.7.9", "2.7.9" }, pynode2.CachedValue.GetElements().Select(x => x.Data));
DispatcherUtil.DoEvents();
}

[Test]
public void TabWithSpacesMatchesEngine()
{
// Arrange
Open(@"core\python\python.dyn");

var nodeView = NodeViewWithGuid("3bcad14e-d086-4278-9e08-ed2759ef92f3");
var nodeModel = nodeView.ViewModel.NodeModel as PythonNodeBase;
Assert.NotNull(nodeModel);

var scriptWindow = EditPythonCode(nodeView, View);
var codeEditor = FindCodeEditor(scriptWindow);
var engineSelectorComboBox = FindEditorDropDown(scriptWindow);

Assert.AreEqual(PythonEngineVersion.IronPython2, engineSelectorComboBox.SelectedItem);

// Act
codeEditor.Focus();
codeEditor.SelectionStart = 0;
var textArea = Keyboard.FocusedElement;
textArea.RaiseEvent(new KeyEventArgs(
Keyboard.PrimaryDevice,
PresentationSource.FromVisual(codeEditor),
0,
Key.Tab)
{
RoutedEvent = Keyboard.KeyDownEvent
}
);
DispatcherUtil.DoEvents();

engineSelectorComboBox.SelectedItem = PythonEngineVersion.CPython3;

codeEditor.SelectionStart = 0;
textArea.RaiseEvent(new KeyEventArgs(
Keyboard.PrimaryDevice,
PresentationSource.FromVisual(codeEditor),
0,
Key.Tab)
{
RoutedEvent = Keyboard.KeyDownEvent
}
);
DispatcherUtil.DoEvents();

// Assert
StringAssert.StartsWith(" \t", codeEditor.Text);
}
}
}