Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix persistent syntax highlighting in split windows #203837

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/vs/editor/contrib/wordHighlighter/browser/wordHighlighter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ class WordHighlighter {

private _removeAllDecorations(): void {
const currentEditors = this.codeEditorService.listCodeEditors();
const deleteURI = [];
// iterate over editors and store models in currentModels
for (const editor of currentEditors) {
if (!editor.hasModel()) {
Expand All @@ -441,7 +442,7 @@ class WordHighlighter {
}

editor.removeDecorations(currentDecorationIDs);
WordHighlighter.storedDecorations.delete(editor.getModel().uri);
deleteURI.push(editor.getModel().uri);

const editorHighlighterContrib = WordHighlighterContribution.get(editor);
if (!editorHighlighterContrib?.wordHighlighter) {
Expand All @@ -453,13 +454,17 @@ class WordHighlighter {
editorHighlighterContrib.wordHighlighter._hasWordHighlights.set(false);
}
}

for (const uri of deleteURI) {
WordHighlighter.storedDecorations.delete(uri);
}
}

private _stopSingular(): void {
// Remove any existing decorations + a possible query, and re - run to update decorations
this._removeSingleDecorations();

if (this.editor.hasWidgetFocus()) {
if (this.editor.hasTextFocus()) {
if (this.editor.getModel()?.uri.scheme !== Schemas.vscodeNotebookCell && WordHighlighter.query?.modelInfo?.model.uri.scheme !== Schemas.vscodeNotebookCell) { // clear query if focused non-nb editor
WordHighlighter.query = null;
this._run();
Expand Down Expand Up @@ -489,9 +494,10 @@ class WordHighlighter {
}
}

private _stopAll(): void {
private _stopAll() {
// Remove any existing decorations
// TODO: @Yoyokrazy - this triggers as notebooks scroll, causing highlights to disappear momentarily.
// TODO: @Yoyokrazy -- this triggers as notebooks scroll, causing highlights to disappear momentarily.
// maybe a nb type check?
this._removeAllDecorations();

// Cancel any renderDecorationsTimer
Expand Down Expand Up @@ -684,6 +690,7 @@ class WordHighlighter {
// a) there is no stored query model, but there is a word. This signals the editor that drove the highlight is disposed (cell out of viewport, etc)
// b) the queried model is not the current model. This signals that the editor that drove the highlight is still in the viewport, but we are highlighting a different cell
// otherwise, we send null in place of the word, and the model and selection are used to compute the word
// TODO: @Yoyokrazy -- investigate this logic for sendWord
const sendWord = (!WordHighlighter.query.modelInfo && WordHighlighter.query.word) ||
(WordHighlighter.query.modelInfo?.model.uri !== this.model.uri)
? true : false;
Expand Down Expand Up @@ -747,6 +754,9 @@ class WordHighlighter {
const newDocumentHighlights = this.workerRequestValue.get(uri);
if (newDocumentHighlights) {
for (const highlight of newDocumentHighlights) {
if (!highlight.range) {
continue;
}
newDecorations.push({
range: highlight.range,
options: getHighlightDecorationOptions(highlight.kind)
Expand Down