Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Commit

Permalink
Flex work in progress, editor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hsz committed Jan 16, 2015
1 parent 62cca21 commit de9b5f5
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 126 deletions.
3 changes: 3 additions & 0 deletions META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@
<lang.commenter
implementationClass="mobi.hsz.idea.latex.lang.LatexCommenter"
language="LaTeX"/>
<lang.parserDefinition
implementationClass="mobi.hsz.idea.latex.lang.LatexParserDefinition"
language="LaTeX"/>
<lang.syntaxHighlighterFactory
implementationClass="mobi.hsz.idea.latex.highlighter.LatexHighlighterFactory"
key="LaTeX"/>
Expand Down
33 changes: 22 additions & 11 deletions src/mobi/hsz/idea/latex/editor/LatexFileEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@
import com.intellij.codeHighlighting.BackgroundEditorHighlighter;
import com.intellij.ide.structureView.StructureViewBuilder;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.fileEditor.FileEditorLocation;
import com.intellij.openapi.fileEditor.FileEditorState;
import com.intellij.openapi.fileEditor.FileEditorStateLevel;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.fileEditor.*;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.Key;
import com.intellij.pom.Navigatable;
import mobi.hsz.idea.latex.lang.LatexLanguage;
import mobi.hsz.idea.latex.ui.LatexFileEditorForm;
import org.jetbrains.annotations.NotNull;
Expand All @@ -48,10 +47,7 @@
* @author Jakub Chrzanowski <[email protected]>
* @since 0.1
*/
public class LatexFileEditor implements FileEditor {

// private final JBPanel panel = new JBPanel();
// private final Editor editor;
public class LatexFileEditor implements TextEditor {

/** UI form that holds all editor's components. */
private final LatexFileEditorForm form;
Expand Down Expand Up @@ -201,9 +197,7 @@ public StructureViewBuilder getStructureViewBuilder() {
@Override
public void dispose() {
Disposer.dispose(this);
// if (!editor.isDisposed()) {
// EditorFactory.getInstance().releaseEditor(editor);
// }
form.dispose();
}

@Nullable
Expand All @@ -216,4 +210,21 @@ public <T> T getUserData(@NotNull Key<T> key) {
public <T> void putUserData(@NotNull Key<T> key, @Nullable T value) {

}

@NotNull
@Override
public Editor getEditor() {
return form.getEditor();
}

@Override
public boolean canNavigateTo(@NotNull Navigatable navigatable) {
return navigatable instanceof OpenFileDescriptor && (((OpenFileDescriptor)navigatable).getOffset() >= 0 ||
((OpenFileDescriptor)navigatable).getLine() != -1); }

@Override
public void navigateTo(@NotNull Navigatable navigatable) {
OpenFileDescriptor d = (OpenFileDescriptor)navigatable;
d.navigateIn(getEditor());
}
}
12 changes: 2 additions & 10 deletions src/mobi/hsz/idea/latex/editor/LatexFileEditorProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@
import com.intellij.openapi.fileEditor.*;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.components.JBLabel;
import mobi.hsz.idea.latex.lang.LatexLanguage;
import mobi.hsz.idea.latex.file.LatexFileType;
import mobi.hsz.idea.latex.lang.LatexLanguage;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -68,14 +67,7 @@ public boolean accept(@NotNull Project project, @NotNull VirtualFile file) {
@NotNull
@Override
public FileEditor createEditor(@NotNull Project project, @NotNull VirtualFile file) {
LatexFileEditor a = new LatexFileEditor(project, FileDocumentManager.getInstance().getDocument(file));

FileEditorManager m = FileEditorManager.getInstance(project);
// for (FileEditor editor : m.getEditors(file)) {
m.addTopComponent(a, new JBLabel("zzzzzzz"));
// }

return a;
return new LatexFileEditor(project, FileDocumentManager.getInstance().getDocument(file));
}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/mobi/hsz/idea/latex/lang/LatexParserDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ public TokenSet getCommentTokens() {
return COMMENTS;
}

/**
* Returns the set of token types which are treated as argument by the PSI builder.
*
* @return the set of argument token types.
*/
@NotNull
public TokenSet getArgumentTokens() {
return ARGUMENTS;
}

/**
* Returns the set of token types which are treated as instructions by the PSI builder.
*
Expand Down
28 changes: 19 additions & 9 deletions src/mobi/hsz/idea/latex/lexer/Latex.flex
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,43 @@ LINE_WS = [\ \t\f]
WHITE_SPACE = ({LINE_WS}|{EOL})+

INSTRUCTION = \\[a-zA-Z]+
ARGUMENT = [\w ]+
ARGUMENT = [^\ \n\r\t\f]+
COMMENT = %.*
SPECIAL = [\S]
CRLF = [\s\r\n]+

%state IN_ENTRY
%state IN_GROUP

%%
<YYINITIAL> {
{WHITE_SPACE}+ { return WHITE_SPACE; }

"{" { return LBRACE; }
"}" { return RBRACE; }
"[" { return LBRACKET; }
"]" { return RBRACKET; }
"(" { return LPAREN; }
")" { return RPAREN; }
"{" { yypushback(1); yybegin(IN_GROUP); }
"[" { yypushback(1); yybegin(IN_GROUP); }
"(" { yypushback(1); yybegin(IN_GROUP); }

"," { return COMMA; }
":" { return COLON; }
"*" { return ASTERISK; }
"\\\\" { return LINE_BREAK; }

{INSTRUCTION} { return INSTRUCTION; }
{ARGUMENT} { return ARGUMENT; }
{COMMENT} { return COMMENT; }
{SPECIAL} { return SPECIAL; }
{CRLF} { return CRLF; }

[^] { yybegin(YYINITIAL); return BAD_CHARACTER; }
} // <YYINITIAL>

<IN_GROUP> {
{WHITE_SPACE}+ { yybegin(YYINITIAL); return CRLF; }

"{" { return LBRACE; }
"[" { return LBRACKET; }
"(" { return LPAREN; }
"}" { return RBRACE; }
"]" { return RBRACKET; }
")" { return RPAREN; }

{ARGUMENT} { return ARGUMENT; }
}
Loading

0 comments on commit de9b5f5

Please sign in to comment.