Skip to content

Commit d1300f3

Browse files
committed
fix: when there're multi \pos and \move tags, only the first should work
1 parent bee3031 commit d1300f3

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/compiler/text.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,13 @@ export function compileText({ styles, style, parsed, start, end }) {
4545
const tag = tags[j];
4646
alignment = alignment || a2an[tag.a || 0] || tag.an;
4747
q = compileTag(tag, 'q') || q;
48-
pos = pos || compileTag(tag, 'pos');
48+
if (!move) {
49+
pos = pos || compileTag(tag, 'pos');
50+
}
4951
org = org || compileTag(tag, 'org');
50-
move = move || compileTag(tag, 'move');
52+
if (!pos) {
53+
move = move || compileTag(tag, 'move');
54+
}
5155
fade = fade || compileTag(tag, 'fade') || compileTag(tag, 'fad');
5256
clip = compileTag(tag, 'clip') || clip;
5357
const key = Object.keys(tag)[0];

test/compiler/text.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ describe('text compiler', () => {
8787
expect(alignment).to.equal(1);
8888
expect(pos).to.deep.equal({ x: 1, y: 2 });
8989
expect(org).to.deep.equal({ x: 1, y: 2 });
90-
expect(move).to.deep.equal({ x1: 1, y1: 2, x2: 3, y2: 4, t1: 0, t2: 0 });
90+
expect(move).to.deep.equal(undefined);
9191
expect(fade).to.deep.equal({ type: 'fad', t1: 1, t2: 2 });
9292
expect(clip).to.deep.equal({
9393
inverse: false,
@@ -103,6 +103,13 @@ describe('text compiler', () => {
103103
expect(test3.q).to.equal(2);
104104
});
105105

106+
it('should only respect the first \\pos or \\move tag', () => {
107+
const { parsed } = parseText('{\\move(1,2,3,4)\\pos(5,6)}bla');
108+
const { pos, move } = compileText({ styles, style, parsed });
109+
expect(move).to.deep.equal({ x1: 1, y1: 2, x2: 3, y2: 4, t1: 0, t2: 0 });
110+
expect(pos).to.deep.equal(undefined);
111+
});
112+
106113
it('should compile text with \\r', () => {
107114
const { parsed } = parseText('{\\fr30}a{\\r}b{\\fr60}c{\\ralt}d');
108115
const { slices } = compileText({ styles, style, parsed });

0 commit comments

Comments
 (0)