Skip to content

Commit 9ee0b51

Browse files
authored
Merge branch 'master' into reuse_bufferlines
2 parents ef6f0db + e4a8464 commit 9ee0b51

File tree

5 files changed

+67
-19
lines changed

5 files changed

+67
-19
lines changed

src/SelectionManager.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class TestSelectionManager extends SelectionManager {
3030

3131
public selectLineAt(line: number): void { this._selectLineAt(line); }
3232
public selectWordAt(coords: [number, number]): void { this._selectWordAt(coords, true); }
33+
public areCoordsInSelection(coords: [number, number], start: [number, number], end: [number, number]): boolean { return this._areCoordsInSelection(coords, start, end); }
3334

3435
// Disable DOM interaction
3536
public enable(): void {}
@@ -478,5 +479,17 @@ describe('SelectionManager', () => {
478479
assert.equal(selectionManager.selectionText, 'a\n😁\nc');
479480
});
480481
});
482+
483+
describe('_areCoordsInSelection', () => {
484+
it('should return whether coords are in the selection', () => {
485+
assert.isFalse(selectionManager.areCoordsInSelection([0, 0], [2, 0], [2, 1]));
486+
assert.isFalse(selectionManager.areCoordsInSelection([1, 0], [2, 0], [2, 1]));
487+
assert.isTrue(selectionManager.areCoordsInSelection([2, 0], [2, 0], [2, 1]));
488+
assert.isTrue(selectionManager.areCoordsInSelection([10, 0], [2, 0], [2, 1]));
489+
assert.isTrue(selectionManager.areCoordsInSelection([0, 1], [2, 0], [2, 1]));
490+
assert.isTrue(selectionManager.areCoordsInSelection([1, 1], [2, 0], [2, 1]));
491+
assert.isFalse(selectionManager.areCoordsInSelection([2, 1], [2, 0], [2, 1]));
492+
});
493+
});
481494
});
482495

src/SelectionManager.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,14 @@ export class SelectionManager extends EventEmitter implements ISelectionManager
289289
return false;
290290
}
291291

292+
return this._areCoordsInSelection(coords, start, end);
293+
}
294+
295+
protected _areCoordsInSelection(coords: [number, number], start: [number, number], end: [number, number]): boolean {
292296
return (coords[1] > start[1] && coords[1] < end[1]) ||
293-
(start[1] === end[1] && coords[1] === start[1] && coords[0] > start[0] && coords[0] < end[0]) ||
294-
(start[1] < end[1] && coords[1] === end[1] && coords[0] < end[0]);
297+
(start[1] === end[1] && coords[1] === start[1] && coords[0] >= start[0] && coords[0] < end[0]) ||
298+
(start[1] < end[1] && coords[1] === end[1] && coords[0] < end[0]) ||
299+
(start[1] < end[1] && coords[1] === start[1] && coords[0] >= start[0]);
295300
}
296301

