mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-14 18:46:34 -05:00
Merge from vscode 31e03b8ffbb218a87e3941f2b63a249f061fe0e4 (#4986)
This commit is contained in:
@@ -115,6 +115,13 @@ export class DragMouseEvent extends StandardMouseEvent {
|
||||
|
||||
export interface IMouseWheelEvent extends MouseEvent {
|
||||
readonly wheelDelta: number;
|
||||
readonly wheelDeltaX: number;
|
||||
readonly wheelDeltaY: number;
|
||||
|
||||
readonly deltaX: number;
|
||||
readonly deltaY: number;
|
||||
readonly deltaZ: number;
|
||||
readonly deltaMode: number;
|
||||
}
|
||||
|
||||
interface IWebKitMouseWheelEvent {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
declare var Buffer: any;
|
||||
const hasBuffer = (typeof Buffer !== 'undefined');
|
||||
export const hasBuffer = (typeof Buffer !== 'undefined');
|
||||
|
||||
let textEncoder: TextEncoder | null;
|
||||
let textDecoder: TextDecoder | null;
|
||||
@@ -20,6 +20,11 @@ export class VSBuffer {
|
||||
}
|
||||
|
||||
public static wrap(actual: Uint8Array): VSBuffer {
|
||||
if (hasBuffer && !(Buffer.isBuffer(actual))) {
|
||||
// https://nodejs.org/dist/latest-v10.x/docs/api/buffer.html#buffer_class_method_buffer_from_arraybuffer_byteoffset_length
|
||||
// Create a zero-copy Buffer wrapper around the ArrayBuffer pointed to by the Uint8Array
|
||||
actual = Buffer.from(actual.buffer, actual.byteOffset, actual.byteLength);
|
||||
}
|
||||
return new VSBuffer(actual);
|
||||
}
|
||||
|
||||
@@ -124,3 +129,44 @@ function readUint8(source: Uint8Array, offset: number): number {
|
||||
function writeUint8(destination: Uint8Array, value: number, offset: number): void {
|
||||
destination[offset] = value;
|
||||
}
|
||||
|
||||
export interface VSBufferReadable {
|
||||
|
||||
/**
|
||||
* Read data from the underlying source. Will return
|
||||
* null to indicate that no more data can be read.
|
||||
*/
|
||||
read(): VSBuffer | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to fully read a VSBuffer readable into a single buffer.
|
||||
*/
|
||||
export function readableToBuffer(readable: VSBufferReadable): VSBuffer {
|
||||
const chunks: VSBuffer[] = [];
|
||||
|
||||
let chunk: VSBuffer | null;
|
||||
while (chunk = readable.read()) {
|
||||
chunks.push(chunk);
|
||||
}
|
||||
|
||||
return VSBuffer.concat(chunks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to convert a buffer into a readable buffer.
|
||||
*/
|
||||
export function bufferToReadable(buffer: VSBuffer): VSBufferReadable {
|
||||
let done = false;
|
||||
return {
|
||||
read: () => {
|
||||
if (done) {
|
||||
return null;
|
||||
}
|
||||
|
||||
done = true;
|
||||
|
||||
return buffer;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -265,33 +265,6 @@ export namespace Event {
|
||||
return emitter.event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to `buffer` but it buffers indefinitely and repeats
|
||||
* the buffered events to every new listener.
|
||||
*/
|
||||
export function echo<T>(event: Event<T>, nextTick = false, buffer: T[] = []): Event<T> {
|
||||
buffer = buffer.slice();
|
||||
|
||||
event(e => {
|
||||
buffer.push(e);
|
||||
emitter.fire(e);
|
||||
});
|
||||
|
||||
const flush = (listener: (e: T) => any, thisArgs?: any) => buffer.forEach(e => listener.call(thisArgs, e));
|
||||
|
||||
const emitter = new Emitter<T>({
|
||||
onListenerDidAdd(emitter: Emitter<T>, listener: (e: T) => any, thisArgs?: any) {
|
||||
if (nextTick) {
|
||||
setTimeout(() => flush(listener, thisArgs));
|
||||
} else {
|
||||
flush(listener, thisArgs);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return emitter.event;
|
||||
}
|
||||
|
||||
export interface IChainableEvent<T> {
|
||||
event: Event<T>;
|
||||
map<O>(fn: (i: T) => O): IChainableEvent<O>;
|
||||
|
||||
@@ -44,4 +44,6 @@ export namespace Schemas {
|
||||
export const data: string = 'data';
|
||||
|
||||
export const command: string = 'command';
|
||||
|
||||
export const vscodeRemote: string = 'vscode-remote';
|
||||
}
|
||||
|
||||
@@ -284,7 +284,6 @@ export namespace DataUri {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class ResourceGlobMatcher {
|
||||
|
||||
private readonly globalExpression: ParsedExpression;
|
||||
@@ -311,3 +310,16 @@ export class ResourceGlobMatcher {
|
||||
return !!this.globalExpression(resource.path);
|
||||
}
|
||||
}
|
||||
|
||||
export function toLocalResource(resource: URI, authority: string | undefined): URI {
|
||||
if (authority) {
|
||||
let path = resource.path;
|
||||
if (path && path[0] !== paths.posix.sep) {
|
||||
path = paths.posix.sep + path;
|
||||
}
|
||||
|
||||
return resource.with({ scheme: Schemas.vscodeRemote, authority, path });
|
||||
}
|
||||
|
||||
return resource.with({ scheme: Schemas.file });
|
||||
}
|
||||
20
src/vs/base/test/common/buffer.test.ts
Normal file
20
src/vs/base/test/common/buffer.test.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { hasBuffer, VSBuffer } from 'vs/base/common/buffer';
|
||||
|
||||
suite('Buffer', () => {
|
||||
|
||||
if (hasBuffer) {
|
||||
test('issue #71993 - VSBuffer#toString returns numbers', () => {
|
||||
const data = new Uint8Array([1, 2, 3, 'h'.charCodeAt(0), 'i'.charCodeAt(0), 4, 5]).buffer;
|
||||
const buffer = VSBuffer.wrap(new Uint8Array(data, 3, 2));
|
||||
assert.deepEqual(buffer.toString(), 'hi');
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
@@ -645,67 +645,6 @@ suite('Event utils', () => {
|
||||
});
|
||||
});
|
||||
|
||||
suite('echo', () => {
|
||||
|
||||
test('should echo events', () => {
|
||||
const result: number[] = [];
|
||||
const emitter = new Emitter<number>();
|
||||
const event = emitter.event;
|
||||
const echoEvent = Event.echo(event);
|
||||
|
||||
emitter.fire(1);
|
||||
emitter.fire(2);
|
||||
emitter.fire(3);
|
||||
assert.deepEqual(result, []);
|
||||
|
||||
const listener = echoEvent(num => result.push(num));
|
||||
assert.deepEqual(result, [1, 2, 3]);
|
||||
|
||||
emitter.fire(4);
|
||||
assert.deepEqual(result, [1, 2, 3, 4]);
|
||||
|
||||
listener.dispose();
|
||||
emitter.fire(5);
|
||||
assert.deepEqual(result, [1, 2, 3, 4]);
|
||||
});
|
||||
|
||||
test('should echo events for every listener', () => {
|
||||
const result1: number[] = [];
|
||||
const result2: number[] = [];
|
||||
const emitter = new Emitter<number>();
|
||||
const event = emitter.event;
|
||||
const echoEvent = Event.echo(event);
|
||||
|
||||
emitter.fire(1);
|
||||
emitter.fire(2);
|
||||
emitter.fire(3);
|
||||
assert.deepEqual(result1, []);
|
||||
assert.deepEqual(result2, []);
|
||||
|
||||
const listener1 = echoEvent(num => result1.push(num));
|
||||
assert.deepEqual(result1, [1, 2, 3]);
|
||||
assert.deepEqual(result2, []);
|
||||
|
||||
emitter.fire(4);
|
||||
assert.deepEqual(result1, [1, 2, 3, 4]);
|
||||
assert.deepEqual(result2, []);
|
||||
|
||||
const listener2 = echoEvent(num => result2.push(num));
|
||||
assert.deepEqual(result1, [1, 2, 3, 4]);
|
||||
assert.deepEqual(result2, [1, 2, 3, 4]);
|
||||
|
||||
emitter.fire(5);
|
||||
assert.deepEqual(result1, [1, 2, 3, 4, 5]);
|
||||
assert.deepEqual(result2, [1, 2, 3, 4, 5]);
|
||||
|
||||
listener1.dispose();
|
||||
listener2.dispose();
|
||||
emitter.fire(6);
|
||||
assert.deepEqual(result1, [1, 2, 3, 4, 5]);
|
||||
assert.deepEqual(result2, [1, 2, 3, 4, 5]);
|
||||
});
|
||||
});
|
||||
|
||||
suite('EventMultiplexer', () => {
|
||||
|
||||
test('works', () => {
|
||||
|
||||
Reference in New Issue
Block a user