SelectedView.Selection.SelectRange internal exception

SyntaxEditor for Windows Forms Forum

Posted 14 years ago by Maurizio Margiotta - Lead Programmer, Evolution City Group S.a.s.
Avatar
Hi,
I have syntaxeditor 3.0.183.0 and it raises this exception in my application.
I have found the cause of this so I write you.
If I execute this code
mSyntaxEditorHTML.SelectedView.Selection.SelectRange(0, 1);
while there is no text in the SyntaxEditor, it raise an exception, but only after it gains focus.

In the specific this is the behaviour:
I open a form with an empty SyntaxEditor. Then I click outside so that the SyntaxEditor loses focus.
I execute the "bad" code.
Then if I move the mouse over the SyntaxEditor area, the mouse cursor is the standard arrow, while it should be the IBeam (it is like if all the area is filled with a selected text). I click on it and the caret appeare on the top left. If I try to write a single letter it raises this exception.
But, if before to write a single letter I click again, the cursor changes to IBeam (like when you click on a selection and it disappears), and if I write it works fine.

I think that it could be better to manage this situation differently, raising an exeption when I select text out of limit, or, better, don't tell nothing and don't raise any exception, but select only the text to the end of document (if present) or select nothing.

System.ArgumentException: The offset '0' added to the length '1' must be less than or equal to the count of characters in the document.
at ActiproSoftware.SyntaxEditor.Document._1(Int32 , Int32 )
at ActiproSoftware.SyntaxEditor.Document.GetSubstring(Int32 offset, Int32 length)
at ActiproSoftware.SyntaxEditor.Document._1(DocumentModificationType , Int32 , Int32 , String , Boolean )
at ActiproSoftware.SyntaxEditor.Document.UndoableInsert(DocumentModificationType type, Int32 offset, Int32 length, String text, Boolean retainSelection)
at ActiproSoftware.SyntaxEditor.Document.UndoableInsert(DocumentModificationType type, Int32 offset, Int32 length, String text)
at ActiproSoftware.SyntaxEditor.EditorView._1(DocumentModificationType , String )
at ActiproSoftware.SyntaxEditor.EditorView._1(String )
at ActiproSoftware.SyntaxEditor.EditorView.InsertText(String text)
at ActiproSoftware.SyntaxEditor.Commands.TypingCommand.Execute(EditCommandContext context)
at ActiproSoftware.SyntaxEditor.MacroRecording._1(EditCommand , EditCommandContext )
at ActiproSoftware.SyntaxEditor.EditorView._1(EditCommand , Boolean )
at ActiproSoftware.SyntaxEditor.SyntaxEditor._1(EditorView , Keys , Char , Boolean )
at ActiproSoftware.SyntaxEditor.SyntaxEditor.OnKeyPress(KeyPressEventArgs e)
at System.Windows.Forms.Control.ProcessKeyEventArgs(Message& m)
at System.Windows.Forms.Control.ProcessKeyMessage(Message& m)
at System.Windows.Forms.Control.WmKeyChar(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at ActiproSoftware.SyntaxEditor.SyntaxEditor.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Comments (1)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Yes I looked at the code and currently, the selection setting methods don't do a bounds check on what you pass them. Therefore no exception will fire immediately if you pass a bad value. Perhaps was can add bounds checking to it in the future but for now just make sure your parameters don't exceed the Document.Length.


Actipro Software Support

The latest build of this product (v2020.1 build 0400) was released 24 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.