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

feat: add ITMDocumentModel interface #556

Merged
merged 1 commit into from
Jun 14, 2023
Merged
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 @@ -13,8 +13,9 @@

import org.eclipse.jface.text.IDocument;
import org.eclipse.tm4e.core.model.TMModel;
import org.eclipse.tm4e.ui.model.ITMDocumentModel;

public final class TMDocumentModel extends TMModel {
public final class TMDocumentModel extends TMModel implements ITMDocumentModel {

private final IDocument document;

Expand All @@ -23,6 +24,7 @@ public TMDocumentModel(final IDocument document) {
this.document = document;
}

@Override
public IDocument getDocument() {
return document;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Copyright (c) 2023 Vegard IT GmbH and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Sebastian Thomschke - initial implementation
*/
package org.eclipse.tm4e.ui.model;

import org.eclipse.jface.text.IDocument;
import org.eclipse.tm4e.core.model.ITMModel;

public interface ITMDocumentModel extends ITMModel {

IDocument getDocument();
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
package org.eclipse.tm4e.ui.model;

import org.eclipse.jface.text.IDocument;
import org.eclipse.tm4e.core.model.ITMModel;

/**
* TextMate model manager API.
Expand All @@ -27,7 +26,7 @@ public interface ITMModelManager {
*
* @return the TextMate model connected to the document.
*/
ITMModel connect(IDocument document);
ITMDocumentModel connect(IDocument document);

/**
* Disconnect the TextMate model of the given document.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
import org.eclipse.tm4e.core.model.TMToken;
import org.eclipse.tm4e.registry.TMEclipseRegistryPlugin;
import org.eclipse.tm4e.ui.TMUIPlugin;
import org.eclipse.tm4e.ui.internal.model.TMDocumentModel;
import org.eclipse.tm4e.ui.internal.model.TMModelManager;
import org.eclipse.tm4e.ui.internal.preferences.PreferenceConstants;
import org.eclipse.tm4e.ui.internal.text.TMPresentationReconcilerTestGenerator;
Expand All @@ -75,6 +74,7 @@
import org.eclipse.tm4e.ui.internal.utils.ContentTypeInfo;
import org.eclipse.tm4e.ui.internal.utils.MarkerUtils;
import org.eclipse.tm4e.ui.internal.utils.PreferenceUtils;
import org.eclipse.tm4e.ui.model.ITMDocumentModel;
import org.eclipse.tm4e.ui.themes.ITheme;
import org.eclipse.tm4e.ui.themes.IThemeManager;
import org.eclipse.tm4e.ui.themes.ITokenProvider;
Expand All @@ -84,7 +84,7 @@
* TextMate presentation reconciler which must be initialized with:
*
* <ol>
* <li>a TextMate grammar {@link IGrammar} used to initialize the {@link TMDocumentModel}.</li>
* <li>a TextMate grammar {@link IGrammar} used to initialize the {@link ITMDocumentModel}.</li>
* <li>a token provider {@link ITokenProvider} to retrieve the {@link IToken} from a {@link TMToken} type .</li>
* </ol>
*/
Expand Down Expand Up @@ -396,7 +396,7 @@ void colorize(final ModelTokensChangedEvent event) {
return;
}
final ITMModel model = event.model;
if (model instanceof final TMDocumentModel docModel) {
if (model instanceof final ITMDocumentModel docModel) {
for (final Range range : event.ranges) {
try {
final int length = document.getLineOffset(range.toLineNumber - 1)
Expand Down Expand Up @@ -514,7 +514,7 @@ public IPresentationRepairer getRepairer(@Nullable final String contentType) {
return null;
}

private void colorize(final IRegion damage, final TMDocumentModel model) throws BadLocationException {
private void colorize(final IRegion damage, final ITMDocumentModel model) throws BadLocationException {
final IDocument doc = model.getDocument();
final int fromLineIndex = doc.getLineOfOffset(damage.getOffset());
final int toLineIndex = doc.getLineOfOffset(damage.getOffset() + damage.getLength());
Expand Down