|
4 | 4 | *--------------------------------------------------------------------------------------------*/ |
5 | 5 |
|
6 | 6 | import * as strings from 'vs/base/common/strings'; |
7 | | -import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; |
| 7 | +import { ICodeEditor, IActiveCodeEditor } from 'vs/editor/browser/editorBrowser'; |
8 | 8 | import { Position } from 'vs/editor/common/core/position'; |
9 | 9 | import { Range } from 'vs/editor/common/core/range'; |
| 10 | +import { CancellationTokenSource } from 'vs/base/common/cancellation'; |
| 11 | +import { IDisposable, dispose } from 'vs/base/common/lifecycle'; |
10 | 12 |
|
11 | 13 | export const enum CodeEditorStateFlag { |
12 | 14 | Value = 1, |
@@ -71,6 +73,35 @@ export class EditorState { |
71 | 73 | } |
72 | 74 | } |
73 | 75 |
|
| 76 | + |
| 77 | +export class EditorStateCancellationTokenSource extends CancellationTokenSource { |
| 78 | + |
| 79 | + private readonly _listener: IDisposable[] = []; |
| 80 | + |
| 81 | + constructor(readonly editor: IActiveCodeEditor, flags: CodeEditorStateFlag) { |
| 82 | + super(); |
| 83 | + |
| 84 | + if (flags & CodeEditorStateFlag.Position) { |
| 85 | + this._listener.push(editor.onDidChangeCursorPosition(_ => this.cancel())); |
| 86 | + } |
| 87 | + if (flags & CodeEditorStateFlag.Selection) { |
| 88 | + this._listener.push(editor.onDidChangeCursorSelection(_ => this.cancel())); |
| 89 | + } |
| 90 | + if (flags & CodeEditorStateFlag.Scroll) { |
| 91 | + this._listener.push(editor.onDidScrollChange(_ => this.cancel())); |
| 92 | + } |
| 93 | + if (flags & CodeEditorStateFlag.Value) { |
| 94 | + this._listener.push(editor.onDidChangeModel(_ => this.cancel())); |
| 95 | + this._listener.push(editor.onDidChangeModelContent(_ => this.cancel())); |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + dispose() { |
| 100 | + dispose(this._listener); |
| 101 | + super.dispose(); |
| 102 | + } |
| 103 | +} |
| 104 | + |
74 | 105 | export class StableEditorScrollState { |
75 | 106 |
|
76 | 107 | public static capture(editor: ICodeEditor): StableEditorScrollState { |
|
0 commit comments