Skip to content
New issue

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

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

Already on GitHub? # to your account

fix: Invoke colorizer when editor is cloned or splitted #827 #870

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.tm4e.ui.tests.support.TestUtils;
import org.eclipse.ui.IEditorDescriptor;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.ide.IDE;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -28,6 +29,7 @@ class TMinGenericEditorTest {

private IEditorDescriptor genericEditorDescr;
private IEditorPart editor;
private IEditorPart clonedEditor;

@BeforeEach
public void setup() throws Exception {
Expand All @@ -40,6 +42,9 @@ public void tearDown() throws Exception {
TestUtils.closeEditor(editor);
editor = null;

TestUtils.closeEditor(clonedEditor);
clonedEditor = null;

TestUtils.assertNoTM4EThreadsRunning();
}

Expand Down Expand Up @@ -72,6 +77,19 @@ void testTMHighlightInGenericEditorEdit() throws Exception {
() -> text.getStyleRanges().length > initialNumberOfRanges + 3);
}

@Test
void testTMHighlightInClonedGenericEditor() throws Exception {
final var f = TestUtils.createTempFile(".ts");
try (var fileOutputStream = new FileOutputStream(f)) {
fileOutputStream.write("let a = '';".getBytes());
}
editor = IDE.openEditor(UI.getActivePage(), f.toURI(), genericEditorDescr.getId(), true);
clonedEditor = UI.getActivePage().openEditor(editor.getEditorInput(), genericEditorDescr.getId(), true, IWorkbenchPage.MATCH_NONE);

final var text = (StyledText) clonedEditor.getAdapter(Control.class);
TestUtils.waitForAndAssertCondition(3_000, () -> text.getStyleRanges().length > 1);
}

@Test
void testReconcilierStartsAndDisposeThread() throws Exception {
testTMHighlightInGenericEditor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,22 @@ public void inputDocumentChanged(final @Nullable IDocument oldDoc, final @Nullab
}

TMPresentationReconciler.this.colorizer = new Colorizer(viewer, theme, listeners);
final var isModelReused = TMModelManager.INSTANCE.isConnected(newDoc);

// connect a TextMate model to the new document
final var docModel = TMModelManager.INSTANCE.connect(newDoc);
docModel.setGrammar(newDocGrammar);
docModel.addModelTokensChangedListener(modelsTokensChangedListener);

// For new models the colorizer will be invoked after tokenization. For reused
// models (e.g. when splitting an editor) this must be done explicitly.
if (colorizer != null && isModelReused) {
try {
colorizer.colorize(new Region(0, newDoc.getLength()), docModel);
} catch (final BadLocationException ex) {
TMUIPlugin.logError(ex);
}
}
}

@Override
Expand Down