3535using AvaloniaEdit . Utils ;
3636using static System . Runtime . InteropServices . JavaScript . JSType ;
3737using System . Diagnostics ;
38+ using SixLabors . ImageSharp . Formats . Webp ;
3839
3940namespace ZXBasicStudio . DocumentEditors . ZXTextEditor . Controls
4041{
@@ -99,14 +100,14 @@ public partial class ZXTextEditor : ZXDocumentEditorBase, IObserver<AvaloniaProp
99100 public override string DocumentName => _docName ;
100101 public override string DocumentPath => _docPath ;
101102 public override bool Modified
102- {
103- get
104- {
105- if ( _docPath == ZXConstants . DISASSEMBLY_DOC || _docPath == ZXConstants . ROM_DOC )
106- return false ;
107-
108- return editor ? . IsModified ?? false ;
109- }
103+ {
104+ get
105+ {
106+ if ( _docPath == ZXConstants . DISASSEMBLY_DOC || _docPath == ZXConstants . ROM_DOC )
107+ return false ;
108+
109+ return editor ? . IsModified ?? false ;
110+ }
110111 }
111112 #endregion
112113
@@ -139,15 +140,15 @@ public int? BreakLine
139140 #region Constructors
140141 public ZXTextEditor ( ) : this ( "Untitled" , ZXTextDocument . Id )
141142 {
142-
143+
143144 }
144145 public ZXTextEditor ( string DocumentPath , Guid DocumentTypeId )
145146 {
146147 InitializeComponent ( ) ;
147148
148149 _docTypeId = DocumentTypeId ;
149150 InitializeShortcuts ( ) ;
150-
151+
151152 editor . DataContext = editor ;
152153 editor . FontSize = ZXOptions . Current . EditorFontSize ;
153154 editor . WordWrap = ZXOptions . Current . WordWrap ;
@@ -208,19 +209,25 @@ private void TextArea_TextEntering(object? sender, TextInputEventArgs e)
208209 {
209210
210211 if ( e . Text == null || e . Text . Length == 0 )
212+ {
211213 return ;
214+ }
212215
213216 if ( completionWindow == null && ! string . IsNullOrWhiteSpace ( e . Text ) && ! char . IsNumber ( e . Text [ 0 ] ) )
214217 {
215218 var d = ( IDocument ) editor . Document ;
216219 var completionData = ShouldComplete ( editor . Document , editor . TextArea . Caret . Line , editor . TextArea . Caret . Column - 1 , e . Text [ 0 ] , false ) ;
217220
218221 if ( completionData != null )
222+ {
219223 ShowCompletion ( completionData , false ) ;
224+ }
220225 }
221226 else if ( completionWindow != null && ! char . IsLetterOrDigit ( e . Text [ 0 ] ) )
227+ {
222228 completionWindow . CompletionList . RequestInsertion ( e ) ;
223-
229+ }
230+
224231 }
225232
226233 private void TextArea_KeyDown ( object ? sender , KeyEventArgs e )
@@ -231,7 +238,9 @@ private void TextArea_KeyDown(object? sender, KeyEventArgs e)
231238 var completionData = ShouldComplete ( editor . Document , editor . TextArea . Caret . Line , editor . TextArea . Caret . Column - 1 , null , true ) ;
232239
233240 if ( completionData != null )
241+ {
234242 ShowCompletion ( completionData , true ) ;
243+ }
235244 }
236245 }
237246
@@ -240,10 +249,9 @@ private void ShowCompletion(IEnumerable<ICompletionData> completions, bool reque
240249 if ( completionWindow == null )
241250 {
242251 completionWindow = new CompletionWindow ( editor . TextArea ) ;
243-
244252 ICompletionData ? selectedItem = null ;
245253
246- if ( requested )
254+ // if (requested)
247255 {
248256 var line = editor . Document . GetLineByNumber ( editor . TextArea . Caret . Line ) ;
249257 var text = editor . Document . GetText ( line ) ;
@@ -270,6 +278,7 @@ private void ShowCompletion(IEnumerable<ICompletionData> completions, bool reque
270278 data . AddRange ( completions ) ;
271279 completionWindow . Show ( ) ;
272280 completionWindow . CompletionList . SelectedItem = selectedItem ;
281+
273282 completionWindow . KeyDown += ( s , e ) =>
274283 {
275284 if ( e . Key == Key . F1 && completionWindow . CompletionList . SelectedItem != null )
@@ -512,20 +521,20 @@ public override bool SaveDocument(TextWriter OutputLog)
512521
513522 return true ;
514523 }
515- catch ( Exception ex )
524+ catch ( Exception ex )
516525 {
517526 OutputLog . WriteLine ( $ "Error saving file { _docPath } : { ex . Message } ") ;
518527 return false ;
519528 }
520529 }
521530 public override bool RenameDocument ( string NewName , TextWriter OutputLog )
522531 {
523- try
532+ try
524533 {
525534 UpdateFileName ( _docPath , NewName ) ;
526535 return true ;
527536 }
528- catch ( Exception ex )
537+ catch ( Exception ex )
529538 {
530539 OutputLog . WriteLine ( $ "Error internally updating the document name: { ex . Message } ") ;
531540 return false ;
@@ -602,22 +611,22 @@ public void Expand()
602611 foreach ( var fold in fManager . AllFoldings )
603612 fold . IsFolded = false ;
604613 }
605-
614+
606615 public void FontIncrease ( )
607616 {
608617 editor . FontSize ++ ;
609618 }
610-
619+
611620 public void FontDecrease ( )
612621 {
613622 editor . FontSize -- ;
614623 }
615-
624+
616625 public void CommentSelection ( )
617626 {
618627 if ( editor . IsReadOnly || commentChar == null || editor . TextArea . Selection == null )
619628 return ;
620-
629+
621630 TextDocument document = editor . TextArea . Document ;
622631
623632 if ( editor . TextArea . Selection . Length == 0 )
@@ -629,7 +638,7 @@ public void CommentSelection()
629638 else
630639 {
631640 IEnumerable < SelectionSegment > selectionSegments = editor . TextArea . Selection . Segments ;
632-
641+
633642 foreach ( SelectionSegment segment in selectionSegments )
634643 {
635644 int lineStart = document . GetLineByOffset ( segment . StartOffset ) . LineNumber ;
@@ -741,17 +750,17 @@ private void Document_Changing(object? sender, DocumentChangeEventArgs e)
741750
742751 if ( e . RemovalLength > 0 )
743752 {
744-
753+
745754 int end = start + e . RemovalLength ;
746755 int linesRemoved = 0 ;
747756 int pos = start ;
748- while ( pos < end )
757+ while ( pos < end )
749758 {
750759 var line = editor . Document . GetLineByOffset ( pos ) ;
751760 if ( pos >= line . EndOffset )
752761 firstLine ++ ;
753762
754-
763+
755764 string lineText = editor . Document . GetText ( line . Offset , line . Length ) ;
756765 int removalLength = Math . Min ( line . EndOffset - pos , end - pos ) ;
757766 string leftText = lineText . Remove ( pos - line . Offset , removalLength ) ;
@@ -766,11 +775,11 @@ private void Document_Changing(object? sender, DocumentChangeEventArgs e)
766775 linesRemoved ++ ;
767776 }
768777
769- if ( linesRemoved > 0 )
778+ if ( linesRemoved > 0 )
770779 changed |= MoveBreakpoints ( firstLine , - linesRemoved ) ;
771780 }
772781
773- if ( changed )
782+ if ( changed )
774783 bpMargin ? . InvalidateVisual ( ) ;
775784 }
776785 private void Document_Changed ( object ? sender , DocumentChangeEventArgs e )
@@ -801,7 +810,7 @@ private void Document_Changed(object? sender, DocumentChangeEventArgs e)
801810
802811 var firstText = editor . Document . GetText ( firstLine . Offset , firstLine . Length ) ;
803812
804- if ( ! string . IsNullOrWhiteSpace ( firstText ) )
813+ if ( ! string . IsNullOrWhiteSpace ( firstText ) )
805814 changed = MoveBreakpoints ( firstLine . LineNumber + 1 , addedLines ) ;
806815 else
807816 changed = MoveBreakpoints ( firstLine . LineNumber , addedLines ) ;
@@ -873,12 +882,12 @@ public void UpdateFontSize(bool increase)
873882 #region IObserver implementation for modified document notifications
874883 public void OnCompleted ( )
875884 {
876-
885+
877886 }
878887
879888 public void OnError ( Exception error )
880889 {
881-
890+
882891 }
883892
884893 public void OnNext ( AvaloniaPropertyChangedEventArgs value )
0 commit comments