mirror of
https://github.com/Microsoft/vscode
synced 2024-09-19 18:48:00 +00:00
for embedded diff editors link word highlighters
This commit is contained in:
parent
977b6a17f2
commit
6cf7b9d8cd
|
@ -9,7 +9,7 @@ import { CancelablePromise, createCancelablePromise, first, timeout } from 'vs/b
|
|||
import { CancellationToken } from 'vs/base/common/cancellation';
|
||||
import { onUnexpectedError, onUnexpectedExternalError } from 'vs/base/common/errors';
|
||||
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
|
||||
import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
|
||||
import { Disposable, DisposableStore, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
|
||||
import { IActiveCodeEditor, ICodeEditor } from 'vs/editor/browser/editorBrowser';
|
||||
import { EditorAction, EditorContributionInstantiation, IActionOptions, registerEditorAction, registerEditorContribution, registerModelAndPositionCommand } from 'vs/editor/browser/editorExtensions';
|
||||
import { EditorOption } from 'vs/editor/common/config/editorOptions';
|
||||
|
@ -29,6 +29,7 @@ import { IWordAtPosition } from 'vs/editor/common/core/wordHelper';
|
|||
import { LanguageFeatureRegistry } from 'vs/editor/common/languageFeatureRegistry';
|
||||
import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures';
|
||||
import { getHighlightDecorationOptions } from 'vs/editor/contrib/wordHighlighter/browser/highlightDecorations';
|
||||
import { Iterable } from 'vs/base/common/iterator';
|
||||
|
||||
const ctxHasWordHighlights = new RawContextKey<boolean>('hasWordHighlights', false);
|
||||
|
||||
|
@ -192,9 +193,12 @@ class WordHighlighter {
|
|||
private readonly _hasWordHighlights: IContextKey<boolean>;
|
||||
private _ignorePositionChangeEvent: boolean;
|
||||
|
||||
constructor(editor: IActiveCodeEditor, providers: LanguageFeatureRegistry<DocumentHighlightProvider>, contextKeyService: IContextKeyService) {
|
||||
private readonly linkedHighlighters: () => Iterable<WordHighlighter | null>;
|
||||
|
||||
constructor(editor: IActiveCodeEditor, providers: LanguageFeatureRegistry<DocumentHighlightProvider>, linkedHighlighters: () => Iterable<WordHighlighter | null>, contextKeyService: IContextKeyService) {
|
||||
this.editor = editor;
|
||||
this.providers = providers;
|
||||
this.linkedHighlighters = linkedHighlighters;
|
||||
this._hasWordHighlights = ctxHasWordHighlights.bindTo(contextKeyService);
|
||||
this._ignorePositionChangeEvent = false;
|
||||
this.occurrencesHighlight = this.editor.getOption(EditorOption.occurrencesHighlight);
|
||||
|
@ -453,6 +457,14 @@ class WordHighlighter {
|
|||
|
||||
this.decorations.set(decorations);
|
||||
this._hasWordHighlights.set(this.hasDecorations());
|
||||
|
||||
// update decorators of friends
|
||||
for (const other of this.linkedHighlighters()) {
|
||||
if (other?.editor.getModel() === this.editor.getModel()) {
|
||||
other.decorations.set(decorations);
|
||||
other._hasWordHighlights.set(other.hasDecorations());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
|
@ -470,13 +482,15 @@ export class WordHighlighterContribution extends Disposable implements IEditorCo
|
|||
}
|
||||
|
||||
private wordHighlighter: WordHighlighter | null;
|
||||
private linkedContributions: Set<WordHighlighterContribution>;
|
||||
|
||||
constructor(editor: ICodeEditor, @IContextKeyService contextKeyService: IContextKeyService, @ILanguageFeaturesService languageFeaturesService: ILanguageFeaturesService) {
|
||||
super();
|
||||
this.wordHighlighter = null;
|
||||
this.linkedContributions = new Set();
|
||||
const createWordHighlighterIfPossible = () => {
|
||||
if (editor.hasModel()) {
|
||||
this.wordHighlighter = new WordHighlighter(editor, languageFeaturesService.documentHighlightProvider, contextKeyService);
|
||||
this.wordHighlighter = new WordHighlighter(editor, languageFeaturesService.documentHighlightProvider, () => Iterable.map(this.linkedContributions, c => c.wordHighlighter), contextKeyService);
|
||||
}
|
||||
};
|
||||
this._register(editor.onDidChangeModel((e) => {
|
||||
|
@ -514,6 +528,19 @@ export class WordHighlighterContribution extends Disposable implements IEditorCo
|
|||
this.wordHighlighter?.stop();
|
||||
}
|
||||
|
||||
public linkWordHighlighters(editor: ICodeEditor): IDisposable {
|
||||
const other = WordHighlighterContribution.get(editor);
|
||||
if (!other) {
|
||||
return Disposable.None;
|
||||
}
|
||||
this.linkedContributions.add(other);
|
||||
other.linkedContributions.add(this);
|
||||
return toDisposable(() => {
|
||||
this.linkedContributions.delete(other);
|
||||
other.linkedContributions.delete(this);
|
||||
});
|
||||
}
|
||||
|
||||
public override dispose(): void {
|
||||
if (this.wordHighlighter) {
|
||||
this.wordHighlighter.dispose();
|
||||
|
|
|
@ -33,6 +33,7 @@ import { EditOperation } from 'vs/editor/common/core/editOperation';
|
|||
import { Session } from 'vs/workbench/contrib/inlineChat/browser/inlineChatSession';
|
||||
import { ILanguageService } from 'vs/editor/common/languages/language';
|
||||
import { FoldingController } from 'vs/editor/contrib/folding/browser/folding';
|
||||
import { WordHighlighterContribution } from 'vs/editor/contrib/wordHighlighter/browser/wordHighlighter';
|
||||
|
||||
export class InlineChatLivePreviewWidget extends ZoneWidget {
|
||||
|
||||
|
@ -85,12 +86,18 @@ export class InlineChatLivePreviewWidget extends ZoneWidget {
|
|||
originalEditor: { contributions: diffContributions },
|
||||
modifiedEditor: { contributions: diffContributions }
|
||||
}, editor);
|
||||
|
||||
this._disposables.add(this._diffEditor);
|
||||
this._diffEditor.setModel({ original: this._session.textModel0, modified: editor.getModel() });
|
||||
this._diffEditor.updateOptions({
|
||||
lineDecorationsWidth: editor.getLayoutInfo().decorationsWidth
|
||||
});
|
||||
|
||||
const highlighter = WordHighlighterContribution.get(editor);
|
||||
if (highlighter) {
|
||||
this._disposables.add(highlighter.linkWordHighlighters(this._diffEditor.getModifiedEditor()));
|
||||
}
|
||||
|
||||
const doStyle = () => {
|
||||
const theme = themeService.getColorTheme();
|
||||
const overrides: [target: string, source: string][] = [
|
||||
|
|
Loading…
Reference in a new issue