@@ -7,18 +7,18 @@ import { getPosFromMouse } from './mouse';
77import { Selection } from "./selection" ;
88import { Completion , CompletionRequest , DefinitionRequest , DefinitionResponse } from "./lsp" ;
99import {
10- Action , ActionContext , ActionResult ,
10+ Action , ActionContext , ActionResult ,
1111 executeAction , handlePasteText ,
1212} from './actions' ;
13- import {
13+ import {
1414 generateCssClasses , addCssToDocument ,
15- findPrevWord , findNextWord ,
15+ findPrevWord , findNextWord ,
1616 getCompletionRange , scoreMatches
1717} from './utils' ;
1818
1919import './styles.css' ;
2020import { Search } from "./search" ;
21- import { computeGitChangesDetailed , ChangeType , DiffInfo } from "./diff" ;
21+ import { computeGitChangesDetailed as computeGitChanges , ChangeType , DiffInfo } from "./diff" ;
2222
2323export interface EditorSettings {
2424 lineHeight : number ;
@@ -71,15 +71,15 @@ export class AnycodeEditor {
7171
7272 private diffEnabled : boolean = true ;
7373 private originalCode ?: string ;
74- private diffResult ?: Map < number , DiffInfo > ;
74+ private diffs ?: Map < number , DiffInfo > ;
7575
7676 constructor (
77- initialText = '' ,
78- filename : string = 'test.txt' ,
79- language : string = 'javascript' ,
77+ initialText = '' ,
78+ filename : string = 'test.txt' ,
79+ language : string = 'javascript' ,
8080 options : any = { }
8181 ) {
82- this . code = new Code ( initialText , filename , language ) ;
82+ this . code = new Code ( initialText , filename , language ) ;
8383 // Set initial cursor position
8484 if ( options . line !== undefined && options . column !== undefined ) {
8585 this . offset = this . code . getOffset ( options . line , options . column ) ;
@@ -93,7 +93,7 @@ export class AnycodeEditor {
9393 if ( this . diffEnabled ) {
9494 this . originalCode = initialText ;
9595 const currentText = this . code . getContent ( ) ;
96- this . diffResult = computeGitChangesDetailed ( this . originalCode , currentText ) ;
96+ this . diffs = computeGitChanges ( this . originalCode , currentText ) ;
9797 }
9898
9999 const theme = options . theme || vesper ;
@@ -137,7 +137,7 @@ export class AnycodeEditor {
137137 }
138138 }
139139
140- public setOnChange ( func : ( t : Change ) => void ) {
140+ public setOnChange ( func : ( t : Change ) => void ) {
141141 this . code . setOnChange ( func ) ;
142142 }
143143
@@ -148,9 +148,9 @@ export class AnycodeEditor {
148148 public setText ( newText : string ) {
149149 this . code . setContent ( newText ) ;
150150 if ( this . diffEnabled && this . originalCode !== undefined ) {
151- this . diffResult = computeGitChangesDetailed ( this . originalCode , newText ) ;
151+ this . diffs = computeGitChanges ( this . originalCode , newText ) ;
152152 } else {
153- this . diffResult = undefined ;
153+ this . diffs = undefined ;
154154 }
155155 }
156156
@@ -208,7 +208,7 @@ export class AnycodeEditor {
208208 }
209209 this . renderer . renderErrors ( this . errorLines ) ;
210210 }
211-
211+
212212 public setCompletions ( completions : Completion [ ] ) {
213213 this . completions = completions ;
214214 }
@@ -229,7 +229,7 @@ export class AnycodeEditor {
229229 this . onCursorChangeCallback = callback ;
230230 }
231231
232- private setupEventListeners ( ) {
232+ private setupEventListeners ( ) {
233233 this . handleScroll = this . handleScroll . bind ( this ) ;
234234 this . container . addEventListener ( "scroll" , this . handleScroll ) ;
235235
@@ -304,7 +304,7 @@ export class AnycodeEditor {
304304 lineHeight : this . settings . lineHeight ,
305305 buffer : this . settings . buffer ,
306306 } ,
307- diffResult : this . diffResult ,
307+ diffResult : this . diffs ,
308308 } ;
309309 }
310310
@@ -549,8 +549,8 @@ export class AnycodeEditor {
549549 }
550550
551551 private selectWord ( row : number , col : number ) {
552- const line = this . code . line ( row ) ;
553-
552+ const line = this . code . line ( row ) ;
553+
554554 const startCol = findPrevWord ( line , col ) ;
555555 const endCol = findNextWord ( line , col ) ;
556556
@@ -625,7 +625,7 @@ export class AnycodeEditor {
625625 const result = await executeAction ( action , ctx ) ;
626626 this . applyEditResult ( result ) ;
627627
628- if ( this . isCompletionOpen ) {
628+ if ( this . isCompletionOpen ) {
629629 await this . showCompletion ( ) ;
630630 }
631631
@@ -641,10 +641,10 @@ export class AnycodeEditor {
641641
642642 // Shortcuts
643643 if ( metaKey ) {
644- if ( shiftKey && key . toLowerCase ( ) === 'z' )
644+ if ( shiftKey && key . toLowerCase ( ) === 'z' )
645645 return Action . REDO ;
646- if ( key . toLowerCase ( ) === '/' )
647- return Action . COMMENT ;
646+ if ( key . toLowerCase ( ) === '/' )
647+ return Action . COMMENT ;
648648
649649 switch ( key . toLowerCase ( ) ) {
650650 case 'z' : return Action . UNDO ;
@@ -702,19 +702,15 @@ export class AnycodeEditor {
702702 const selectionChanged = this . selection !== result . ctx . selection ;
703703
704704 if ( ! textChanged && ! offsetChanged && ! selectionChanged ) return ;
705-
705+
706706 if ( textChanged ) {
707707 this . code = result . ctx . code ;
708708 // calculate diff when text changes
709709 if ( this . diffEnabled && this . originalCode !== undefined ) {
710710 const currentText = this . code . getContent ( ) ;
711- this . diffResult = computeGitChangesDetailed ( this . originalCode , currentText ) ;
712- console . log ( 'diffResult' , this . diffResult ) ;
713- // Update renderer with fresh diffResult immediately
714- this . renderer . updateDiffResult ( this . diffResult ) ;
711+ this . diffs = computeGitChanges ( this . originalCode , currentText ) ;
715712 } else {
716- this . diffResult = undefined ;
717- this . renderer . updateDiffResult ( undefined ) ;
713+ this . diffs = undefined ;
718714 }
719715 }
720716 if ( offsetChanged ) this . offset = result . ctx . offset ;
@@ -1034,7 +1030,7 @@ export class AnycodeEditor {
10341030 this . search . setNeedsFocus ( false ) ;
10351031 return ;
10361032 }
1037-
1033+
10381034 // Perform search
10391035 const matches = this . getEditorState ( ) . code . search ( pattern ) ;
10401036 this . search . clear ( ) ;
@@ -1074,9 +1070,9 @@ export class AnycodeEditor {
10741070
10751071 if ( this . diffEnabled && this . originalCode !== undefined ) {
10761072 const currentText = this . code . getContent ( ) ;
1077- this . diffResult = computeGitChangesDetailed ( this . originalCode , currentText ) ;
1073+ this . diffs = computeGitChanges ( this . originalCode , currentText ) ;
10781074 } else {
1079- this . diffResult = undefined ;
1075+ this . diffs = undefined ;
10801076 }
10811077
10821078 this . renderer . renderChanges ( this . getEditorState ( ) , this . search ) ;
@@ -1093,24 +1089,27 @@ export class AnycodeEditor {
10931089
10941090 if ( enabled && this . originalCode !== undefined ) {
10951091 const currentText = this . code . getContent ( ) ;
1096- this . diffResult = computeGitChangesDetailed ( this . originalCode , currentText ) ;
1097- this . renderer . updateDiffResult ( this . diffResult ) ;
1092+ this . diffs = computeGitChanges ( this . originalCode , currentText ) ;
10981093 }
10991094
11001095 if ( ! enabled ) {
11011096 this . renderer . clearAllDiffs ( ) ;
1097+ } else {
1098+ this . renderer . render ( this . getEditorState ( ) , this . search ) ;
1099+ this . verifyDiffRendering ( ) ;
11021100 }
1103-
1104- this . renderer . renderChanges ( this . getEditorState ( ) , this . search ) ;
1105- this . verifyDiffRendering ( ) ;
11061101 }
11071102
11081103 private verifyDiffRendering ( ) : void {
1109- if ( ! this . diffEnabled || ! this . diffResult || this . diffResult . size === 0 ) {
1104+ if ( ! this . diffEnabled || this . diffs === undefined ) {
11101105 return ;
11111106 }
11121107
1113- this . renderer . verifyDiffRendering ( this . diffResult ) ;
1108+ if ( this . diffs . size == 0 ) {
1109+ this . renderer . clearAllDiffs ( ) ;
1110+ }
1111+
1112+ this . renderer . verifyDiffRendering ( this . diffs ) ;
11141113 }
11151114
11161115}
0 commit comments