Slightly different way of addressing #1085
saving files after local update with setTexrtpull/1098/head
parent
362b590ba3
commit
28f3e454b6
|
@ -28,8 +28,11 @@ export function getText(): Promise<string> {
|
|||
* This updates the editor text, but in a minimal-diff way:
|
||||
* it compares the current editor text with the new text, and only sends the changes to the editor, thereby preserving cursor location
|
||||
*/
|
||||
export function setText(newText: string): Promise<void> {
|
||||
return syscall("editor.setText", newText);
|
||||
export function setText(
|
||||
newText: string,
|
||||
isolateHistory = false,
|
||||
): Promise<void> {
|
||||
return syscall("editor.setText", newText, isolateHistory);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -659,7 +659,7 @@ export class Client implements ConfigContainer {
|
|||
if (this.currentPage) {
|
||||
if (
|
||||
!this.ui.viewState.unsavedChanges ||
|
||||
this.ui.viewState.uiOptions.forcedROMode
|
||||
this.ui.viewState.uiOptions.forcedROMode || this.readOnlyMode
|
||||
) {
|
||||
// No unsaved changes, or read-only mode, not gonna save
|
||||
return resolve();
|
||||
|
@ -1143,7 +1143,7 @@ export class Client implements ConfigContainer {
|
|||
this.space.watchPage(pageName);
|
||||
} else {
|
||||
// Just apply minimal patches so that the cursor is preserved
|
||||
await editor.setText(doc.text);
|
||||
await editor.setText(doc.text, true);
|
||||
}
|
||||
|
||||
// Note: these events are dispatched asynchronously deliberately (not waiting for results)
|
||||
|
|
|
@ -25,12 +25,14 @@ export function editorSyscalls(client: Client): SysCallMapping {
|
|||
"editor.getText": () => {
|
||||
return client.editorView.state.sliceDoc();
|
||||
},
|
||||
"editor.setText": (_ctx, newText: string) => {
|
||||
"editor.setText": (_ctx, newText: string, shouldIsolateHistory = false) => {
|
||||
const currentText = client.editorView.state.sliceDoc();
|
||||
const allChanges = diffAndPrepareChanges(currentText, newText);
|
||||
client.editorView.dispatch({
|
||||
changes: allChanges,
|
||||
annotations: isolateHistory.of("full"),
|
||||
annotations: shouldIsolateHistory
|
||||
? isolateHistory.of("full")
|
||||
: undefined,
|
||||
});
|
||||
},
|
||||
"editor.getCursor": (): number => {
|
||||
|
|
Loading…
Reference in New Issue