hack around DOM renderer issue, fix api tests

This commit is contained in:
Jörg Breitbart
2022-12-04 22:26:29 +01:00
parent d19361ac85
commit 39c2e57ad3
5 changed files with 21 additions and 16 deletions
@@ -46,13 +46,12 @@ export class LinkComputer {
const rex = new RegExp(regex.source, (regex.flags || '') + 'g');
const [lines, startLineIndex] = LinkComputer._getFullLineString(y - 1, terminal);
// TODO: do locally limited search if string is too long
const line = lines.join('');
// Don't try if the wrapped line if excessively large as the regex matching will block the main
// thread.
if (line.length > 1024) {
// TODO: more sophisticated handling with individual line introspection?
return [];
}
@@ -62,12 +61,6 @@ export class LinkComputer {
while ((match = rex.exec(line)) !== null) {
const text = match[0];
if (!text) {
// something matched but does not comply with the given matchIndex
// since this is most likely a bug the regex itself we simply do nothing here
console.log('match found without corresponding matchIndex');
break;
}
// Get index, match.index is for the outer match which includes negated chars
// therefore we cannot use match.index directly, instead we search the position
@@ -99,8 +92,8 @@ export class LinkComputer {
}
const [startY, startX] = LinkComputer._mapStringIndexToBuffer(startLineIndex, stringIndex, terminal);
const [endY, endX] = LinkComputer._mapStringIndexToBuffer(startLineIndex, stringIndex + text.length, terminal);
const [startY, startX] = LinkComputer._mapStrIdx(startLineIndex, stringIndex, terminal);
const [endY, endX] = LinkComputer._mapStrIdx(startLineIndex, stringIndex + text.length, terminal);
if (startY === -1 || startX === -1 || endY === -1 || endX === -1) {
continue;
@@ -112,8 +105,8 @@ export class LinkComputer {
y: startY + 1
},
end: {
x: endX + 1,
y: endY
x: endX,
y: endY + 1
}
};
@@ -155,7 +148,7 @@ export class LinkComputer {
* Returns buffer position as [lineIndex, columnIndex] 0-based,
* or [-1, -1] in case the lookup ran into a non-existing line.
*/
private static _mapStringIndexToBuffer(lineIndex: number, stringIndex: number, terminal: Terminal): [number, number] {
private static _mapStrIdx(lineIndex: number, stringIndex: number, terminal: Terminal): [number, number] {
const buf = terminal.buffer.active;
const cell = buf.getNullCell();
while (stringIndex) {
@@ -7,9 +7,10 @@ import { Terminal, ITerminalAddon, IDisposable } from 'xterm';
import { ILinkProviderOptions, WebLinkProvider } from './WebLinkProvider';
// consider everthing starting with http:// or https://
// up to first whitespace as url
// gets further narrowed down with URL later on
const strictUrlRegex = /https?:[/]{2}\S*/;
// up to first whitespace, `"` or `'` as url
// NOTE: The repeated end clause is needed to not match a dangling `:`
// resembling the old (...)*([^:"\'\\s]) final path clause
const strictUrlRegex = /https?:[/]{2}[^\s^"^']*[^\s^"^'^:]/;
function handleLink(event: MouseEvent, uri: string): void {
const newWindow = window.open();
@@ -35,6 +35,10 @@ describe('WebLinksAddon', () => {
it('.io', async function(): Promise<any> {
await testHostName('foo.io');
});
it.skip('correct buffer offsets', async () => {
// TODO: test strings in test_weblinks.sh automatically
});
});
async function testHostName(hostname: string): Promise<void> {