@@ -205,9 +205,13 @@ class VDoc {
205205 if ( this . options . _debug ) {
206206 trace ( 'vdoc#update' , side , editor , viewport ) ;
207207 }
208- const lines = Object . keys ( this . _lines [ side ] ) ;
209- for ( let i = 0 ; i < lines . length ; ++ i ) {
210- const id = lines [ i ] ;
208+ const keys = Object . keys ( this . _lines [ side ] ) ;
209+ // while Mergely diffs unicode diacritic chars (letters+mark),
210+ // CM is by character, so diffs need to be mapped.
211+ const mappedChars = mapLettersToChars ( editor . getValue ( ) ) ;
212+
213+ for ( const key of keys ) {
214+ const { id } = this . _lines [ side ] [ key ] ;
211215 if ( id < viewport . from || id > viewport . to ) {
212216 continue ;
213217 }
@@ -216,7 +220,7 @@ class VDoc {
216220 if ( vline . rendered ) {
217221 continue ;
218222 }
219- vline . update ( editor ) ;
223+ vline . update ( editor , mappedChars ) ;
220224 }
221225 }
222226
@@ -257,7 +261,7 @@ class VLine {
257261 this . markup . push ( [ charFrom , charTo , className ] ) ;
258262 }
259263
260- update ( editor ) {
264+ update ( editor , mappedChars ) {
261265 if ( this . rendered ) {
262266 // FIXME: probably do not need this now
263267 console . log ( 'already rendered' , this . id ) ;
@@ -279,18 +283,17 @@ class VLine {
279283 editor . setGutterMarker ( this . id , name , item ) ;
280284 }
281285 if ( this . markup . length ) {
282- // while Mergely diffs unicode chars (letters+mark), CM is by character,
283- // so diffs need to be mapped.
284- const mapped = mapLettersToChars ( editor . getValue ( ) ) ;
286+ // while Mergely diffs unicode diacritic chars (letters+mark),
287+ // CM is by character, so diffs need to be mapped.
285288 for ( const markup of this . markup ) {
286289 const [ charFrom , charTo , className ] = markup ;
287290 const fromPos = { line : this . id } ;
288291 const toPos = { line : this . id } ;
289292 if ( charFrom >= 0 ) {
290- fromPos . ch = mapped [ charFrom ] ;
293+ fromPos . ch = mappedChars [ charFrom ] ;
291294 }
292295 if ( charTo >= 0 ) {
293- toPos . ch = mapped [ charTo ] ;
296+ toPos . ch = mappedChars [ charTo ] ;
294297 }
295298 this . _clearMarkup . push (
296299 editor . markText ( fromPos , toPos , { className } ) ) ;
0 commit comments