提交 c936b0f6 编写于 作者: B Benjamin Pasero

Jumpy cursor with trim trailing whitespace and autosave (fixes #18410)

上级 05ac1a76
...@@ -70,23 +70,21 @@ class TrimWhitespaceParticipant implements INamedSaveParticpant { ...@@ -70,23 +70,21 @@ class TrimWhitespaceParticipant implements INamedSaveParticpant {
} }
function findEditor(model: IModel, codeEditorService: ICodeEditorService): ICommonCodeEditor { function findEditor(model: IModel, codeEditorService: ICodeEditorService): ICommonCodeEditor {
if (model.isAttachedToEditor()) { let candidate: ICommonCodeEditor = null;
const allEditors = codeEditorService.listCodeEditors();
for (let i = 0, len = allEditors.length; i < len; i++) {
const editor = allEditors[i];
const editorModel = editor.getModel();
if (!editorModel) { if (model.isAttachedToEditor()) {
continue; // empty editor for (const editor of codeEditorService.listCodeEditors()) {
} if (editor.getModel() === model) {
if (editor.isFocused()) {
return editor; // favour focussed editor if there are multiple
}
if (model === editorModel) { candidate = editor;
return editor;
} }
} }
} }
return null; return candidate;
} }
export class FinalNewLineParticipant implements INamedSaveParticpant { export class FinalNewLineParticipant implements INamedSaveParticpant {
...@@ -158,7 +156,7 @@ class FormatOnSaveParticipant implements INamedSaveParticpant { ...@@ -158,7 +156,7 @@ class FormatOnSaveParticipant implements INamedSaveParticpant {
}).then(edits => { }).then(edits => {
if (edits && versionNow === model.getVersionId()) { if (edits && versionNow === model.getVersionId()) {
const editor = this._findEditor(model); const editor = findEditor(model, this._editorService);
if (editor) { if (editor) {
this._editsWithEditor(editor, edits); this._editsWithEditor(editor, edits);
} else { } else {
...@@ -194,24 +192,6 @@ class FormatOnSaveParticipant implements INamedSaveParticpant { ...@@ -194,24 +192,6 @@ class FormatOnSaveParticipant implements INamedSaveParticpant {
forceMoveMarkers: true forceMoveMarkers: true
}; };
} }
private _findEditor(model: IModel) {
if (!model.isAttachedToEditor()) {
return;
}
let candidate: ICommonCodeEditor;
for (const editor of this._editorService.listCodeEditors()) {
if (editor.getModel() === model) {
if (editor.isFocused()) {
return editor;
} else {
candidate = editor;
}
}
}
return candidate;
}
} }
class ExtHostSaveParticipant implements INamedSaveParticpant { class ExtHostSaveParticipant implements INamedSaveParticpant {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册