|
@@ -4,6 +4,7 @@ import type {
|
|
IDisposable,
|
|
IDisposable,
|
|
IPosition,
|
|
IPosition,
|
|
} from "monaco-editor/esm/vs/editor/editor.api";
|
|
} from "monaco-editor/esm/vs/editor/editor.api";
|
|
|
|
+import debounce from "lodash.debounce";
|
|
|
|
|
|
/** Options passed in to the Rustpad constructor. */
|
|
/** Options passed in to the Rustpad constructor. */
|
|
export type RustpadOptions = {
|
|
export type RustpadOptions = {
|
|
@@ -56,12 +57,15 @@ class Rustpad {
|
|
this.onChangeHandle = options.editor.onDidChangeModelContent((e) =>
|
|
this.onChangeHandle = options.editor.onDidChangeModelContent((e) =>
|
|
this.onChange(e)
|
|
this.onChange(e)
|
|
);
|
|
);
|
|
- this.onCursorHandle = options.editor.onDidChangeCursorPosition((e) =>
|
|
|
|
- this.onCursor(e)
|
|
|
|
- );
|
|
|
|
- this.onSelectionHandle = options.editor.onDidChangeCursorSelection((e) =>
|
|
|
|
- this.onSelection(e)
|
|
|
|
- );
|
|
|
|
|
|
+ const cursorUpdate = debounce(() => this.sendCursorData(), 20);
|
|
|
|
+ this.onCursorHandle = options.editor.onDidChangeCursorPosition((e) => {
|
|
|
|
+ this.onCursor(e);
|
|
|
|
+ cursorUpdate();
|
|
|
|
+ });
|
|
|
|
+ this.onSelectionHandle = options.editor.onDidChangeCursorSelection((e) => {
|
|
|
|
+ this.onSelection(e);
|
|
|
|
+ cursorUpdate();
|
|
|
|
+ });
|
|
this.beforeUnload = (event: BeforeUnloadEvent) => {
|
|
this.beforeUnload = (event: BeforeUnloadEvent) => {
|
|
if (this.outstanding) {
|
|
if (this.outstanding) {
|
|
event.preventDefault();
|
|
event.preventDefault();
|
|
@@ -412,7 +416,6 @@ class Rustpad {
|
|
private onCursor(event: editor.ICursorPositionChangedEvent) {
|
|
private onCursor(event: editor.ICursorPositionChangedEvent) {
|
|
const cursors = [event.position, ...event.secondaryPositions];
|
|
const cursors = [event.position, ...event.secondaryPositions];
|
|
this.cursorData.cursors = cursors.map((p) => unicodeOffset(this.model, p));
|
|
this.cursorData.cursors = cursors.map((p) => unicodeOffset(this.model, p));
|
|
- this.sendCursorData();
|
|
|
|
}
|
|
}
|
|
|
|
|
|
private onSelection(event: editor.ICursorSelectionChangedEvent) {
|
|
private onSelection(event: editor.ICursorSelectionChangedEvent) {
|
|
@@ -421,7 +424,6 @@ class Rustpad {
|
|
unicodeOffset(this.model, s.getStartPosition()),
|
|
unicodeOffset(this.model, s.getStartPosition()),
|
|
unicodeOffset(this.model, s.getEndPosition()),
|
|
unicodeOffset(this.model, s.getEndPosition()),
|
|
]);
|
|
]);
|
|
- this.sendCursorData();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|