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

Exception is thrown when making a new line #199

Closed
AlphaNecron opened this issue Feb 1, 2022 · 12 comments · Fixed by #200
Closed

Exception is thrown when making a new line #199

AlphaNecron opened this issue Feb 1, 2022 · 12 comments · Fixed by #200
Assignees

Comments

@AlphaNecron
Copy link
Contributor

Kide_Ce7fskTPt1.mp4

This happens only when I add tm.SetGrammar(ropts.GetScopeByLanguageId(ropts.GetLanguageByExtension(".cs").Id));

Is there any solution?

@AlphaNecron
Copy link
Contributor Author

Stacktrace:

System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
   at System.Collections.Generic.List`1.get_Item(Int32 index)
   at TextMateSharp.Model.AbstractLineList.Get(Int32 index) in /_/src/TextMateSharp/Model/AbstractLineList.cs:line 37
   at TextMateSharp.Model.TMModel.TokenizerThread.ThreadWorker() in /_/src/TextMateSharp/Model/TMModel.cs:line 97
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

@danipen
Copy link
Collaborator

danipen commented Feb 1, 2022

@AlphaNecron. I tried the demo application and I cannot reproduce it.

Could you share a minimal sample that reproduces the issue? I'll try to fix. Thanks in advance

@AlphaNecron
Copy link
Contributor Author

Can i send the project to your email?

@danipen
Copy link
Collaborator

danipen commented Feb 1, 2022

Well, just share here how you instantiate the Avalonia Text Editor and how you set up TextMate just to help me to reproduce the issue.

@AlphaNecron
Copy link
Contributor Author

       <avaloniaEdit:TextEditor x:Name="MainEditor" Padding="4"
                                 Background="#181818"
                                 HorizontalScrollBarVisibility="Auto"
                                 VerticalScrollBarVisibility="Auto"
                                 FontFamily="avares://Kide/Assets/Fonts#JetBrains Mono"
                                 FontWeight="Normal"
                                 FontSize="13"
                                 Encoding="{Binding EditorEncoding, Mode=TwoWay}"
                                 WordWrap="False" ShowLineNumbers="True">
            <avaloniaEdit:TextEditor.Options>
                <avaloniaEdit:TextEditorOptions EnableHyperlinks="True" ConvertTabsToSpaces="True" ShowSpaces="True" EnableRectangularSelection="True" HighlightCurrentLine="True"/>
            </avaloniaEdit:TextEditor.Options>
            <avaloniaEdit:TextEditor.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="Cut">
                        <MenuItem.Icon>
                            <PathIcon Width="12" Height="12" Data="{StaticResource CutGeometry}"/>
                        </MenuItem.Icon>
                    </MenuItem>
                </ContextMenu>
            </avaloniaEdit:TextEditor.ContextMenu>
            <Interaction.Behaviors>
                <behaviors:DocumentTextBindingBehavior Text="{Binding Code, Mode=TwoWay}" />
            </Interaction.Behaviors>
        </avaloniaEdit:TextEditor>
            var ropts = new RegistryOptions(ThemeName.DarkPlus);
            var editor = this.FindControl<TextEditor>("MainEditor");
            editor.TextArea.Caret.PositionChanged += delegate
            {
                ViewModel!.CaretPos = editor.TextArea.Caret.Position.Location;
            };
            editor.TextArea.SelectionBrush = new SolidColorBrush
            {
                Color = Color.FromRgb(38, 78, 119),
                Opacity = 0.4
            };
            editor.TextArea.SelectionCornerRadius = 2;
            editor.TextArea.SelectionForeground = new SolidColorBrush
            {
                Color = Color.FromRgb(248, 250, 251)
            };
            editor.TextArea.IndentationStrategy = new CSharpIndentationStrategy();
            var tm = editor.InstallTextMate(ropts);
            tm.SetGrammar(ropts.GetScopeByLanguageId(ropts.GetLanguageByExtension(".pas").Id));
            tm.SetTheme(ropts.LoadTheme(ThemeName.DarkPlus));

@danipen
Copy link
Collaborator

danipen commented Feb 1, 2022

I'm sorry I'm unable to reproduce the issue. Can you reproduce the issue in the "Demo" application?

@danipen
Copy link
Collaborator

danipen commented Feb 1, 2022

I cannot:

pascal.mp4

@AlphaNecron
Copy link
Contributor Author

https://github.com/AlphaNecron/Kide Here's the repo, you can try and see.

@danipen
Copy link
Collaborator

danipen commented Feb 1, 2022

Reproduced using your sample. I'll provide a fix for it.

Note that re-setting the document text here makes editing incredible slow (and that unveiled a sync issue in TextMateSharp).

@AlphaNecron
Copy link
Contributor Author

Reproduced using your sample. I'll provide a fix for it.

Note that re-setting the document text here makes editing incredible slow (and that unveiled a sync issue in TextMateSharp).

It's a part of the MVVM example of AvaloniaEdit tho.

@AlphaNecron
Copy link
Contributor Author

Note that re-setting the document text here makes editing incredible slow (and that unveiled a sync issue in TextMateSharp).

Is there another way to do this?

@danipen
Copy link
Collaborator

danipen commented Feb 1, 2022

Sorry I'm not familiar with the MVVM sample of avalonia edit. @Takoooooo can you help with this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants