Skip to content

Commit

Permalink
fix copy and paste
Browse files Browse the repository at this point in the history
  • Loading branch information
webzwo0i committed Jan 14, 2022
1 parent 8c9d776 commit bd14d52
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
11 changes: 7 additions & 4 deletions static/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ exports.postAceInit = function(hook, context) {
}

exports.aceAttribsToClasses = function(hook, context) {
if(context.key == 'url'){
var url = context.value;
return ['url-' + url ];
if (context.key === 'url'){
if (/^ ?url-/.test(context.value)) {
return [context.value];
} else {
return ['url-' + context.value];
}
}
}

Expand Down Expand Up @@ -83,6 +86,6 @@ function doInsertLink(url) {
exports.collectContentPre = function(hook,context) {
var url = /(?:^| )url-(\S*)/.exec(context.cls);
if(url) {
context.cc.doAttrib(context.state,"url::" + url);
context.cc.doAttrib(context.state,"url::" + url[0]);
}
}
28 changes: 28 additions & 0 deletions static/tests/frontend/specs/embeddedlinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,32 @@ describe('ep_embedded_hyperlinks2', function () {
secondSpan.classList.contains('b');
});
});

it('has correct links after copy and paste', async function() {
// FIXME use clipboard API
const html = '<span class="url-beta.etherpad.com/"><a href="http://beta.etherpad.com/">1link, </a></span>\
<span class="b url-beta.etherpad.com/"><a href="http://beta.etherpad.com/"><b>2bold</b></a></span>\
<span class="url-beta.etherpad.com/"><a href="http://beta.etherpad.com/">, 3link</a></span>'
helper.linesDiv()[0].html(html);
await helper.waitForPromise(() => helper.commits.length === 1);

await helper.waitForPromise(() => {
const lineText = helper.textLines()[0];
const firstSpan = helper.linesDiv()[0][0].children[0];
const secondSpan = helper.linesDiv()[0][0].children[1];
const thirdSpan = helper.linesDiv()[0][0].children[2];

return lineText === '1link, 2bold, 3link' &&
firstSpan.children[0].getAttribute('href') === 'http://beta.etherpad.com/' &&
secondSpan.children[0].getAttribute('href') === 'http://beta.etherpad.com/' &&
thirdSpan.children[0].getAttribute('href') === 'http://beta.etherpad.com/' &&
firstSpan.classList.contains('url-beta.etherpad.com/') &&
!firstSpan.classList.contains('url-') &&
secondSpan.classList.contains('url-beta.etherpad.com/') &&
!secondSpan.classList.contains('url-') &&
thirdSpan.classList.contains('url-beta.etherpad.com/') &&
!thirdSpan.classList.contains('url-') &&
secondSpan.classList.contains('b');
});
});
});

0 comments on commit bd14d52

Please sign in to comment.