1
0
mirror of synced 2025-11-06 04:30:40 +08:00

fix: Fixed a regression rendering inline markup for numbers, punctuation, and symbols

This commit is contained in:
Jamie Peabody
2024-06-19 19:15:54 +01:00
parent 64a20ee5b1
commit 592725282c
3 changed files with 33 additions and 4 deletions

View File

@@ -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/);

View File

@@ -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) {

View File

@@ -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`