Skip to content

Commit

Permalink
fix: Fixed a regression rendering inline markup for numbers, punctuat…
Browse files Browse the repository at this point in the history
…ion, and symbols
  • Loading branch information
wickedest committed Jun 19, 2024
1 parent 64a20ee commit 5927252
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
Expand All @@ -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/);
Expand Down
4 changes: 3 additions & 1 deletion src/vdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
27 changes: 26 additions & 1 deletion test/markup.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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`
Expand Down

0 comments on commit 5927252

Please sign in to comment.