From 592725282c95dc70ab3f6f17a28703ae8738ea47 Mon Sep 17 00:00:00 2001 From: Jamie Peabody Date: Wed, 19 Jun 2024 19:15:54 +0100 Subject: [PATCH] fix: Fixed a regression rendering inline markup for numbers, punctuation, and symbols --- src/diff.js | 6 ++++-- src/vdoc.js | 4 +++- test/markup.spec.js | 27 ++++++++++++++++++++++++++- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/diff.js b/src/diff.js index 4211b3c..1b9231c 100644 --- a/src/diff.js +++ b/src/diff.js @@ -241,11 +241,13 @@ function CodeifyText(lhs, rhs, options) { this.ctxs = {}; this.options = options; this.options.split = this.options.split || 'lines'; + const exp = /\p{Letter}\p{Mark}*|\p{Number}\p{Mark}*|\p{Punctuation}\p{Mark}*|\p{Symbol}\p{Mark}*|\p{White_Space}/gu; if (typeof lhs === 'string') { if (this.options.split === 'chars') { + console.log('HERE') // split characters and include their diacritical marks - this.lhs = lhs.match(/\p{Letter}\p{Mark}*|\p{White_Space}/gu) || []; + this.lhs = lhs.match(exp) || []; // this.lhs = [...lhs]; } else if (this.options.split === 'words') { this.lhs = lhs.split(/\s/); @@ -258,7 +260,7 @@ function CodeifyText(lhs, rhs, options) { if (typeof rhs === 'string') { if (this.options.split === 'chars') { // split characters and include their diacritical marks - this.rhs = rhs.match(/\p{Letter}\p{Mark}*|\p{White_Space}/gu) || []; + this.rhs = rhs.match(exp) || []; // this.rhs = [...rhs]; } else if (this.options.split === 'words') { this.rhs = rhs.split(/\s/); diff --git a/src/vdoc.js b/src/vdoc.js index 9ee8366..ef82639 100644 --- a/src/vdoc.js +++ b/src/vdoc.js @@ -2,7 +2,9 @@ const diff = require('./diff'); const trace = console.log; -const expLetters = new RegExp(/\p{Letter}\p{Mark}*|\p{White_Space}/gu); +const expLetters = new RegExp( + /\p{Letter}\p{Mark}*|\p{Number}\p{Mark}*|\p{Punctuation}\p{Mark}*|\p{Symbol}\p{Mark}*|\p{White_Space}/gu +); class VDoc { constructor(options) { diff --git a/test/markup.spec.js b/test/markup.spec.js index 61c3341..f80eb09 100644 --- a/test/markup.spec.js +++ b/test/markup.spec.js @@ -42,6 +42,7 @@ describe('markup', () => { const LHS_CHANGE_START = '.mergely.lhs.c.CodeMirror-linebackground.start'; const LHS_CHANGE_END = '.mergely.lhs.c.CodeMirror-linebackground.end'; + const LHS_CHANGE_START_AND_END = '.mergely.lhs.c.CodeMirror-linebackground.start.end'; const RHS_CHANGE_START = '.mergely.rhs.c.CodeMirror-linebackground.start'; const RHS_CHANGE_END = '.mergely.rhs.c.CodeMirror-linebackground.end'; @@ -335,7 +336,31 @@ describe('markup', () => { expect(rhs_spans[0].innerText).to.equal('y'); } }, - + { + name: 'Changes with non-letter chars', + lhs: '~# 00 == ! (dog) \n', + rhs: '~? 11 ++ ] (fox) .\n', + only: true, + check: (editor) => { + expect(editor.querySelectorAll(LHS_CHANGE_START_AND_END + '.cid-0')).to.have.length(1); + expect(editor.querySelectorAll(LHS_INLINE_TEXT + '.cid-0')).to.have.length(6); + expect(editor.querySelectorAll(RHS_INLINE_TEXT + '.cid-0')).to.have.length(7); + const lhs_changes = editor.querySelectorAll(LHS_INLINE_TEXT + '.cid-0'); + const rhs_changes = editor.querySelectorAll(RHS_INLINE_TEXT + '.cid-0'); + const lhs_values = []; + for (const value of lhs_changes.values()) { + lhs_values.push(value.innerText); + } + const rhs_values = []; + for (const value of rhs_changes.values()) { + rhs_values.push(value.innerText); + } + console.log(lhs_values); + console.log(rhs_values); + expect(lhs_values).to.deep.equal(['#', '00', '==', '!', 'd', 'g']); + expect(rhs_values).to.deep.equal(['?', '11', '++', ']', 'f', 'x', '.']); + } + }, ]; // to debug, add `only: true` to the test `opts` above, and run `npm run debug`