297302
/**

src/SoundManager.ts

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,36 @@ import { ITerminal, ISoundManager } from './Types';
1212
export const DEFAULT_BELL_SOUND = 'data:audio/wav;base64,UklGRigBAABXQVZFZm10IBAAAAABAAEARKwAAIhYAQACABAAZGF0YQQBAADpAFgCwAMlBZoG/wdmCcoKRAypDQ8PbRDBEQQTOxRtFYcWlBePGIUZXhoiG88bcBz7HHIdzh0WHlMeZx51HmkeUx4WHs8dah0AHXwc3hs9G4saxRnyGBIYGBcQFv8U4RPAEoYRQBACD70NWwwHC6gJOwjWBloF7gOBAhABkf8b/qv8R/ve+Xf4Ife79W/0JfPZ8Z/wde9N7ijtE+wU6xvqM+lb6H7nw+YX5mrlxuQz5Mzje+Ma49fioeKD4nXiYeJy4pHitOL04j/jn+MN5IPkFOWs5U3mDefM55/ogOl36m7rdOyE7abuyu8D8Unyj/Pg9D/2qfcb+Yn6/vuK/Qj/lAAlAg==';
1313

1414
export class SoundManager implements ISoundManager {
15-
private _audioContext: AudioContext;
15+
private static _audioContext: AudioContext;
16+
17+
static get audioContext(): AudioContext | null {
18+
if (!SoundManager._audioContext) {
19+
const audioContextCtor: typeof AudioContext = (<any>window).AudioContext || (<any>window).webkitAudioContext;
20+
if (!audioContextCtor) {
21+
console.warn('Web Audio API is not supported by this browser. Consider upgrading to the latest version');
22+
return null;
23+
}
24+
SoundManager._audioContext = new audioContextCtor();
25+
}
26+
return SoundManager._audioContext;
27+
}
1628

1729
constructor(
1830
private _terminal: ITerminal
1931
) {
2032
}
2133

2234
public playBellSound(): void {
23-
const audioContextCtor: typeof AudioContext = (<any>window).AudioContext || (<any>window).webkitAudioContext;
24-
if (!this._audioContext && audioContextCtor) {
25-
this._audioContext = new audioContextCtor();
26-
}
27-
28-
if (this._audioContext) {
29-
const bellAudioSource = this._audioContext.createBufferSource();
30-
const context = this._audioContext;
31-
this._audioContext.decodeAudioData(this._base64ToArrayBuffer(this._removeMimeType(this._terminal.options.bellSound)), (buffer) => {
32-
bellAudioSource.buffer = buffer;
33-
bellAudioSource.connect(context.destination);
34-
bellAudioSource.start(0);
35-
});
36-
} else {
37-
console.warn('Sorry, but the Web Audio API is not supported by your browser. Please, consider upgrading to the latest version');
35+
const ctx = SoundManager.audioContext;
36+
if (!ctx) {
37+
return;
3838
}
39+
const bellAudioSource = ctx.createBufferSource();
40+
ctx.decodeAudioData(this._base64ToArrayBuffer(this._removeMimeType(this._terminal.options.bellSound)), (buffer) => {
41+
bellAudioSource.buffer = buffer;
42+
bellAudioSource.connect(ctx.destination);
43+
bellAudioSource.start(0);
44+
});
3945
}
4046

4147
private _base64ToArrayBuffer(base64: string): ArrayBuffer {

src/addons/webLinks/webLinks.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,28 @@ describe('webLinks addon', () => {
3939

4040
assert.equal(uri, 'http://foo.com/a~b#c~d?e~f');
4141
});
42+
43+
it('should allow : character in URI path', () => {
44+
const term = new MockTerminal();
45+
webLinks.webLinksInit(<any>term);
46+
47+
const row = ' http://foo.com/colon:test ';
48+
49+
const match = row.match(term.regex);
50+
const uri = match[term.options.matchIndex];
51+
52+
assert.equal(uri, 'http://foo.com/colon:test');
53+
});
54+
55+
it('should not allow : character at the end of a URI path', () => {
56+
const term = new MockTerminal();
57+
webLinks.webLinksInit(<any>term);
58+
59+
const row = ' http://foo.com/colon:test: ';
60+
61+
const match = row.match(term.regex);
62+
const uri = match[term.options.matchIndex];
63+
64+
assert.equal(uri, 'http://foo.com/colon:test');
65+
});
4266
});

src/addons/webLinks/webLinks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const ipClause = '((\\d{1,3}\\.){3}\\d{1,3})';
1414
const localHostClause = '(localhost)';
1515
const portClause = '(:\\d{1,5})';
1616
const hostClause = '((' + domainBodyClause + '\\.' + tldClause + ')|' + ipClause + '|' + localHostClause + ')' + portClause + '?';
17-
const pathClause = '(\\/[\\/\\w\\.\\-%~]*)*';
17+
const pathClause = '(\\/[\\/\\w\\.\\-%~:]*)*([^:\\s])';
1818
const queryStringHashFragmentCharacterSet = '[0-9\\w\\[\\]\\(\\)\\/\\?\\!#@$%&\'*+,:;~\\=\\.\\-]*';
1919
const queryStringClause = '(\\?' + queryStringHashFragmentCharacterSet + ')?';
2020
const hashFragmentClause = '(#' + queryStringHashFragmentCharacterSet + ')?';

0 commit comments

Comments
 (0)