@vscode/web-editors 0.0.2-134 → 0.0.2-135
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/{syncedTextDocument-EBcq_UIM.d.ts → syncedTextDocument-BIWK0LCP.d.ts} +13 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.js +29 -8
- package/dist/index.js.map +1 -1
- package/dist/vscode.d.ts +1 -1
- package/dist/vscode.js +5 -1
- package/dist/vscode.js.map +1 -1
- package/package.json +2 -2
|
@@ -27,7 +27,17 @@ interface SyncedTextDocument {
|
|
|
27
27
|
* Fires after the text changed (not for other changes such as the dirty
|
|
28
28
|
* state). {@link getText} and {@link version} are those after the change.
|
|
29
29
|
*/
|
|
30
|
-
readonly onDidChangeText: Event<
|
|
30
|
+
readonly onDidChangeText: Event<DocumentTextChange>;
|
|
31
|
+
}
|
|
32
|
+
/** A change of a {@link SyncedTextDocument}'s text. */
|
|
33
|
+
interface DocumentTextChange {
|
|
34
|
+
/**
|
|
35
|
+
* Where the text changed, if known, with offsets into the text before the
|
|
36
|
+
* change; the edits don't overlap. Without them, the old and new text are
|
|
37
|
+
* compared, which turns separate changes into one replacement of
|
|
38
|
+
* everything between them, so the editor loses its cursor there.
|
|
39
|
+
*/
|
|
40
|
+
readonly edits?: readonly DocumentTextEdit[];
|
|
31
41
|
}
|
|
32
42
|
/**
|
|
33
43
|
* Replaces `length` characters at `offset` with `newText`. Unlike the
|
|
@@ -40,5 +50,5 @@ interface DocumentTextEdit {
|
|
|
40
50
|
readonly newText: string;
|
|
41
51
|
}
|
|
42
52
|
//#endregion
|
|
43
|
-
export { IDisposable as i,
|
|
44
|
-
//# sourceMappingURL=syncedTextDocument-
|
|
53
|
+
export { IDisposable as a, Event as i, DocumentTextEdit as n, SyncedTextDocument as r, DocumentTextChange as t };
|
|
54
|
+
//# sourceMappingURL=syncedTextDocument-BIWK0LCP.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
|
-
import {
|
|
5
|
+
import { a as IDisposable, i as Event, n as DocumentTextEdit, r as SyncedTextDocument, t as DocumentTextChange } from "./chunks/syncedTextDocument-BIWK0LCP.js";
|
|
6
6
|
import { HubRpcConnection, InterfaceClient, InterfaceDefinition, MemberMap } from "@vscode/hubrpc";
|
|
7
7
|
import { MessageEndpoint, MessageLikeEvent, WindowMessageTransport } from "@vscode/hubrpc/web";
|
|
8
8
|
import { HubAccessDuration, HubAccessRequest, HubAccessResult } from "@vscode/hubrpc/hub/common";
|
|
@@ -3132,5 +3132,5 @@ interface TrackedOffset extends IDisposable {
|
|
|
3132
3132
|
readonly offset: number;
|
|
3133
3133
|
}
|
|
3134
3134
|
//#endregion
|
|
3135
|
-
export { AppContext, type ConnectionInput, ContentEdit, ContentType, ContentVersion, DocumentTextEdit, EditorAssociationResult, EditorCapabilities, EditorRegistrationStatus, EditorScope, EmbeddedAppAccessOptions, EmbeddedAppDescriptor, EmbeddedAppHandle, EmbeddingContext, type Event, HostCapabilities, HostTransport, type IDisposable, JsonFormatOptions, JsonValue, type MessageEndpoint, type MessageLikeEvent, OT_EDIT_TRANSFORM, OtPeer, OtType, PresentationMode, PresentationPreferences, ScopeRegistration, SyncedTextDocument, TextComponent, TextDocumentEditorOptions, TextDocumentSync, TextDocumentSyncOptions, TextEdit, TextOperation, TextOperationBuilder, TrackedOffset, VsCodeAppEmbeddingEventsProxy, VsCodeAppHostClient, VsCodeAppHostClientOptions, VsCodeAppHostProxy, WebEditorClient, WebEditorClientOptions, WebEditorClientState, WebEditorClientTransportProxy, WebEditorHost, WebEditorHostOptions, WebEditorHostProxy, WebEditorHostTransportProxy, WebEditorPresentationHostProxy, WebEditorPresentationProxy, WebEditorProxy, WebEditorUpdate, WindowMessageTransport, applyContentEdits, applyTextEdits, contentEditsOt, createWindowParentConnection, decodeFromEditor, diffContent, diffText, encodeForEditor, mapContentOffset, mapThrough, textOperationOt, transformContentEdits, vscodeAppEmbeddingEventsInterface, vscodeAppHostInterface, webEditorClientTransportInterface, webEditorHostInterface, webEditorHostTransportInterface, webEditorInterface, webEditorPresentationHostInterface, webEditorPresentationInterface };
|
|
3135
|
+
export { AppContext, type ConnectionInput, ContentEdit, ContentType, ContentVersion, DocumentTextChange, DocumentTextEdit, EditorAssociationResult, EditorCapabilities, EditorRegistrationStatus, EditorScope, EmbeddedAppAccessOptions, EmbeddedAppDescriptor, EmbeddedAppHandle, EmbeddingContext, type Event, HostCapabilities, HostTransport, type IDisposable, JsonFormatOptions, JsonValue, type MessageEndpoint, type MessageLikeEvent, OT_EDIT_TRANSFORM, OtPeer, OtType, PresentationMode, PresentationPreferences, ScopeRegistration, SyncedTextDocument, TextComponent, TextDocumentEditorOptions, TextDocumentSync, TextDocumentSyncOptions, TextEdit, TextOperation, TextOperationBuilder, TrackedOffset, VsCodeAppEmbeddingEventsProxy, VsCodeAppHostClient, VsCodeAppHostClientOptions, VsCodeAppHostProxy, WebEditorClient, WebEditorClientOptions, WebEditorClientState, WebEditorClientTransportProxy, WebEditorHost, WebEditorHostOptions, WebEditorHostProxy, WebEditorHostTransportProxy, WebEditorPresentationHostProxy, WebEditorPresentationProxy, WebEditorProxy, WebEditorUpdate, WindowMessageTransport, applyContentEdits, applyTextEdits, contentEditsOt, createWindowParentConnection, decodeFromEditor, diffContent, diffText, encodeForEditor, mapContentOffset, mapThrough, textOperationOt, transformContentEdits, vscodeAppEmbeddingEventsInterface, vscodeAppHostInterface, webEditorClientTransportInterface, webEditorHostInterface, webEditorHostTransportInterface, webEditorInterface, webEditorPresentationHostInterface, webEditorPresentationInterface };
|
|
3136
3136
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -6094,7 +6094,7 @@ var TextDocumentSync = class {
|
|
|
6094
6094
|
this._onError = options.onError ?? ((message, detail) => console.error("TextDocumentSync:", message, detail));
|
|
6095
6095
|
this._documentText = _document.getText();
|
|
6096
6096
|
this._text = this._documentText;
|
|
6097
|
-
this._subscription = _document.onDidChangeText(() => this._acceptDocumentChange());
|
|
6097
|
+
this._subscription = _document.onDidChangeText((change) => this._acceptDocumentChange(change.edits));
|
|
6098
6098
|
}
|
|
6099
6099
|
/** The editor text: the document text with the editor changes that are not written yet. */
|
|
6100
6100
|
get text() {
|
|
@@ -6175,18 +6175,23 @@ var TextDocumentSync = class {
|
|
|
6175
6175
|
this._unwritten = this._unwritten.compose(operation);
|
|
6176
6176
|
this._write();
|
|
6177
6177
|
}
|
|
6178
|
-
_acceptDocumentChange() {
|
|
6178
|
+
_acceptDocumentChange(edits) {
|
|
6179
|
+
const change = {
|
|
6180
|
+
text: this._document.getText(),
|
|
6181
|
+
edits
|
|
6182
|
+
};
|
|
6179
6183
|
if (this._writing) {
|
|
6180
|
-
this._changesDuringWrite.push(
|
|
6184
|
+
this._changesDuringWrite.push(change);
|
|
6181
6185
|
return;
|
|
6182
6186
|
}
|
|
6183
|
-
this._acceptExternalChange(
|
|
6187
|
+
this._acceptExternalChange(change);
|
|
6184
6188
|
this._write();
|
|
6185
6189
|
}
|
|
6186
6190
|
/** Someone else changed the document: merges the change with the editor changes that are not written yet. */
|
|
6187
|
-
_acceptExternalChange(documentText) {
|
|
6191
|
+
_acceptExternalChange({ text: documentText, edits }) {
|
|
6188
6192
|
if (documentText === this._documentText) return;
|
|
6189
|
-
const
|
|
6193
|
+
const external = (edits && fromDocumentEdits(this._documentText, edits, documentText)) ?? diffText(this._documentText, documentText);
|
|
6194
|
+
const [externalPrime, unwrittenPrime] = TextOperation.transform(external, this._unwritten);
|
|
6190
6195
|
this._documentText = documentText;
|
|
6191
6196
|
this._unwritten = unwrittenPrime;
|
|
6192
6197
|
this._applyFromDocument(externalPrime);
|
|
@@ -6216,7 +6221,7 @@ var TextDocumentSync = class {
|
|
|
6216
6221
|
this._writing = void 0;
|
|
6217
6222
|
const changes = this._changesDuringWrite.splice(0);
|
|
6218
6223
|
if (applied) {
|
|
6219
|
-
const written = changes.shift() ?? this._document.getText();
|
|
6224
|
+
const written = changes.shift()?.text ?? this._document.getText();
|
|
6220
6225
|
this._documentText = written;
|
|
6221
6226
|
const [unwrittenPrime, adjustmentPrime] = TextOperation.transform(this._unwritten, diffText(write.expected, written));
|
|
6222
6227
|
this._unwritten = unwrittenPrime;
|
|
@@ -6226,7 +6231,7 @@ var TextDocumentSync = class {
|
|
|
6226
6231
|
this._unwritten = TextOperation.identity;
|
|
6227
6232
|
this._applyFromDocument(diffText(this._text, this._documentText));
|
|
6228
6233
|
} else this._unwritten = operation.compose(this._unwritten);
|
|
6229
|
-
for (const
|
|
6234
|
+
for (const change of changes) this._acceptExternalChange(change);
|
|
6230
6235
|
this._write();
|
|
6231
6236
|
}
|
|
6232
6237
|
/** Applies a change that comes from the document to {@link text} and sends it to the editor. */
|
|
@@ -6248,6 +6253,22 @@ var TextDocumentSync = class {
|
|
|
6248
6253
|
this._onDidChangeText.fire();
|
|
6249
6254
|
}
|
|
6250
6255
|
};
|
|
6256
|
+
/**
|
|
6257
|
+
* The operation that applies `edits` (offsets into `oldText`, in any order) to
|
|
6258
|
+
* `oldText`, if they don't overlap and turn it into `newText`; `undefined`
|
|
6259
|
+
* otherwise, for example if a change was missed.
|
|
6260
|
+
*/
|
|
6261
|
+
function fromDocumentEdits(oldText, edits, newText) {
|
|
6262
|
+
const builder = new TextOperationBuilder();
|
|
6263
|
+
let offset = 0;
|
|
6264
|
+
for (const edit of [...edits].sort((a, b) => a.offset - b.offset)) {
|
|
6265
|
+
if (edit.offset < offset || edit.length < 0 || edit.offset + edit.length > oldText.length) return;
|
|
6266
|
+
builder.retain(edit.offset - offset).insert(edit.newText).delete(edit.length);
|
|
6267
|
+
offset = edit.offset + edit.length;
|
|
6268
|
+
}
|
|
6269
|
+
const operation = builder.build();
|
|
6270
|
+
return operation.apply(oldText) === newText ? operation : void 0;
|
|
6271
|
+
}
|
|
6251
6272
|
var TrackedOffsetImpl = class {
|
|
6252
6273
|
offset;
|
|
6253
6274
|
assoc;
|