
Is there a fix or a workaround for this issue?
- Run test app
- Click the "Open" button to load a file
- Enter a number in the "Jump" text box which is higher than the total number of lines in the loaded file.
- Click the "Jump" button.
- Press enter
- Unhandled exception is thrown "ArgumentOutOfRangeException"
To reproduce this issue, please use the following code to create a simple test app:
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication2"
xmlns:syntaxeditor="http://schemas.actiprosoftware.com/winfx/xaml/syntaxeditor"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<syntaxeditor:SyntaxEditor Name="actiproEditor" IsLineNumberMarginVisible="True" IsOutliningMarginVisible="False" IsSelectionMarginVisible="False"
FontFamily="Consolas" FontSize="16" TextOptions.TextFormattingMode="Display" IsDefaultContextMenuEnabled="False"
Background="White" LineNumberMarginForeground="Gray" IsCurrentLineHighlightingEnabled="True">
</syntaxeditor:SyntaxEditor>
<StackPanel Grid.Row="1" Orientation="Horizontal">
<Button Content="Open" Margin="0,0,5,0" Click="Open_OnClick"/>
<Button Content="Jump" Margin="5,0" Click="Jump_OnClick"/>
<TextBox Name="txtJump" Text="100" Margin="5,0"/>
</StackPanel>
</Grid>
</Window>
using System.Windows;
namespace WpfApplication2
{
using Microsoft.Win32;
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow
{
public MainWindow()
{
this.InitializeComponent();
}
private void Open_OnClick(object sender, RoutedEventArgs e)
{
var dialog = new OpenFileDialog();
var result = dialog.ShowDialog();
if (result.Value)
{
this.actiproEditor.Document.LoadFile(dialog.FileName);
}
}
private void Jump_OnClick(object sender, RoutedEventArgs e)
{
var line = (int)double.Parse(this.txtJump.Text);
line = line - 1; // in Actipro Synax Editor the first line is line #0
if (line < 0)
{
line = 0;
}
else if (line >= this.actiproEditor.ActiveView.CurrentSnapshot.Lines.Count)
{
line = this.actiproEditor.ActiveView.CurrentSnapshot.Lines.Count;
}
var position = new ActiproSoftware.Text.TextPosition(line, 0);
this.actiproEditor.ActiveView.Scroller.ScrollIntoView(position, false);
this.actiproEditor.Caret.Position = position;
this.actiproEditor.Focus();
}
}
}